Beispiel #1
0
    def test_ls(self):
        from pycdstar.commands import c_ls

        res = c_ls(get_api(obj=object(bitstream=[])), args({"<URL>": "a", "-s": True}))
        assert len(list(res)) == 0
        res = c_ls(get_api(obj=object(bitstream=[defaultdict(lambda: 1)])), args({"<URL>": "a"}, default=True))
        assert len(list(res)) == 1
Beispiel #2
0
    def test_Object(self):
        from pycdstar.resource import Object, Bitstream, ACL

        api = get_api(ret={'uid': 'abc'})
        obj = Object(api)
        assert api._req.called
        self.assertEquals(obj.id, 'abc')
        self.assertIn('uid', obj.read())

        api = get_api()
        obj = Object(api)
        assert obj.metadata
        obj.metadata = {}

        api = get_api(ret=MagicMock(status_code=404))
        obj = Object(api)
        obj.metadata = {}

        api = get_api(ret={
            'uid': 1, 'bitstreamid': 0, 'bitstream': [{'bitstreamid': 0}]})
        obj = Object(api)
        self.assertEquals(len(obj.bitstreams), 1)
        bs = obj.add_bitstream(fname=test_file('test.json'), name='test.json')
        self.assertIsInstance(bs, Bitstream)
        bs.update(fname=test_file('test.json'))
        with self.assertRaises(AttributeError):
            bs.read()  # FIXME: find way to actually test this!

        api = get_api(ret={'uid': 1, 'read': [], 'write': [], 'manage': []})
        obj = Object(api)
        acl = obj.acl
        self.assertIsInstance(acl, ACL)
        acl.update(read=['me'])
Beispiel #3
0
    def test_Resource(self):
        from pycdstar.resource import Resource

        self.assertRaises(NotImplementedError, Resource, get_api())
        rsc = Resource(get_api(), id='1')
        self.assertTrue(rsc.exists())
        self.assertRaises(NotImplementedError, rsc.update)
        rsc.delete()

        rsc = Resource(get_api(), id='1', obj='2')
        assert rsc.path
Beispiel #4
0
    def test_create(self):
        from pycdstar.commands import c_create

        res = list(
            c_create(
                get_api(),
                args({"<DIR>": ".", "--metadata": "{}", "--include": "*.py", "--exclude": "*.pyc"}),
                verbose=True,
            )
        )
        assert res
Beispiel #5
0
    def test_delete(self):
        from pycdstar.commands import c_delete

        assert c_delete(get_api(obj=object()), args({"<URL>": "a"}), verbose=True)
Beispiel #6
0
    def test_metadata(self):
        from pycdstar.commands import c_metadata

        res = c_metadata(get_api(obj=object()), args({"<URL>": "a"}))
        self.assertIn("uid", res)
        c_metadata(get_api(obj=object()), args({"<URL>": "a", "<JSON>": "{}"}))
Beispiel #7
0
def object(**kw):
    kw.setdefault("uid", "a")
    return Object(get_api(ret=Response(kw)))