Skip to content

Commit

Permalink
Basic AGCOD mock test. Don't have time to do more/make it better righ…
Browse files Browse the repository at this point in the history
…t now.
  • Loading branch information
davepeck committed Apr 16, 2024
1 parent ac05ed8 commit 2c144d6
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
8 changes: 7 additions & 1 deletion server/utils/agcod.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ def _httpx_invoker(
) -> dict:
"""Invoke an HTTP request."""
response = httpx.request(method, url, content=body, headers=headers)
# TODO: for now, we just blow up in a generic way if the response is bad.
# AGCOD has a specific error format that we should parse and raise to provide
# detail.
response.raise_for_status()
return response.json() # assumes dict-like JSON response
maybe_response = response.json()
if not isinstance(maybe_response, dict):
raise ValueError(f"Unexpected AGCOD response type: {type(maybe_response)}")
return maybe_response


class AmazonClient:
Expand Down
9 changes: 6 additions & 3 deletions server/utils/test_agcod.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,17 @@ def create_gift_card_invoker(self, amount: int = 100):
class CreateGiftCardTestCase(AGCODTextMixin, unittest.TestCase):
"""Test the create_gift_card function."""

# TODO: flesh out the the architecture and tests if I have time

def test_create_gift_card(self):
"""Test creating a gift card."""
invoker = self.create_gift_card_invoker()
client = AGCODTestClient(invoker)
amount = 50
client.create_gift_card(amount)
invoker = self.create_gift_card_invoker(amount)
client = AGCODTestClient(invoker)
response = client.create_gift_card(amount)
call_args = invoker.call_args[0]
self.assertEqual(invoker.call_count, 1)
self.assertEqual(call_args[0], "POST")
self.assertTrue("/CreateGiftCard" in call_args[1])
self.assertTrue("test_partner_id-" in call_args[2].decode())
self.assertEqual(response.card_info.value.amount, amount)
2 changes: 1 addition & 1 deletion server/vb/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.3 on 2024-04-16 17:50
# Generated by Django 5.0.3 on 2024-04-16 20:20

import django.core.validators
import django.db.models.deletion
Expand Down

0 comments on commit 2c144d6

Please sign in to comment.