Skip to content

Individual Contribution Report 2 | Omer Talip Akalin

Ömer Talip Akalın edited this page May 12, 2023 · 7 revisions

Member

Name: Omer Talip Akalin

Main git issues (significant ones only)

  • We were storing passwords without hash :) #179
  • Implementing the task (with unit tests, in a single issue) #195
  • Adding swagger template #226

The name, route, description of utilized third party URIs

For this practice app, I've used the Instatus API.

Instatus a service for companies to announce the status of their systems in real time. I've utilized the API to fetch the status of incidents and to update the status of incidents based on a mock company I formed, namely Tcorp. For this specific purpose, I prepared a template incident and used it only. You can check it here.

The routes used are https://api.instatus.com/v1/{PAGE_ID}/incidents for fetching incidents and https://api.instatus.com/v2/{PAGE_ID}/incidents/{curr_inc_id}/incident-updates/{template_id} for updating incidents, where one template is for resolving an incident and the other one is for investigating an incident.

The name, route, description of the created API functions

I've configured API functions for a GET request and a POST request.

POST - change_status: This function is accessed via the route /change_status/<new_status> and is used to change the status of incident of the application, by setting <new_status> to resolved or investigating. Otherwise, it returns an error.

GET - get_current_status: This function is accessed via the route /get_current_status and is used to fetch the current status of incident / page.

To fetch the page, I also added the route of get_status_page:

get_status_page: This function is accessed via the route /status_page and is used to render the status page of our application.

Description of Unit Tests

In the unit tests, I've tried to validate my API endpoints. To do so, I used pytest and unittest libraries, which are quite handy to use.

I added tests to the endpoint with mocks to:

  • Test the status page & title
@patch("app.views.get_current_status")
def test_get_status_page(mock_get_current_status, client):
    mock_get_current_status.return_value = MagicMock(
        response=[json.dumps({"status": 200, "message": "RESOLVED"})]
    )
    response = client.get("/status_page")
    assert response.status_code == 200
    assert b"Current Status: STABLE" in response.data
  • Test invalid post request
def test_change_status_invalid(client):
    response = client.post("/change_status/invalid")
    assert response.json == {"status": 404, "message": "Page not found"}
  • Test the investigating case
@patch("app.views.get_all_incidents")
@patch("requests.post")
def test_change_status_investigating(mock_post, mock_get_all_incidents, client):
    mock_get_all_incidents.return_value = [{"id": "1", "status": "RESOLVED"}]
    mock_post.return_value.status_code = 200
    response = client.post("/change_status/investigating")
    assert response.json == {
        "status": 200,
        "message": "Status changed - investigating",
    } or response.json == {
        "message": "Status INVESTIGATING already",
        "status": 200,
    }
  • Test the resolved case
  • Test whether fetching the current status works correctly

Sample Calls to External Sources

Here are the sample calls that I make to other APIs:

GET https://api.instatus.com/v1/clhe4m8r51385441dmzneperc58/incidents
User-Agent: python-requests/2.29.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Authorization: Bearer <api_token_here>

Here's the response json with status - 200 (it's huge, so I'm putting the link): https://pastebin.ubuntu.com/p/nVgKVPXJ8V/

POST https://api.instatus.com/v2/clhe4m8r51385441dmzneperc58/incidents/clhkbihz64313239emzfrfreyw5/incident-updates/clhe63sdy1582381dmzszbs884p
User-Agent: python-requests/2.29.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Authorization: Bearer <api_token_here>
Content-Length: 0

Here's the response json with status - 200 (it's huge, so I'm putting the link): https://pastebin.ubuntu.com/p/JQd8qKTrry/

