Skip to content

Commit

Permalink
Query db read endpoint (#44)
Browse files Browse the repository at this point in the history
* [change] send queries to db read endpoint

* [remove] model patch handler
  • Loading branch information
tngzng authored Apr 18, 2022
1 parent 61deda0 commit 3a094f6
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 76 deletions.
4 changes: 2 additions & 2 deletions env.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"
}
Expand Down
10 changes: 0 additions & 10 deletions handlers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
64 changes: 0 additions & 64 deletions tests/handlers/test_model_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3a094f6

Please sign in to comment.