Exemplo n.º 1
0
    def __tag_results(self, results):
        from disco.ddfs import DDFS
        ddfs = DDFS()
        results_tag = results[0]
        ddfs.put(self.docset.ddfs_link_file_tag, list(ddfs.blobs(results_tag)))

        # remove old, temporary tag
        ddfs.delete(results_tag)
Exemplo n.º 2
0
class DDFSWriteTestCase(DiscoTestCase):
    def setUp(self):
        self.ddfs = DDFS(self.disco_master_url)

    def test_chunk(self):
        from disco.core import RecordIter
        url = 'http://discoproject.org/media/text/chekhov.txt'
        self.ddfs.chunk('disco:test:chunk', [url], chunk_size=100*1024)
        self.assert_(0 < len(list(self.ddfs.blobs('disco:test:chunk'))) <= 4)
        self.assert_(list(RecordIter(['tag://disco:test:chunk'])),
                     list(RecordIter([url], reader=None)))
        self.ddfs.delete('disco:test:chunk')

    def test_push(self):
        self.ddfs.push('disco:test:blobs', [(StringIO('blobdata'), 'blobdata')])
        self.assert_(self.ddfs.exists('disco:test:blobs'))
        self.ddfs.push('tag://disco:test:blobs2', [(StringIO('blobdata'), 'blobdata')])
        self.assert_(self.ddfs.exists('disco:test:blobs2'))
        self.ddfs.delete('disco:test:blobs')
        self.assert_(not self.ddfs.exists('disco:test:blobs'))
        self.ddfs.delete('disco:test:blobs2')
        self.assert_(not self.ddfs.exists('disco:test:blobs2'))

    def test_tag(self):
        self.ddfs.tag('disco:test:tag', [['urls']])
        self.assert_(self.ddfs.exists('disco:test:tag'))
        self.ddfs.delete('disco:test:tag')
        self.assert_(not self.ddfs.exists('disco:test:tag'))
        self.ddfs.tag('tag://disco:test:tag', [['urls']])
        self.assert_(self.ddfs.exists('tag://disco:test:tag'))
        self.ddfs.tag('disco:test:tag', [['more_urls']])
        self.assertEquals(sorted(self.ddfs.get('disco:test:tag')['urls']),
                          sorted([['urls'], ['more_urls']]))
        self.ddfs.delete('tag://disco:test:tag')
        self.assert_(not self.ddfs.exists('tag://disco:test:tag'))

    def test_put(self):
        self.ddfs.put('disco:test:tag', [['urls']])
        self.assert_(self.ddfs.exists('disco:test:tag'))
        self.assertEquals(self.ddfs.get('disco:test:tag')['urls'], [['urls']])
        self.ddfs.put('disco:test:tag', [['tags']])
        self.assertEquals(self.ddfs.get('disco:test:tag')['urls'], [['tags']])
        self.ddfs.delete('tag://disco:test:tag')

    def test_delete(self):
        self.ddfs.delete('disco:test:notag')

    def tearDown(self):
        self.ddfs.delete('disco:test:notag')
        self.ddfs.delete('disco:test:tag')
        self.ddfs.delete('disco:test:blobs')
        self.ddfs.delete('disco:test:blobs2')
Exemplo n.º 3
0
class DDFSWriteTestCase(DiscoTestCase):
    def setUp(self):
        self.ddfs = DDFS(self.disco_master_url)

    def test_push(self):
        from cStringIO import StringIO
        self.ddfs.push('disco:test:blobs', [(StringIO('blobdata'), 'blobdata')])
        self.assert_(self.ddfs.exists('disco:test:blobs'))
        self.ddfs.push('tag://disco:test:blobs2', [(StringIO('blobdata'), 'blobdata')])
        self.assert_(self.ddfs.exists('disco:test:blobs2'))
        self.ddfs.delete('disco:test:blobs')
        self.assert_(not self.ddfs.exists('disco:test:blobs'))
        self.ddfs.delete('disco:test:blobs2')
        self.assert_(not self.ddfs.exists('disco:test:blobs2'))

    def test_tag(self):
        self.ddfs.tag('disco:test:tag', [['urls']])
        self.assert_(self.ddfs.exists('disco:test:tag'))
        self.ddfs.delete('disco:test:tag')
        self.assert_(not self.ddfs.exists('disco:test:tag'))
        self.ddfs.tag('tag://disco:test:tag', [['urls']])
        self.assert_(self.ddfs.exists('tag://disco:test:tag'))
        self.ddfs.tag('disco:test:tag', [['more_urls']])
        self.assertEquals(sorted(self.ddfs.get('disco:test:tag')['urls']),
                          sorted([['urls'], ['more_urls']]))
        self.ddfs.delete('tag://disco:test:tag')
        self.assert_(not self.ddfs.exists('tag://disco:test:tag'))

    def test_put(self):
        self.ddfs.put('disco:test:tag', [['urls']])
        self.assert_(self.ddfs.exists('disco:test:tag'))
        self.assertEquals(self.ddfs.get('disco:test:tag')['urls'], [['urls']])
        self.ddfs.put('disco:test:tag', [['tags']])
        self.assertEquals(self.ddfs.get('disco:test:tag')['urls'], [['tags']])
        self.ddfs.delete('tag://disco:test:tag')

    def test_delete(self):
        self.ddfs.delete('disco:test:notag')
