diff --git a/env.json b/env.json index e0572dd..1a2e171 100644 --- a/env.json +++ b/env.json @@ -5,7 +5,7 @@ "DB_NAME": "/dev/article-rec-db/name", "DB_PASSWORD": "/dev/database/password", "DB_USER": "/dev/database/user", - "DB_HOST": "/dev/database/host", + "DB_HOST": "/dev/read-database/host", "PORT": 5000, "DEBUG": true, "TEST_DB": false, @@ -23,7 +23,7 @@ "DB_NAME": "/prod/article-rec-db/name", "DB_PASSWORD": "/prod/database/password", "DB_USER": "/prod/database/user", - "DB_HOST": "/prod/database/host", + "DB_HOST": "/prod/read-database/host", "DEBUG": false, "ADMIN_TOKEN": "/prod/article-rec-api/admin-token" } diff --git a/handlers/model.py b/handlers/model.py index cbf6742..faf98ae 100644 --- a/handlers/model.py +++ b/handlers/model.py @@ -71,13 +71,3 @@ async def get(self): "results": [x.to_dict() for x in query], } self.api_response(res) - - @admin_only - async def patch(self, _id): - try: - resource = get_resource(self.mapping, _id) - except DoesNotExist: - raise tornado.web.HTTPError(404, "RESOURCE DOES NOT EXIST") - self.mapping.set_current(_id, resource["type"], resource["site"]) - resource = get_resource(self.mapping, _id) - self.api_response(resource) diff --git a/tests/handlers/test_model_handler.py b/tests/handlers/test_model_handler.py index 90ea96f..bc7af8c 100644 --- a/tests/handlers/test_model_handler.py +++ b/tests/handlers/test_model_handler.py @@ -134,67 +134,3 @@ async def test_get__site__filter(self): assert len(results["results"]) == 1 assert results["results"][0]["site"] == "texas-tribune" - - @tornado.testing.gen_test - async def test_patch__no_admin_token__throws_error(self): - response = await self.http_client.fetch( - self.get_url(f"{self._endpoint}/1/set_current"), - method="PATCH", - raise_error=False, - allow_nonstandard_methods=True, - ) - - assert response.code == 401 - - @tornado.testing.gen_test - async def test_patch__wrong_admin_token__throws_error(self): - response = await self.http_client.fetch( - self.get_url(f"{self._endpoint}/1/set_current"), - method="PATCH", - raise_error=False, - allow_nonstandard_methods=True, - headers={"Authorization": "bad-auth"}, - ) - - assert response.code == 403 - - @tornado.testing.gen_test - async def test_patch__missing_resource__throws_error(self): - response = await self.http_client.fetch( - self.get_url(f"{self._endpoint}/1/set_current"), - method="PATCH", - raise_error=False, - allow_nonstandard_methods=True, - headers={"Authorization": config.get("ADMIN_TOKEN")}, - ) - - assert response.code == 404 - - @tornado.testing.gen_test - async def test_patch__good_admin_token__updates_resource(self): - old_current = ModelFactory.create( - status=Status.CURRENT.value, site=Site.TEXAS_TRIBUNE.value - ) - new_current = ModelFactory.create( - status=Status.STALE.value, site=Site.TEXAS_TRIBUNE.value - ) - wrong_site = ModelFactory.create( - status=Status.CURRENT.value, site=Site.WCP.value - ) - - response = await self.http_client.fetch( - self.get_url(f"{self._endpoint}/{new_current['id']}/set_current"), - method="PATCH", - raise_error=False, - allow_nonstandard_methods=True, - headers={"Authorization": config.get("ADMIN_TOKEN")}, - ) - - assert response.code == 200 - - old_current = get_resource(Model, old_current["id"]) - new_current = get_resource(Model, new_current["id"]) - wrong_site = get_resource(Model, wrong_site["id"]) - assert old_current["status"] == Status.STALE.value - assert new_current["status"] == Status.CURRENT.value - assert wrong_site["status"] == Status.CURRENT.value