def test_adding_an_intercept(): intercepts = Intercepts() intercept = Intercept("my-query") result = intercepts.add(intercept) intercept_list = intercepts.all() assert result is True assert intercept_list == [intercept.to_json()]
def post(self, intercept_id): request = json.loads(self.request.body.decode('utf-8')) intercept = Intercept(query=request["query"], id=intercept_id) result = self.application.intercepts.update(intercept) response = {"intercept": intercept.to_json(), "success": result} self.write(json.dumps(response))
def test_intercepts_all_returns_intercepts(http_client, base_url, app): app.intercepts.add(Intercept(query="some-query")) app.intercepts.add(Intercept(query="some-query")) app.intercepts.add(Intercept(query="some-query")) response = yield http_client.fetch(base_url + "/intercepts/all/1") assert response.code == 200 response_data = json.loads(response.body) assert len(response_data["intercepts"]) == 3
def test_updating_a_non_existing_intercept(): intercepts = Intercepts() intercept = Intercept("my-query") intercepts.add(intercept) updated = Intercept("update-query", id="some-other-id") result = intercepts.update(updated) intercept_list = intercepts.all() assert result is False assert intercept_list == [intercept.to_json()]
def test_updating_an_intercept(): intercepts = Intercepts() intercept = Intercept("my-query") intercepts.add(intercept) updated = Intercept("update-query", id=intercept.id) result = intercepts.update(updated) intercept_list = intercepts.all() assert result is True assert intercept_list == [updated.to_json()]
def test_adding_an_intercept_with_an_existing_id(): intercepts = Intercepts() intercept = Intercept("my-query") result = intercepts.add(intercept) new_intercept = Intercept("some-other-query", id=intercept.id) result = intercepts.add(new_intercept) assert result is False intercept_list = intercepts.all() assert intercept_list == [intercept.to_json()]
def test_deleting_an_intercept(): intercepts = Intercepts() intercept = Intercept("my-query") intercepts.add(intercept) result = intercepts.delete(intercept.id) intercept_list = intercepts.all() assert result is True assert intercept_list == []
def test_intercepts_delete_intercept(http_client, base_url, app): intercept = Intercept(query="some-query") app.intercepts.add(intercept) headers = yield get_auth_headers(http_client, base_url) request = HTTPRequest(base_url + "/intercepts/delete/1/" + intercept.id, method="POST", body="", headers=headers) response = yield http_client.fetch(request) assert response.code == 200 response_data = json.loads(response.body) assert response_data["success"] == True assert len(app.intercepts.all()) == 0
def test_intercepts_modify_intercept(http_client, base_url, app): intercept = Intercept(query="some-query") app.intercepts.add(intercept) body = {"id": intercept.id, "query": "updated-query"} headers = yield get_auth_headers(http_client, base_url) request = HTTPRequest(base_url + "/intercepts/update/1/" + intercept.id, method="POST", body=json.dumps(body), headers=headers) response = yield http_client.fetch(request) assert response.code == 200 response_data = json.loads(response.body) assert response_data["success"] == True assert len(app.intercepts.all()) == 1 assert app.intercepts.all()[0]["query"] == "updated-query"
def test_intercept_stores_query(): intercept = Intercept("my-query") assert intercept.query == "my-query"
def test_finding_an_intercept(): intercepts = Intercepts() intercept = Intercept("my-query") result = intercepts.add(intercept) assert intercepts.find_by_id(intercept.id) == intercept
def test_intercept_generates_unique_ids(): first_intercept = Intercept("my-first-query") second_intercept = Intercept("my-second-query") assert first_intercept.id != second_intercept.id
def test_intercepts_to_json(): intercept = Intercept("my-query") expected_json = {"id": intercept.id, "query": intercept.query} assert intercept.to_json() == expected_json
def test_intercept_can_be_created_with_and_id(): intercept = Intercept("my-query", id="my-id") assert intercept.id == "my-id"
def test_intercept_stores_query_kwarg(): intercept = Intercept(query="my-query") assert intercept.query == "my-query"