示例#1
0
def test_SourcesCatalog(tmp_path):
    cat_path = tmp_path / 'test.json'
    with SourcesCatalog(cat_path) as cat:
        cat.add(
            'key', Object('id', [Bitstream('bsid', 5, 'text/plain', '', '', '')], {}))
        assert 'key' in cat
        assert 'url' in cat.get('key')

    assert 'key' in load(str(cat_path))
示例#2
0
def test_idempotency(catalog_path, tmp_catalog_path):
    with catalog_path.open(encoding='utf8') as fp:
        orig = fp.read()
    with Catalog(str(tmp_catalog_path)) as c:
        obj = c[OBJID].asdict()
        obj['metadata'] = OrderedDict(
            sorted(obj['metadata'].items(), reverse=True))
        c[OBJID] = Object.fromdict(OBJID, obj)
    assert orig.split() == tmp_catalog_path.read_text('utf8').split()
示例#3
0
    def test_SourcesCatalog(self):
        from pyconcepticon.util import SourcesCatalog

        cat_path = self.tmp_path('test.json')
        with SourcesCatalog(cat_path) as cat:
            cat.add(
                'key',
                Object('id', [Bitstream('bsid', 5, 'text/plain', '', '', '')],
                       {}))
            self.assertIn('key', cat)
            self.assertIn('url', cat.get('key'))

        self.assertIn('key', load(cat_path))
示例#4
0
# coding: utf8
from __future__ import unicode_literals, print_function, division

from clldutils.path import Path, copy
from clldutils import jsonlib
from cdstarcat.catalog import Object, Bitstream

MOCK_CDSTAR_OBJECT = Object(
    '12345-1234-1234-1234-1',
    [
        Bitstream('thumbnail', 1, 2, 3, 4, 5),
        Bitstream('web', 1, 2, 3, 4, 5),
        Bitstream('other', 1, 2, 3, 4, 5),
    ],
    {},
)


class MockResponse(object):
    headers = {'content-type': 'image/jpeg'}

    def __init__(self, json=None, content='<a>b</a>', text=''):
        self._json = json or {"a": "b"}
        self.content = content
        self.text = text

    def json(self):
        return self._json


class MockRequests(object):