Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev setup #1

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions service/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,20 @@ def check_content_type(media_type):
status.HTTP_415_UNSUPPORTED_MEDIA_TYPE,
f"Content-Type must be {media_type}",
)

######################################################################
# READ AN ACCOUNT
######################################################################
@app.route("/accounts/<int:account_id>", methods=["GET"])
def get_accounts(account_id):
"""
Reads an Account
This endpoint will read an Account based the account_id that is requested
"""
app.logger.info("Request to read an Account with id: %s", account_id)

account = Account.find(account_id)
if not account:
abort(status.HTTP_404_NOT_FOUND, f"Account with id [{account_id}] could not be found.")

return account.serialize(), status.HTTP_200_OK
8 changes: 7 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
[nosetests]
verbosity=1
verbosity=2
with-spec=1
spec-color=1
with-coverage=1
cover-erase=1
cover-package=service


[coverage:report]
show_missing = True
Expand Down
15 changes: 15 additions & 0 deletions tests/test_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,18 @@ def test_unsupported_media_type(self):
self.assertEqual(response.status_code, status.HTTP_415_UNSUPPORTED_MEDIA_TYPE)

# ADD YOUR TEST CASES HERE ...

def test_get_account(self):
"""It should Read a single Account"""
account = self._create_accounts(1)[0]
resp = self.client.get(
f"{BASE_URL}/{account.id}", content_type="application/json"
)
self.assertEqual(resp.status_code, status.HTTP_200_OK)
data = resp.get_json()
self.assertEqual(data["name"], account.name)

def test_get_account_not_found(self):
"""It should not Read an Account that is not found"""
resp = self.client.get(f"{BASE_URL}/0")
self.assertEqual(resp.status_code, status.HTTP_404_NOT_FOUND)