def test_jsondumps(self): from pyimeji.util import jsonload, jsondumps object_test = jsonload( os.path.join(os.path.dirname(__file__), 'test.json')) self.assertIsNotNone(jsondumps(object_test)) self.assertEqual( jsondumps(object_test), open(os.path.join(os.path.dirname(__file__), 'test.json'), mode='rb').read())
# coding=utf8 from __future__ import unicode_literals from unittest import TestCase from datetime import datetime import os from httmock import all_requests, response, HTTMock from pyimeji.util import pkg_path, jsonload, jsondumps SERVICE_URL = 'http://example.org' RESOURCES = { name: jsonload(pkg_path('tests', 'resources', '%s.json' % name)) for name in ['item', 'collection', 'album', 'profile'] } class Response(object): def __init__(self, key, status, content): self.key = key self.status = status self.content = content RESPONSES = {} for path, method, status, content in [ ('items', 'get', 200, jsondumps([{ "id": "Wo1JI_oZNyrfxV_t" }])),
def test_jsonload(self): from pyimeji.util import jsonload self.assertEquals( jsonload(os.path.join(os.path.dirname(__file__), 'test.json'))['status'], 'ok')
def test_jsondumps(self): from pyimeji.util import jsonload, jsondumps object_test = jsonload(os.path.join(os.path.dirname(__file__), 'test.json')) self.assertIsNotNone(jsondumps(object_test)) self.assertEqual(jsondumps(object_test), open(os.path.join(os.path.dirname(__file__), 'test.json'), mode='rb').read())
# coding=utf8 from __future__ import unicode_literals from unittest import TestCase from datetime import datetime import os from httmock import all_requests, response, HTTMock from pyimeji.util import pkg_path, jsonload, jsondumps SERVICE_URL = 'http://example.org' RESOURCES = { name: jsonload(pkg_path('tests', 'resources', '%s.json' % name)) for name in ['item', 'collection', 'album', 'profile']} class Response(object): def __init__(self, key, status, content): self.key = key self.status = status self.content = content RESPONSES = {} for path, method, status, content in [ ('items', 'get', 200, jsondumps([{"id": "Wo1JI_oZNyrfxV_t"}])), ('items', 'post', 201, RESOURCES['item']),
def __setattr__(self, attr, value): if attr == 'metadata' and isinstance(value, string_types): # if a string is passed as metadata, it is interpreted as filename. value = jsonload(value) Resource.__setattr__(self, attr, value)