Skip to content

Commit

Permalink
[#980] Fix unit tests, combined API tests into the sinle module
Browse files Browse the repository at this point in the history
Co-authored-by: sergey <sergey.lyapustin@strolid.com>
  • Loading branch information
2 people authored and pair committed Aug 23, 2023
1 parent 51ba70e commit 97d05bf
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 49 deletions.
34 changes: 29 additions & 5 deletions server/tests/test_api_get_vcons.py → server/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,45 @@
from fastapi.testclient import TestClient
from vcon_fixture import generate_mock_vcon
import pytest
import conserver
app = conserver.conserver_app
import api


def post_vcon(vcon):
# Use the TestClient to make requests to the app.
with TestClient(app) as client:
with TestClient(api.app) as client:
response = client.post("/vcon", json=vcon)
assert response.status_code == 201
print("response: {}".format(response))
return response


@pytest.mark.anyio
def test_get_vcons():
def test_api_vcon_lifecycle():
# Write a dozen vcons
test_vcon = generate_mock_vcon()
post_vcon(test_vcon)

# Read the vcon back using the test client
with TestClient(api.app) as client:
response = client.get("/vcon/{}".format(test_vcon["uuid"]))
assert response.status_code == 200
print("response: {}".format(response))

# Delete the vcon using the test client
with TestClient(api.app) as client:
response = client.delete("/vcon/{}".format(test_vcon["uuid"]))
assert response.status_code == 204
print("response: {}".format(response))

# Read the vcon back
with TestClient(api.app) as client:
response = client.get("/vcon/{}".format(test_vcon["uuid"]))
assert response.status_code == 404
print("response: {}".format(response))


@pytest.mark.anyio
def test_get_vcons():
vcon_uuids = []
# Write a dozen vcons and read them back
for i in range(12):
Expand All @@ -24,7 +48,7 @@ def test_get_vcons():
vcon_uuids.append(test_vcon["uuid"])

# Read the vcons back using the test client, deleting them as we go
with TestClient(app) as client:
with TestClient(api.app) as client:
# Get the list of vCons from the server
response = client.get("/vcon")
assert response.status_code == 200
Expand Down
44 changes: 0 additions & 44 deletions server/tests/test_api_vcon_lifecycle.py

This file was deleted.

0 comments on commit 97d05bf

Please sign in to comment.