def test_refresh_removes_non_existing_file_entries(self): # Given p = Project(name='test', path=self.root) p.scan() # When relpath = 'hello.py' m = p.get(relpath) os.remove(m.path) p.refresh() # Then #self.assertEqual(p.number_of_files, 4) self.assertFalse(p.has_media(relpath)) self.assertFalse(relpath in p._media) self.assertFalse(relpath in p._relpath2index) for key in p._data: self.assertEqual(len(p._data[key]), 4) for key in p._tag_data: self.assertEqual(len(p._tag_data[key]), 4) files = [x.name for x in p.root.files] self.assertTrue(relpath not in files) # Check if the database is consistent. for rp in p._relpath2index.keys(): m = p.get(rp) self.assertEqual(m.relpath, rp)
def test_date_ranges_are_searchable(self): # Given fname = join(self.root, 'root.txt') dt = datetime.datetime(2015, 1, 1) ts = time.mktime(dt.timetuple()) os.utime(fname, (ts, ts)) p = Project(name='test', path=self.root) p.scan() # When result = list(p.search("mtime:2015")) # Then self.assertEqual(len(result), 1) self.assertEqual(result[0][0], 'root.txt') # When fname = join(self.root, 'hello.py') dt = datetime.datetime(2015, 2, 1) ts = time.mktime(dt.timetuple()) os.utime(fname, (ts, ts)) p.refresh() result = list(p.search("mtime:2015")) # Then self.assertEqual(len(result), 2) names = sorted(x[0] for x in result) self.assertEqual(names, ['hello.py', 'root.txt']) # When result = list(p.search("mtime:201501")) # Then self.assertEqual(len(result), 1) self.assertEqual(result[0][0], 'root.txt') # When result = list(p.search("mtime:[jan 2015 TO feb 2015]")) # Then self.assertEqual(len(result), 2) names = sorted(x[0] for x in result) self.assertEqual(names, ['hello.py', 'root.txt']) # When result = list(p.search("mtime:>20150202")) # Then self.assertEqual(len(result), 3) names = sorted(x[0] for x in result) self.assertNotIn('hello.py', names) self.assertNotIn('root.txt', names)
def test_refresh_updates_new_media(self): # Given p = Project(name='test', path=self.root) p.scan() self.assertEqual(p.number_of_files, 5) m = p.get('root.txt') orig_size = m.size # Change this. m.tags['completed'] = True create_dummy_file(join(self.root, 'sub', 'sub1.txt')) with open(m.path, 'w') as fp: fp.write('hello world\n') # When p.refresh() # Then m = p.get('root.txt') self.assertEqual(m.tags['completed'], True) self.assertEqual(p.number_of_files, 6) self.assertTrue(m.size > orig_size) m = p.get(join('sub', 'sub1.txt')) self.assertEqual(m.tags['completed'], False)