def test_check_existing_dirs_file_added(self, get_mp3_files, listdir, match, meta): files = ["one.mp3", "two.mp3", "three.mp3"] get_mp3_files.return_value = files listdir.return_value = files ids = { "/a/directory/audio/subdir/one.mp3": { "meta": { "recordingid": self.file1id } }, "/a/directory/audio/subdir/two.mp3": { "meta": { "recordingid": self.file2id } } } def metadata_side(path, *args, **kwargs): return ids[path] meta.side_effect = metadata_side jobs._check_existing_directories(self.collection) match.assert_called_once_with(self.collection.collectionid, "/a/directory/audio/subdir")
def test_check_existing_dirs_file_removed(self, listdir, meta): listdir.return_value = ["one.mp3"] meta.return_value = {"meta": {"recordingid": self.file1id}} self.assertEqual(2, len(self.directory.collectionfile_set.all())) jobs._check_existing_directories(self.collection) self.assertEqual(1, len(self.directory.collectionfile_set.all()))
def test_check_existing_dirs_file_added(self, listdir, match, meta): listdir.return_value = ["one.mp3", "two.mp3", "three.mp3"] ids = {"/a/directory/audio/subdir/one.mp3": {"meta": {"recordingid": self.file1id}}, "/a/directory/audio/subdir/two.mp3": {"meta": {"recordingid": self.file2id}}} def metadata_side(path, *args, **kwargs): return ids[path] meta.side_effect = metadata_side jobs._check_existing_directories(self.collection) match.assert_called_once_with(self.collection.collectionid, "/a/directory/audio/subdir")
def test_check_existing_dirs_file_changed(self, meta, listdir): newuuid = str(uuid.uuid4()) def metadata_side(path, *args, **kwargs): if path == "/a/directory/audio/subdir/one.mp3": return {"meta": {"recordingid": self.file1id}} elif path == "/a/directory/audio/subdir/two.mp3": return {"meta": {"recordingid": newuuid}} listdir.return_value = ["one.mp3", "two.mp3"] meta.side_effect = metadata_side jobs._check_existing_directories(self.collection) cf = models.CollectionFile.objects.get(pk=self.file2.pk) self.assertEqual(str(cf.recordingid), newuuid)