def test_json_response_body_and_request_payload(self): app = TApp(mock_app) # The asserts are actually inside the route handler, so no asserts after # this statement. response = app.post( "/response-and-request-is-json/", params=json.dumps({"foo": "X", "bar": 10}), content_type="application/json", )
def test_pagination_produces_correct_number_of_pages(self): bank_id = self._create_200_members() api = TApp( get_bank_api( self.get_table(), "irrelevant_s3_bucket_for_this_test", "irrelevant_sqs_queue", get_default_signal_type_mapping(), ) ) running_count = 0 continuation_token = None unique_member_ids = set() while True: if continuation_token: response = json.loads( api.get( f"/get-members/{bank_id}?content_type=photo&continuation_token={continuation_token}" ).body ) else: response = json.loads( api.get(f"/get-members/{bank_id}?content_type=photo").body ) running_count += len(response["bank_members"]) continuation_token = response["continuation_token"] unique_member_ids.update( map(lambda member: member["bank_member_id"], response["bank_members"]) ) if continuation_token == None: # Last page should not have any continuation_token break # Checks for total number of items received. Should work with any page size. assert running_count == 200 # Checks that the number of unique member ids is equal to the expected # value (ie. no repeats) assert len(unique_member_ids) == 200
def test_json_response_body(self): app = TApp(mock_app) response = app.get("/response-is-json/") self.assertEqual(response.status, "200 OK") self.assertEqual(response.body, b'{"foo": "X", "bar": 10}')
""" Unit and functional tests for ElasticSearch PostProcessing Service """ import service from webtest import TestApp as TApp # Change alias so that pytest does not attempt to load this as a test case class from werkzeug.debug import DebuggedApplication debug_app = app = DebuggedApplication(service.app) debug_app.catchall = False # Now most exceptions are re-raised within bottle. test_app = TApp(debug_app) def test_service_initiated(): """ Assert root url returns a message showing the service is ready. """ assert "ready" in service.index() def test_no_data(): """ Assert correct error message is returned when no data is supplied to the unwind url. """ response = test_app.post("/evaluate_goal", expect_errors=True) assert response.status == '400 Bad Request' assert "No data" in response.text def test_valid_data(): """
""" Unit and functional tests for the bkt objective unwind service. """ import json from service import bkt_outcome_unwind from webtest import TestApp as TApp # Change alias so that pytest does not attempt to load this as a test case class from werkzeug.debug import DebuggedApplication app = DebuggedApplication(bkt_outcome_unwind.bkt_app) app.catchall = False # Now most exceptions are re-raised within bottle. test_app = TApp(app) def test_service_initiated(): """ Assert root url returns a message showing the service is ready. """ assert "ready" in bkt_outcome_unwind.index() def test_no_data(): """ Assert correct error message is returned when no data is supplied to the unwind url. """ response = test_app.post("/bkt_service/unwind", expect_errors=True) assert response.status == '400 Bad Request' assert "No data" in response.text def test_valid_data():
def client(app) -> TApp: return TApp(app)