POST https://api.instatus.com/v2/clhe4m8r51385441dmzneperc58/incidents/clhkbihz64313239emzfrfreyw5/incident-updates/clhe627g51571411dmzj73v5tyk
User-Agent: python-requests/2.29.0
Accept-Encoding: gzip, deflate
Accept: */*
Connection: keep-alive
Authorization: Bearer <api_token_here>
Content-Length: 0

Here's the response json with status - 200 (it's huge, so I'm putting the link): https://pastebin.ubuntu.com/p/wM8Wwz9ZnX/

Sample Calls to my endpoints

Here's the status getter (I made that from browser to fetch more data):

Note: curl --verbose --request GET 127.0.0.1:5000/get_current_status

Note: Unnecessary use of -X or --request, GET is already inferred.
Note: Trying 127.0.0.1:5000...
Note: Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)
GET /get_current_status HTTP/1.1
Host: 127.0.0.1:5000
User-Agent: curl/7.87.0
Accept: */*
 
Note:  Mark bundle as not supporting multiuse
HTTP/1.1 200 OK
Server: Werkzeug/2.3.2 Python/3.11.3
Date: Fri, 12 May 2023 18:18:00 GMT
Content-Type: application/json
Content-Length: 36
Connection: close
{"message":"RESOLVED","status":200}
Note: Closing connection 0

And here's the status updater (three consecutive calls for better understanding):

Note: curl --verbose --request POST 127.0.0.1:5000/change_status/investigating -H "Authorization: Bearer {TOKEN_HERE}"
Note: Trying 127.0.0.1:5000...
Note: Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)

POST /change_status/investigating HTTP/1.1
Host: 127.0.0.1:5000
User-Agent: curl/7.87.0
Accept: */*
Authorization: Bearer {TOKEN_HERE}
 
Note: Mark bundle as not supporting multiuse
HTTP/1.1 200 OK
Server: Werkzeug/2.3.2 Python/3.11.3
Date: Fri, 12 May 2023 18:20:03 GMT
Content-Type: application/json
Content-Length: 58
Connection: close

{"message":"Status changed - investigating","status":200}
Note: Closing connection 0
Note: curl --verbose --request POST 127.0.0.1:5000/change_status/resolved -H "Authorization: Bearer {TOKEN_HERE}"
Note: Trying 127.0.0.1:5000...
Note: Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)

POST /change_status/resolved HTTP/1.1
Host: 127.0.0.1:5000
User-Agent: curl/7.87.0
Accept: */*
Authorization: Bearer {TOKEN_HERE}
 
Note: Mark bundle as not supporting multiuse
HTTP/1.1 200 OK
Server: Werkzeug/2.3.2 Python/3.11.3
Date: Fri, 12 May 2023 18:20:03 GMT
Content-Type: application/json
Content-Length: 58
Connection: close

{"message":"Status changed - resolved","status":200}
Note: Closing connection 0
Note: curl --verbose --request POST 127.0.0.1:5000/change_status/resolved -H "Authorization: Bearer {TOKEN_HERE}"
Note: Trying 127.0.0.1:5000...
Note: Connected to 127.0.0.1 (127.0.0.1) port 5000 (#0)

POST /change_status/resolved HTTP/1.1
Host: 127.0.0.1:5000
User-Agent: curl/7.87.0
Accept: */*
Authorization: Bearer {TOKEN_HERE}
 
Note: Mark bundle as not supporting multiuse
HTTP/1.1 200 OK
Server: Werkzeug/2.3.2 Python/3.11.3
Date: Fri, 12 May 2023 18:20:03 GMT
Content-Type: application/json
Content-Length: 58
Connection: close

{"message":"Status RESOLVED already","status":200}
Note: Closing connection 0

Any other significant work

I've handled many pull requests as a reviewer, and I also tried my best to solve problems regarding Git. In these pull requests, I requested many reasonable changes, which's been liked by my teammates.

Here are some of the pull requests that I reviewed:

I also proposed the idea of using Flask as it's easy to onboard. I also showed a couple of tricks for development.

I have joined the implementation & discussion phases two weeks late (due to some personal problems). But I truly believe that I contributed to the team, especially in terms of organization, effectively.

Challenges that I encountered

As a person who uses Docker daily, I never knew it was that challenging to build Postgresql to use in the container localhost. We (me and @erkamkavak) have encountered so many interesting bugs that at some point I was proposing to change it to Postgresql.

Other than that, this task made me remember how much I prefer not to write Javascript.

Clone this wiki locally