-
Notifications
You must be signed in to change notification settings - Fork 2
Cahid Enes Keleş Milestone 2 Member Contribution
- https://www.uuidtools.com/api/generate/v4: This API generates a UUID version 4 and returns it. There are other options available but this particular route is the one that I used.
-
/add/resource
: POST with json body: Add resource to the database -
/add/need
: POST with json body: Add need to the database -
/add/event
: POST with json body: Add event to the database -
/add/action
: POST with json body: Add action to the database -
/get/resource
: GET: get the list of resources -
/get/need
: GET: get the list of needs -
/get/event
: GET: get the list of events -
/get/action
: GET: get the list of actions -
/get/resource?id=<id>
: GET: Get resource with id -
/get/need?id=<id>
: GET: Get need with id -
/get/event?id=<id>
: GET: Get event with id -
/get/action?id=<id>
: GET: Get action with id -
/delete/resource?id=<id>
: GET: Delete resource with id -
/delete/need?id=<id>
: GET: Delete need with id -
/delete/event?id=<id>
: GET: Delete event with id -
/delete/action?id=<id>
: GET: Delete action with id
Note: The parameters of the POST requests can be seen and be tested in docs: Swagger or Redoc. Note that these documentations also include UI endpoints as well.
For each combination of (resource, need, event, action) and (add, get, delete) there are related tests, there is no API endpoint that have not any unit test. There are total of 70 unit tests (and 1 mock test to cleanup).
For add tests, there are
- Full arguments tests
- Only required arguments tests
- 1 required argument missing tests for each required argument (should fail)
For get tests, there are
- Empty list tests
- At least 3 tests
- ID tests
- Unpresent ID tests (should return null)
For delete tests, there are
- ID tests
- Unpresent ID tests
An example test is as follows:
def test_full_arguments(self):
r = requests.post(f'http://0.0.0.0:8000{api_prefix}/add/resource', json={
"type": "food",
"location": "1234",
"notes": "this resource is here for a test",
"updated_at": "2020-04-01T12:00:00Z",
"is_active": True,
"upvotes": 0,
"downvotes": 0,
"creator_id": "test",
"creation_date": "2020-04-01T12:00:00Z",
"condition": "good",
"quantity": 1
})
# test response uuid
self.assertEqual(r.status_code, 200)
uuid = r.text[1:-1]
self.assertTrue(uuid4regex.match(uuid), f'uuid {uuid} does not match regex {uuid4regex.pattern}')
return uuid
Two types of requests have two different use of calls. POST requests require a json body, while (some of) GET requests require inline parameters. For each type of requests, the example is as follows:
import requests
uri = 'http://13.49.41.10:8000'
# POST Request Example
response = requests.post(uri + '/add/resource', json={
"type": "Food",
"location": "Istanbul",
"notes": "This is a test resource",
"updated_at": "12.05.2023",
"is_active": True,
"upvotes": 0,
"downvotes": 0,
"creator_id": "293874",
"creation_date": "12.05.2023",
"condition": "New",
"quantity": 1
})
print('Headers:', response.headers)
print('Status Code:', response.status_code)
print('Json:', response.json())
print()
# GET Request Example
response = requests.get(uri + '/get/resource?id=' + response.json())
print('Headers:', response.headers)
print('Status Code:', response.status_code)
print('Json:', response.json())
And the output is:
Headers: {'date': 'Fri, 12 May 2023 20:17:48 GMT', 'server': 'uvicorn', 'content-length': '38', 'content-type': 'application/json'}
Status Code: 200
Json: 787d8f8a-c9df-4fcc-b5fa-5c8d860dc630
Headers: {'date': 'Fri, 12 May 2023 20:17:48 GMT', 'server': 'uvicorn', 'content-length': '268', 'content-type': 'application/json'}
Status Code: 200
Json: {'uuid': '787d8f8a-c9df-4fcc-b5fa-5c8d860dc630', 'type': 'Food', 'location': 'Istanbul', 'notes': 'This is a test resource', 'updated_at': '12.05.2023', 'is_active': True, 'upvotes': 0, 'downvotes': 0, 'creator_id': '293874', 'creation_date': '12.05.2023', 'condition': 'New', 'quantity': 1}
I initially thought that we should make the dockerization and deployment by ourselves, and I did all these things. Here is the API that I deployed myself: http://13.49.41.10:8000/ (later I merged my code with shared code and docker and amazon server) The Dockerfile and other files related to the dockerization and deployment are deleted. But you can see these files in the history. As backend, I (and we) used fastapi. As database, I used PostgreSQL.
There were a lot of new things to learn in a short time, that was very very challenging. I initially tried to use MongoDB for database. I worked very hard and melted down 5 hours just struggling and I was failed. This was very depressing for me. But I recovered tomorrow, and used PostgreSQL (with the suggestions of my teammates: it is better if we could use the advantages of different types of databases).
📌 Communication Plan
📌 Docker and local deployment tutorial
📌 RAM
📌 Test Traceability Matrix