Skip to content

Commit

Permalink
Added tons of fields to comic, added more tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkuykendall committed Apr 14, 2016
1 parent 3b23494 commit 64e4ab1
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 17 deletions.
8 changes: 8 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@ marvelous

Marvel API python wrapper.

Contributing
------------

- To run the test suite, run `python -m nose` in the `tests` folder
- When running a new test for the first time, set the environment variables
`PUBLIC_KEY` and `PRIVATE_KEY` to any Marel API keys. The result will be
stored in the `testing_mock` database without your keys.

Examples
--------

Expand Down
5 changes: 2 additions & 3 deletions marvelous/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ def api(public_key=None, private_key=None, cache=False):
except:
raise LibraryError(
"Marvelous only supports cache with requests-cache >= 0.4.11, "
"not yet on pypi. To install development requests-cache, run "
"`pip install git+git://github.com/reclosedev/"
"requests-cache.git`.")
"not yet on pypi. To install the newest requests-cache, run "
"`pip install requests-cache`.")


return Session(public_key, private_key, cached_requests=cache)
28 changes: 23 additions & 5 deletions marvelous/comic.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,38 @@
from marshmallow import Schema, fields, post_load
from marshmallow import Schema, fields, pre_load, post_load
from dates import DatesSchema
from series import SeriesSchema


class Comic():
def __init__(self, title, dates, series):
self.title = title
self.dates = dates
self.series = series
def __init__(self, **kwargs):
for k, v in kwargs.iteritems():
setattr(self, k, v)


class ComicSchema(Schema):
id = fields.Int()
digitalId = fields.Int(attribute='digital_id')
title = fields.Str()
issueNumber = fields.Int(attribute='issue_number')
variantDescription = fields.Str(attribute='variant_description')
description = fields.Str(allow_none=True)
modified = fields.DateTime()
isbn = fields.Str()
up = fields.Str()
diamondCode = fields.Str(attribute='diamond_dode')
ean = fields.Str()
issn = fields.Str()
format = fields.Str()
pageCount = fields.Int(attribute='page_count')
dates = fields.Nested(DatesSchema)
series = fields.Nested(SeriesSchema)

@pre_load
def process_input(self, data):
# print data.keys()
# raise hell
return data

@post_load
def make(self, data):
return Comic(**data)
14 changes: 8 additions & 6 deletions marvelous/series.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@


class Series():
def __init__(self, _id, resource_uri, response=None):
self.response = response
self.id = _id
self.resource_uri = resource_uri
def __init__(self, **kwargs):
if 'response' not in kwargs:
kwargs['response'] = None

for k, v in kwargs.iteritems():
setattr(self, k, v)

def comics(self, params):
return comics_list.ComicsList(
Expand All @@ -16,7 +18,7 @@ def comics(self, params):

class SeriesSchema(Schema):
response = fields.Raw()
_id = fields.Int()
id = fields.Int()
resourceURI = fields.Str(attribute='resource_uri')

@pre_load
Expand All @@ -27,7 +29,7 @@ def process_input(self, data):
data['data']['results'][0]['response'] = data
data = data['data']['results'][0]

data['_id'] = data['resourceURI'].split('/')[-1]
data['id'] = data['resourceURI'].split('/')[-1]
return data

@post_load
Expand Down
5 changes: 4 additions & 1 deletion marvelous/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ def call(self, endpoint, params=None):

return response

def comics(self, params):
def comics(self, params=None):
if params is None:
params = {}

return comics_list.ComicsList(
self.call(['comics'], params=params))

Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
marshmallow==2.6.0
nose==1.3.7
requests==2.9.1
git+git://github.com/reclosedev/requests-cache.git
requests-cache==0.4.12
20 changes: 19 additions & 1 deletion tests/comic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def setUp(self):
public_key=pub, private_key=priv, cache={
'name': 'testing_mock', 'expire_after': None})

def test_pulls(self):
def test_pulls_verbose(self):
week = self.m.comics({
'format': "comic",
'formatType': "comic",
Expand All @@ -21,5 +21,23 @@ def test_pulls(self):

self.assertTrue(len(week.comics) > 0)

def test_pulls_simple(self):
week = self.m.comics({'dateDescriptor': "thisWeek"})
self.assertTrue(len(week.comics) > 0)

def test_pulls_simpler(self):
week = self.m.comics()
self.assertTrue(len(week.comics) > 0)

def test_known_comic(self):
af15 = self.m.comics({'digitalId': 4746}).comics[0]
self.assertTrue(af15.title == "Amazing Fantasy (1962) #15")
self.assertTrue(af15.issue_number == 15)
self.assertTrue(af15.description is None)
self.assertTrue(af15.format == "Comic")
self.assertTrue(af15.page_count == 36)
self.assertTrue(af15.id == 16926)


if __name__ == '__main__':
unittest.main()
Binary file modified tests/testing_mock.sqlite
Binary file not shown.

0 comments on commit 64e4ab1

Please sign in to comment.