Skip to content
This repository has been archived by the owner on Jan 7, 2024. It is now read-only.

Commit

Permalink
Add API proxy test
Browse files Browse the repository at this point in the history
  • Loading branch information
eloquence authored and sssoleileraaa committed Oct 13, 2020
1 parent 3d2a5a8 commit ce2257b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions data/test_get_users.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"{\"body\": \"{\\\"passphrase\\\": \\\"correct horse battery staple profanity oil chewy\\\", \\\"username\\\": \\\"journalist\\\"}\", \"method\": \"POST\", \"path_query\": \"api/v1/token\", \"timeout\": 20}+1": "{\"status\": 200, \"body\": \"{\\\"expiration\\\":\\\"2020-10-10T04:06:41.835560Z\\\",\\\"journalist_first_name\\\":\\\"\\\",\\\"journalist_last_name\\\":\\\"\\\",\\\"journalist_uuid\\\":\\\"2ef9ec39-696d-4707-a1bf-4c00aa726468\\\",\\\"token\\\":\\\"eyJhbGciOiJIUzI1NiIsImV4cCI6MTYwMjMwMjgwMSwiaWF0IjoxNjAyMjc0MDAxfQ.eyJpZCI6MX0.vcLFjEKqEbQ12Vbky9eurp_yQEznGk1KFFVKc_ZaE2A\\\"}\\n\", \"headers\": {\"Content-Type\": \"application/json\", \"Content-Length\": \"288\", \"Server\": \"Werkzeug/0.16.0 Python/3.5.2\", \"Date\": \"Fri, 09 Oct 2020 20:06:41 GMT\"}, \"version\": \"0.3.0\\n\"}", "{\"headers\": \"{\\\"Accept\\\": \\\"application/json\\\", \\\"Content-Type\\\": \\\"application/json\\\"}\", \"method\": \"GET\", \"path_query\": \"api/v1/users\", \"timeout\": 20}+1": "{\"status\": 200, \"body\": \"{\\\"users\\\":[{\\\"first_name\\\":\\\"\\\",\\\"last_name\\\":\\\"\\\",\\\"username\\\":\\\"journalist\\\",\\\"uuid\\\":\\\"2ef9ec39-696d-4707-a1bf-4c00aa726468\\\"},{\\\"first_name\\\":\\\"\\\",\\\"last_name\\\":\\\"\\\",\\\"username\\\":\\\"dellsberg\\\",\\\"uuid\\\":\\\"c9729e59-6c4b-4f56-9f6f-4a87eb22d130\\\"}]}\\n\", \"headers\": {\"Content-Type\": \"application/json\", \"Content-Length\": \"217\", \"Server\": \"Werkzeug/0.16.0 Python/3.5.2\", \"Date\": \"Fri, 09 Oct 2020 20:06:42 GMT\"}, \"version\": \"0.3.0\\n\"}"}
14 changes: 14 additions & 0 deletions tests/test_apiproxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,20 @@ def test_get_current_user(self):
self.assertTrue("first_name" in user)
self.assertTrue("last_name" in user)

@dastollervey_datasaver
def test_get_users(self):
users = self.api.get_users()
for user in users:
# Assert expected fields are present
assert hasattr(user, "first_name")
assert hasattr(user, "last_name")
# Every user has a non-empty name and UUID
assert user.username
assert user.uuid
# The API should never return these fields
assert not hasattr(user, "last_login")
assert not hasattr(user, "is_admin")

@dastollervey_datasaver
def test_error_unencrypted_reply(self):
s = self.api.get_sources()[0]
Expand Down

0 comments on commit ce2257b

Please sign in to comment.