Skip to content

Commit

Permalink
test: update operation api tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcellmueller committed Nov 17, 2023
1 parent 797c8a4 commit 352bfe1
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions bc_obps/registration/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ def test_post_new_operation(self, client):
)
post_response = client.post(self.endpoint, content_type=content_type_json, data=mock_operation.json())
assert post_response.status_code == 200
assert post_response.json() == {"name": "Springfield Nuclear Power Plant"}
assert post_response.json() == {"name": "Springfield Nuclear Power Plant", "id": 2}
# check that the default status of pending was applied
get_response = client.get(self.endpoint).json()[0]
assert 'status' in get_response and get_response['status'] == 'pending'
assert 'status' in get_response and get_response['status'] == 'not_registered'

def test_post_new_malformed_operation(self, client):
response = client.post(
Expand All @@ -105,7 +105,7 @@ def test_post_new_malformed_operation(self, client):

def test_put_operation_update_status_approved(self, client):
operation = baker.make(Operation)
assert operation.status == Operation.Statuses.PENDING
assert operation.status == Operation.Statuses.NOT_REGISTERED

url = self.build_update_status_url(operation_id=operation.id)

Expand All @@ -128,7 +128,7 @@ def test_put_operation_update_status_approved(self, client):

def test_put_operation_update_status_rejected(self, client):
operation = baker.make(Operation)
assert operation.status == Operation.Statuses.PENDING
assert operation.status == Operation.Statuses.NOT_REGISTERED

url = self.build_update_status_url(operation_id=operation.id)

Expand All @@ -142,7 +142,7 @@ def test_put_operation_update_status_rejected(self, client):
assert parsed_object.get("pk") == operation.id
assert parsed_object.get("fields").get("status") == "rejected"

get_response = client.get(self.endpoint + "/" + str(operation.id))
get_response = client.get(self.endpoint + "/" + str(operation.id) + "?submit=false")
assert get_response.status_code == 200
get_response_dict = get_response.json()
assert get_response_dict.get("status") == "rejected"
Expand All @@ -151,7 +151,7 @@ def test_put_operation_update_status_rejected(self, client):

def test_put_operation_not_verified_when_not_registered(self, client):
operation = baker.make(Operation)
assert operation.status == Operation.Statuses.PENDING
assert operation.status == Operation.Statuses.NOT_REGISTERED

url = self.build_update_status_url(operation_id=operation.id)

Expand All @@ -173,7 +173,7 @@ def test_put_operation_not_verified_when_not_registered(self, client):
def test_put_operation_update_status_invalid_data(self, client):
def send_put_invalid_data():
operation = baker.make(Operation)
assert operation.status == Operation.Statuses.PENDING
assert operation.status == Operation.Statuses.NOT_REGISTERED

url = self.build_update_status_url(operation_id=operation.id)

Expand Down Expand Up @@ -229,15 +229,17 @@ def test_put_operation(self, client):
)

response = client.put(
self.endpoint + str(operation.id), content_type=content_type_json, data=mock_operation.json()
self.endpoint + str(operation.id) + "?submit=false",
content_type=content_type_json,
data=mock_operation.json(),
)
assert response.status_code == 200
assert response.json() == {"name": "New name"}

def test_put_malformed_operation(self, client):
operation = baker.make(Operation)
response = client.put(
self.endpoint + str(operation.id),
self.endpoint + str(operation.id) + "?submit=false",
content_type=content_type_json,
data={"garbage": "i am bad data"},
)
Expand Down

0 comments on commit 352bfe1

Please sign in to comment.