Ejemplo n.º 1
0
 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())
Ejemplo n.º 2
0
# 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"
    }])),
Ejemplo n.º 3
0
    def test_jsonload(self):
        from pyimeji.util import jsonload

        self.assertEquals(
            jsonload(os.path.join(os.path.dirname(__file__),
                                  'test.json'))['status'], 'ok')
Ejemplo n.º 4
0
 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())
Ejemplo n.º 5
0
    def test_jsonload(self):
        from pyimeji.util import jsonload

        self.assertEquals(
            jsonload(os.path.join(os.path.dirname(__file__), 'test.json'))['status'],
            'ok')
Ejemplo n.º 6
0
# 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']),
Ejemplo n.º 7
0
 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)
Ejemplo n.º 8
0
 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)