Exemplo n.º 4
0
class DDFSAuthTestCase(DiscoTestCase):
    def setUp(self):
        self.ddfs = DDFS(self.disco_master_url)
        self.ddfs.push('disco:test:authrd', [(StringIO('datablob'), 'blobdata')])
        self.ddfs.push('disco:test:authwr', [(StringIO('datablob'), 'blobdata')])
        self.ddfs.setattr('disco:test:authrd', 'a', 'v')
        self.ddfs.setattr('disco:test:authwr', 'a', 'v')
        self.ddfs.setattr('disco:test:authrd', 'ddfs:read-token', 'rdr')
        self.ddfs.setattr('disco:test:authwr', 'ddfs:write-token', 'wtr')

    def test_write_noread(self):
        self.assertEquals(self.ddfs.getattr('disco:test:authwr', 'a'), 'v')
        self.assertEquals(self.ddfs.getattr('disco:test:authwr', 'a', token='rand'), 'v')

    def test_write_noread2(self):
        self.assertCommErrorCode(401, lambda: self.ddfs.setattr('disco:test:authwr', 'a2', 'v2'))
        rand_setter = lambda: self.ddfs.setattr('disco:test:authwr', 'a2', 'v2', token='rand')
        self.assertCommErrorCode(401, rand_setter)
        self.ddfs.setattr('disco:test:authwr', 'a2', 'v2', token='wtr')
        self.ddfs.delattr('disco:test:authwr', 'a2', token='wtr')

    def test_write_noread3(self):
        setter = lambda: self.ddfs.setattr('disco:test:authwr', 'ddfs:read-token', 'r')
        self.assertCommErrorCode(401, setter)
        self.ddfs.setattr('disco:test:authwr', 'ddfs:read-token', 'r', token='wtr')
        self.assertCommErrorCode(401, lambda: self.ddfs.getattr('disco:test:authwr', 'a'))
        self.assertEquals(self.ddfs.getattr('disco:test:authwr', 'a', token='r'), 'v')
        self.ddfs.delattr('disco:test:authwr', 'ddfs:read-token', token='wtr')

    def test_read_nowrite(self):
        self.assertCommErrorCode(401, lambda: self.ddfs.getattr('disco:test:authrd', 'a'))
        rand_getter = lambda: self.ddfs.getattr('disco:test:authrd', 'a', token='rand')
        self.assertCommErrorCode(401, rand_getter)
        self.assertEquals(self.ddfs.getattr('disco:test:authrd', 'a', token='rdr'), 'v')

    def test_read_nowrite2(self):
        self.ddfs.setattr('disco:test:authrd', 'a2', 'v2')
        self.assertEquals(self.ddfs.getattr('disco:test:authrd', 'a2', token='rdr'), 'v2')
        self.ddfs.delattr('disco:test:authrd', 'a2', token='rand')

    def test_read_nowrite3(self):
        self.ddfs.setattr('disco:test:authrd', 'ddfs:read-token', 'r')
        self.ddfs.setattr('disco:test:authrd', 'ddfs:read-token', 'rdr')

    def test_atomic_token(self):
        self.ddfs.push('disco:test:atomic1',
                        [(StringIO('abc'), 'atom')],
                        update=True,
                        delayed=True,
                        token='secret1')
        getter = lambda: self.ddfs.getattr('disco:test:atomic1', 'foobar')
        self.assertCommErrorCode(401, getter)
        self.assertEquals(self.ddfs.getattr('disco:test:atomic1',
                                            'ddfs:write-token',
                                            token='secret1'), 'secret1')
        self.ddfs.put('disco:test:atomic2', [], token='secret2')
        getter = lambda: self.ddfs.getattr('disco:test:atomic2', 'foobar')
        self.assertCommErrorCode(401, getter)
        self.assertEquals(self.ddfs.getattr('disco:test:atomic2',
                                            'ddfs:write-token',
                                            token='secret2'), 'secret2')
        self.ddfs.put('disco:test:notoken', [])
        self.assertEquals(self.ddfs.getattr('disco:test:notoken',
                                            'ddfs:write-token'), None)

    def tearDown(self):
        self.ddfs.delete('disco:test:authrd')
        self.ddfs.delete('disco:test:authwr', token='wtr')
        self.ddfs.delete('disco:test:atomic1', token='secret1')
        self.ddfs.delete('disco:test:atomic2', token='secret2')
        self.ddfs.delete('disco:test:notoken')