def testHtmlFilesListedLastForChangedFiles(self): local_cat = ( Catalogue() .add_file('news/test.jpg.htm', 'GGG', '777') .add_file('flex.js', 'HHH', '888') .add_file('assets/blah.jpg', 'FFF', '666') .add_file('assets/xtr/blam.css', 'III', '999') .add_file('index.html', 'AAA', '111') .add_file('words.txt', 'HHH', '888') .add_file('test/I think, "great.img', 'DDD', '444') .add_file('assets/blah.png', 'EEE', '555') ) remote_cat = ( Catalogue() .add_file('news/test.jpg.htm', 'GGGCHANGED', '777') .add_file('flex.js', 'HHH', '888') .add_file('assets/blah.jpg', 'FFFCHANGED', '666') .add_file('assets/xtr/blam.css', 'IIICHANGED', '999') .add_file('index.html', 'AAACHANGED', '111') .add_file('words.txt', 'HHHCHANGED', '888') .add_file('test/I think, "great.img', 'DDD', '444') .add_file('assets/blah.png', 'EEE', '555') ) diff, new_remote_catalogue = local_cat.diff_dict(remote_cat) cl = change_list(diff) self.assertEqual([ (ChangeReason.CONTENT_CHANGED, 'assets/blah.jpg'), (ChangeReason.CONTENT_CHANGED, 'words.txt'), (ChangeReason.CONTENT_CHANGED, 'assets/xtr/blam.css'), (ChangeReason.CONTENT_CHANGED, 'news/test.jpg.htm'), (ChangeReason.CONTENT_CHANGED, 'index.html') ], cl)
def testHtmlFilesListedLastForNewUploads(self): """ This is a rather crude was of ensuring static assets are available before the HTML documents that reference them. """ local_cat = ( Catalogue() .add_file('news/test.jpg.htm', 'GGG', '777') .add_file('flex.js', 'HHH', '888') .add_file('assets/blah.jpg', 'FFF', '666') .add_file('assets/xtr/blam.css', 'III', '999') .add_file('index.html', 'AAA', '111') .add_file('words.txt', 'HHH', '888') .add_file('test/I think, "great.img', 'DDD', '444') .add_file('assets/blah.png', 'EEE', '555') ) remote_cat = Catalogue() diff, new_remote_catalogue = local_cat.diff_dict(remote_cat) cl = change_list(diff) self.assertEqual([ (ChangeReason.NEW_FILE, 'assets/blah.jpg'), (ChangeReason.NEW_FILE, 'assets/blah.png'), (ChangeReason.NEW_FILE, 'test/I think, "great.img'), (ChangeReason.NEW_FILE, 'words.txt'), (ChangeReason.NEW_FILE, 'assets/xtr/blam.css'), (ChangeReason.NEW_FILE, 'flex.js'), (ChangeReason.NEW_FILE, 'news/test.jpg.htm'), (ChangeReason.NEW_FILE, 'index.html') ], cl)
def test_diff_dict(self): local_cat = ( Catalogue() .add_file('index.html', '9J9J9J', 'P2P2P2') .add_file('assets/blam/160-180.jpg', 'A1A1A1', 'B3B3B3') .add_file('♬ /music.fav.mp3', 200010, '7A9 ') .add_file('robots.txt', '4b4b4b', '929292') .add_file('consistent.html.html', '123', '123') .add_file('news_update.html', '4b4b4b', '929292') ) remote_cat = ( Catalogue() .add_file('assets/blam/160-180.jpg', 'A1A1A1', '9S9S95') .add_file('consistent.html.html', '123', '123') .add_file('index.html', '282828', 'P2P2P2') .add_file('♬ /music.fav.mp3', 200010, '7A9 ') .add_file('robots.txt', 'asdfhl', 'lkjfds') .add_file('tempfile.txt', 'fj8fj8', 'flwlfwl') ) diff_dict, new_remote_catalogue = local_cat.diff_dict(remote_cat) expected = { 'num_changes': 5, 'upload': { 'new_files': ['news_update.html'], 'content_changed': ['index.html', 'robots.txt'], 'attributes_changed': ['assets/blam/160-180.jpg'] }, 'delete': ['tempfile.txt'], 'delete_protected': [], 'unchanged': ['consistent.html.html', '♬ /music.fav.mp3'] } self.assertEqual(expected, diff_dict)
def setUp(self): self.simple_cat = Catalogue() self.simple_cat.add_file('test/blah.img', 'AABBCC', 'XXYYZZ') self.edgecase_cat = ( Catalogue() .add_file('test/blah.img', 'AABBCC', 'XXYYZZ') .add_file('test/blah.img', 'AABBCC', '112233') # Same file .add_file('fest_ЬℓσБ: &8>', 'FS FSFS', '7A9 ') # Unicode .add_file('♬ /music.fav.mp3', 200010, '7A9 ') # Integer hash .add_file('test/I think, "great.img', 'AABBCC', '11,2233') # Comma ) hndl, self.tmpf_path = tempfile.mkstemp() os.close(hndl)
def test_edgecase_from_sqlite_but_newer_version(self): new_version = MAX_DB_SCHEMA_VERSION + 1 with write_gzipped_sqlite(self.tmpf_path) as c: c.execute('PRAGMA user_version = {v:d}'.format(v=new_version)) c.execute('CREATE TABLE dummy ( path TEXT )') ncat = Catalogue() with self.assertRaisesRegex( click.ClickException, 'is version 3.*to version 2'): ncat.from_sqlite(self.tmpf_path)
def test_edgecase_from_sqlite_but_older_version(self): new_version = MAX_DB_SCHEMA_VERSION - 1 with write_gzipped_sqlite(self.tmpf_path) as c: c.execute('PRAGMA user_version = {v:d}'.format(v=new_version)) c.execute('''CREATE TABLE files ( path TEXT, content_hash TEXT, attributes_hash TEXT)''') ncat = Catalogue() ncat.from_sqlite(self.tmpf_path) self.assertEqual({}, ncat.to_dict())
def test_edgecase_from_sqlite(self): self.edgecase_cat.to_sqlite(self.tmpf_path) ncat = Catalogue() ncat.from_sqlite(self.tmpf_path) self.assertEqual(ncat.to_dict(), self.edgecase_cat.to_dict())
def test_edgecase_from_csv(self): self.old_to_csv_from_catalogue(self.edgecase_cat, self.tmpf_path) ncat = Catalogue() ncat.from_csv(self.tmpf_path) self.assertEqual(ncat.to_dict(), self.edgecase_cat.to_dict())