-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* added users get endpoint, with required new database operation, and tests for both
- Loading branch information
Showing
5 changed files
with
158 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,6 +66,37 @@ def test_get_user(self): | |
|
||
self.verify_user_data(email, hashed_password, admin) | ||
|
||
|
||
def test_get_all_users(self): | ||
""" | ||
test inserts two new users, then fetches from the table with the db get function and | ||
raw sql to compare the results. Checks the number of returned rows is the same, | ||
and that all of the columns match from each returned row. | ||
""" | ||
|
||
email1 = "[email protected]" | ||
hashed_password = 'examplepasswordhash2' | ||
admin = True | ||
self.create_example_user(email1, hashed_password, admin) | ||
|
||
email2 = "[email protected]" | ||
hashed_password = 'examplepasswordhash3' | ||
admin = True | ||
self.create_example_user(email2, hashed_password, admin) | ||
|
||
users_get_endpoint_result = user.get_all_users(self.database) | ||
|
||
verify_query = """ | ||
SELECT * FROM USERS;""" | ||
self.database.cursor.execute(verify_query) | ||
|
||
verify_rows = [r._asdict() for r in self.database.cursor.fetchall()] | ||
|
||
assert len(verify_rows) == len(users_get_endpoint_result) | ||
|
||
for (email, hashed_password, admin) in [ | ||
(r['email'], r['hashed_password'], r['admin']) for r in users_get_endpoint_result]: | ||
self.verify_user_data(email, hashed_password, admin) | ||
def test_get_missing_user(self): | ||
|
||
email = "[email protected]" | ||
|
@@ -92,6 +123,8 @@ def create_example_user(self, email, hashed_password, admin): | |
|
||
#Helper function | ||
def verify_user_data(self, email, hashed_password, admin): | ||
# is passed the data obtained from the app feature e.g. a database function, | ||
# and checks the fields match a second, raw SQL query. | ||
|
||
verify_query = """ | ||
SELECT USERS.user_id::text, email, admin, hashed_password, auth_id::text, date_created, date_modified | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters