changed api according to specification

This commit is contained in:
Joel 2021-02-10 22:41:23 +01:00
parent 5e46e8068a
commit d468732040
No known key found for this signature in database
GPG key ID: BDDDBECD0808290E
6 changed files with 150 additions and 58 deletions

101
test.py
View file

@ -35,6 +35,19 @@ def change_api_state(park_id: int = 0, in_get_park: bool = False, was_in_park: b
requests.post("http://localhost:5000/api/api/updateState", json=data)
def change_double_elim_api_state(started: bool = False, goal: list = [0, 0], position: list = [0, 0, 0],
op_position: list = [0, 0, 0], items: list = []):
data = {
"started": started,
"goal": goal,
"position": position,
"opPosition": op_position,
"items": items
}
requests.post("http://localhost:5000/api/api/updateDoubleElimState", json=data)
class TestApiServer(unittest.TestCase):
def test_get_park(self):
ret, code = Api.Seeding.get_park()
@ -70,7 +83,7 @@ class TestApiServer(unittest.TestCase):
ret = Api.Seeding.pay_park()
assert type(ret) is int
assert ret == 201
assert ret == 204
def test_simon_says(self):
change_api_state(in_simon_zone=False)
@ -163,26 +176,94 @@ class TestApiServer(unittest.TestCase):
last_pos = next_pos
def test_get_position(self):
response = Api.DoubleElim.get_position()
response, status = Api.DoubleElim.get_position()
assert type(status) is int
assert status == 503
assert type(response) == Api.Position
assert 0 <= response.x
assert 0 <= response.y
assert 0 <= response.degrees <= 360
assert 0 == response.x
assert 0 == response.y
assert 0 == response.degrees
change_double_elim_api_state(started=True, position=[50, 75, 90])
response, status = Api.DoubleElim.get_position()
assert type(status) is int
assert status == 200
assert type(response) == Api.Position
assert 50 == response.x
assert 75 == response.y
assert 90 == response.degrees
def test_get_opponent(self):
response = Api.DoubleElim.get_opponent()
response, status = Api.DoubleElim.get_opponent()
assert type(status) is int
assert status == 503
assert type(response) == Api.Position
assert 0 == response.x
assert 0 == response.y
assert 0 == response.degrees
change_double_elim_api_state(started=True, op_position=[50, 75, 90])
response, status = Api.DoubleElim.get_opponent()
assert type(status) is int
assert status == 200
assert type(response) == Api.Position
assert 50 == response.x
assert 75 == response.y
assert 90 == response.degrees
def test_get_goal(self):
response = Api.DoubleElim.get_goal()
response, status = Api.DoubleElim.get_goal()
assert type(status) is int
assert status == 503
assert type(response) == Api.Position
assert 0 <= response.x
assert 0 <= response.y
assert 0 == response.x
assert 0 == response.y
assert response.degrees == -1
change_double_elim_api_state(started=True, goal=[50, 75])
response, status = Api.DoubleElim.get_goal()
assert type(status) is int
assert status == 200
assert type(response) == Api.Position
assert 50 == response.x
assert 75 == response.y
assert response.degrees == -1
def test_get_items(self):
response = Api.DoubleElim.get_items()
response, status = Api.DoubleElim.get_items()
assert type(status) is int
assert status == 503
assert type(response) == list
assert response == []
change_double_elim_api_state(started=True)
response, status = Api.DoubleElim.get_items()
assert type(status) is int
assert status == 200
assert type(response) == list
assert response == []
change_double_elim_api_state(started=True, items=[{"id": 0, "x": 50, "y": 75}])
response, status = Api.DoubleElim.get_items()
assert type(status) is int
assert status == 200
assert type(response) == list
assert len(response) == 1
assert response == [{"id": 0, "x": 50, "y": 75}]
change_double_elim_api_state(started=True, items=[{"id": 0, "x": 50, "y": 75}, {"id": 2, "x": -50, "y": -75}])
response, status = Api.DoubleElim.get_items()
assert type(status) is int
assert status == 200
assert type(response) == list
assert len(response) == 2
assert response == [{"id": 0, "x": 50, "y": 75}, {"id": 2, "x": -50, "y": -75}]
def setUp(self) -> None:
if START_SERVER: