Skip to content

Commit

Permalink
Refactor prices module to handle digital prices
Browse files Browse the repository at this point in the history
  • Loading branch information
bpepple committed Oct 21, 2021
1 parent dd92425 commit dfffdd1
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
16 changes: 5 additions & 11 deletions esak/prices.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@


class Prices:
def __init__(self, print=None, **kwargs):
self.print = print
self.unknown = kwargs
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)


class PriceSchemas(Schema):
printPrice = fields.Float(attribute="print")

# Supposedly digital prices could also be listed, but I
# couldn't find any refences so made a guess what I thought
# it would be. I'll leave it here in case we need it in the
# future.

# digitalPrice = fields.Float(attribute="digital")
printPrice = fields.Decimal(places=2, allow_none=True, attribute="print")
digitalPurchasePrice = fields.Decimal(places=2, allow_none=True, attribute="digital")

class Meta:
unknown = INCLUDE
Expand Down
18 changes: 15 additions & 3 deletions tests/comic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
Test Comic module.
This module contains tests for Comic objects.
"""
from decimal import Decimal


def test_pulls_verbose(talker):
Expand Down Expand Up @@ -36,20 +37,19 @@ def test_known_comic(talker):
assert af15.issue_number == 15
assert af15.description is None
assert af15.format == "Comic"
# assert af15.page_count == 36
assert af15.id == 16926
assert "Spider-Man (Peter Parker)" in [c.name for c in af15.characters]
assert "Foo" not in [c.name for c in af15.characters]
assert "Steve Ditko" in [s.name for s in af15.creators]
assert "Abe Lincoln" not in [s.name for s in af15.creators]
# assert af15.prices.print == 0.1
assert af15.prices.print == Decimal("0.00")


def test_invalid_isbn(talker):
"""Sometimes Marvel API sends number for isbn"""
murpg = talker.comic(1143)
assert murpg.isbn == "785110283"
assert murpg.prices.print == 9.99
assert murpg.prices.print == Decimal("9.99")


def test_invalid_diamond_code(talker):
Expand All @@ -61,3 +61,15 @@ def test_invalid_diamond_code(talker):
def test_upc_code(talker):
cable = talker.comic(95781)
assert cable.upc == "759606201991000111"


def test_comic_digital_price(talker):
cw1 = talker.comic(4216)
assert cw1.title == "Civil War (2006) #1"
assert cw1.prices.print == Decimal("0.00")
assert cw1.prices.digital == Decimal("1.99")
assert cw1.series.name == "Civil War (2006 - 2007)"
assert cw1.format == "Comic"
assert cw1.upc == "75960605921800111"
assert cw1.issue_number == 1
assert cw1.digital_id == 5486
Binary file modified tests/testing_mock.sqlite
Binary file not shown.

0 comments on commit dfffdd1

Please sign in to comment.