From dd92425f1252853419a51f19fbc803ebc28d64cb Mon Sep 17 00:00:00 2001 From: Brian Pepple Date: Wed, 20 Oct 2021 22:53:36 -0400 Subject: [PATCH 1/2] Add user-agent to request --- esak/session.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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() From dfffdd1812739f499b993622e0b7c0b5cb76454d Mon Sep 17 00:00:00 2001 From: Brian Pepple Date: Wed, 20 Oct 2021 23:09:11 -0400 Subject: [PATCH 2/2] Refactor prices module to handle digital prices --- esak/prices.py | 16 +++++----------- tests/comic_test.py | 18 +++++++++++++++--- tests/testing_mock.sqlite | Bin 598016 -> 606208 bytes 3 files changed, 20 insertions(+), 14 deletions(-) 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/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 8c784677ad74ae6d7beb8eae41427f65808bd25b..8c935eb5a003fd9411f337adee7139e5ad079bc0 100644 GIT binary patch delta 3418 zcmeHJU2Gd!70!4(PO4=|vrXERrqXe;-2^q0%=q6SYUAd|cB$hKyUDU_6Gu zoSCshin3`z;Q{T#R^H``eE`ZLAs&m^-3O2;Li+>{2zWw5P$A%D7g*qFB^J(%OE;FH z3JI}K`(n?%_ndRjIrlr?Ik)aVee2eRm(EF}eSLi|-+{}*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