diff --git a/esak/prices.py b/esak/prices.py index 7b3acca..a235a17 100644 --- a/esak/prices.py +++ b/esak/prices.py @@ -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 diff --git a/esak/session.py b/esak/session.py index c570654..7fc93d3 100644 --- a/esak/session.py +++ b/esak/session.py @@ -1,5 +1,6 @@ import datetime import hashlib +import platform import urllib.parse from collections import OrderedDict from typing import Any, Dict, List, Optional, Union @@ -8,6 +9,7 @@ from marshmallow import ValidationError from esak import ( + __version__, character, characters_list, comic, @@ -92,8 +94,15 @@ def call(self, endpoint: List[Union[str, int]], params: Dict[str, Any] = None) - if cached_response is not None: return cached_response + header = { + "User-Agent": f"esak/{__version__} ({platform.system()}; {platform.release()})" + } self._update_params(params) - response = requests.get(url, params=params) + response = requests.get( + url, + params=params, + headers=header, + ) data = response.json() diff --git a/tests/comic_test.py b/tests/comic_test.py index 5c7bf0d..7b6c281 100644 --- a/tests/comic_test.py +++ b/tests/comic_test.py @@ -2,6 +2,7 @@ Test Comic module. This module contains tests for Comic objects. """ +from decimal import Decimal def test_pulls_verbose(talker): @@ -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): @@ -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 diff --git a/tests/testing_mock.sqlite b/tests/testing_mock.sqlite index 8c78467..8c935eb 100644 Binary files a/tests/testing_mock.sqlite and b/tests/testing_mock.sqlite differ