def tag(args): """ Tag file with metadata. """ args.collection.metadata[args.key] = args.value coda.add(args.collection) return
def setUp(): global __user_config__ cwd = os.path.dirname(os.path.realpath(__file__)) coda.db.__user_config__ = os.path.join(cwd, 'resources', '.coda') coda.db.options() coda.db.session.db.files.drop() coda.add(cl) return
def test_delete(self): path = os.path.realpath(__file__) fi = coda.File(path) coda.add(fi) self.call('delete', path) fi = coda.find_one({'path': path}) self.assertEqual(fi, None) return
def test_find(self): path = os.path.realpath(__file__) fi = coda.File(path=path, metadata={ 'cohort': 'testing', 'ext': 'py', 'type': 'source' }) coda.add(fi) res = self.call('find', 'cohort', 'testing') self.assertTrue('tests/test_coda.py' in res) coda.delete(fi) return
def test_metadata(self): # test metadata setting one = os.path.join(__resources__, 'simple', 'one.txt') fi = coda.File(one, metadata={'one': 1}) self.assertEqual(fi.one, 1) fi.two = 2 self.assertEqual(fi.metadata.two, 2) # test implicit querying for files already in the database coda.add(fi) fi2 = coda.File(one) self.assertEqual(fi.one, 1) self.assertEqual(fi.metadata.one, 1) coda.delete(fi) return
def test_list(self): path = os.path.realpath(__file__) fi = coda.File(path=path, metadata={ 'cohort': 'testing', 'ext': 'py', 'type': 'source' }) coda.add(fi) res = self.call('list') self.assertTrue('tests/test_coda.py' in res) res = self.call('list', path) self.assertTrue('"cohort": "testing"' in res) self.assertTrue('"ext": "py"' in res) self.assertTrue('"type": "source"' in res) coda.delete(fi) return
def test_add_delete(self, path): # add fi = coda.File(path=path, metadata={ 'cohort': 'testing', 'ext': 'py', 'type': 'source' }) coda.add(fi) cl = coda.find({'cohort': 'testing'}) self.assertEqual(len(cl), 1) self.assertEqual(cl[0].type, 'source') # update fi.metadata.type = 'newtype' fi.metadata.keep = True coda.add(fi) cl = coda.find({'cohort': 'testing'}) self.assertEqual(cl[0].type, 'newtype') self.assertEqual(cl[0].keep, True) # delete coda.delete(fi) cl = coda.find({'cohort': 'testing'}) self.assertEqual(cl, None) return
def add(args): """ Add file to internal database for tracking. """ coda.add(args.collection) return