def setUp(self): _tags = { 'tracknumber': ['1/2'], 'title': ['One Love'], 'artist': ['Bob Marley'], 'album': ['Exodus'] } self._song_name = 'Bob Marley - One Love' self._filename = self._song_name + '.mp3' self._new_filename = 'Dennis Brown - Here I Come.mp3' def getitem(name): return _tags[name] def contains(key): return key in _tags self.mp3 = Mock() self.mp3.__getitem__ = Mock(side_effect=getitem) self.mp3.__setitem__ = Mock() self.mp3.__contains__ = Mock(side_effect=contains) self.mp3.filename = self._filename self.filesystem = Mock() self.template = Mock() self.template.template = DEFAULT_FORMAT self.template.idpattern = FreiTemplate.idpattern self.template.delimiter = FreiTemplate.delimiter self.template.safe_substitute.return_value = self._song_name + ' ' self.song = FreiSong(self.mp3, filesystem=self.filesystem)
def setUp(self): _tags = {'tracknumber': ['1/2'], 'title': ['One Love'], 'artist': ['Bob Marley'], 'album': ['Exodus']} self._song_name = 'Bob Marley - One Love' self._filename = self._song_name + '.mp3' self._new_filename = 'Dennis Brown - Here I Come.mp3' def getitem(name): return _tags[name] def contains(key): return key in _tags self.mp3 = Mock() self.mp3.__getitem__ = Mock(side_effect=getitem) self.mp3.__setitem__ = Mock() self.mp3.__contains__ = Mock(side_effect=contains) self.mp3.filename = self._filename self.filesystem = Mock() self.template = Mock() self.template.template = DEFAULT_FORMAT self.template.idpattern = FreiTemplate.idpattern self.template.delimiter = FreiTemplate.delimiter self.template.safe_substitute.return_value = self._song_name + ' ' self.song = FreiSong(self.mp3, filesystem=self.filesystem)
def get_songs(self, files): return [FreiSong(EasyMP3(file)) for file in files]
class TestFreiSong(unittest.TestCase): def setUp(self): _tags = { 'tracknumber': ['1/2'], 'title': ['One Love'], 'artist': ['Bob Marley'], 'album': ['Exodus'] } self._song_name = 'Bob Marley - One Love' self._filename = self._song_name + '.mp3' self._new_filename = 'Dennis Brown - Here I Come.mp3' def getitem(name): return _tags[name] def contains(key): return key in _tags self.mp3 = Mock() self.mp3.__getitem__ = Mock(side_effect=getitem) self.mp3.__setitem__ = Mock() self.mp3.__contains__ = Mock(side_effect=contains) self.mp3.filename = self._filename self.filesystem = Mock() self.template = Mock() self.template.template = DEFAULT_FORMAT self.template.idpattern = FreiTemplate.idpattern self.template.delimiter = FreiTemplate.delimiter self.template.safe_substitute.return_value = self._song_name + ' ' self.song = FreiSong(self.mp3, filesystem=self.filesystem) def test_getitem(self): self.assertEqual('Bob Marley', self.song['artist']) self.assertEqual('01', self.song['tracknumber']) self.assertEqual('', self.song['foo']) def test_setitem(self): self.song['title'] = 'Here I Come' self.mp3.__setitem__.assert_called_with('title', 'Here I Come') self.song['foo'] = 'bar' self.mp3.__setitem__.assert_not_called_with('foo', 'bar') def test_contains(self): self.assertTrue('artist' in self.song) def test_update(self): self.song.update({ 'artist': 'Dennis Brown', 'title': 'Here I Come', 'foo': 'bar' }) self.mp3.update.assert_called_with({ 'artist': 'Dennis Brown', 'title': 'Here I Come' }) def test_save(self): self.song.filename = self._new_filename self.song.save() self.mp3.save.assert_called_with() self.assertEquals(self._new_filename, self.mp3.filename) self.filesystem.rename.assert_called_with(self._filename, self._new_filename) self.song.save() self.filesystem.rename.assert_not_called_with(self._new_filename, self._new_filename)
class TestFreiSong(unittest.TestCase): def setUp(self): _tags = {'tracknumber': ['1/2'], 'title': ['One Love'], 'artist': ['Bob Marley'], 'album': ['Exodus']} self._song_name = 'Bob Marley - One Love' self._filename = self._song_name + '.mp3' self._new_filename = 'Dennis Brown - Here I Come.mp3' def getitem(name): return _tags[name] def contains(key): return key in _tags self.mp3 = Mock() self.mp3.__getitem__ = Mock(side_effect=getitem) self.mp3.__setitem__ = Mock() self.mp3.__contains__ = Mock(side_effect=contains) self.mp3.filename = self._filename self.filesystem = Mock() self.template = Mock() self.template.template = DEFAULT_FORMAT self.template.idpattern = FreiTemplate.idpattern self.template.delimiter = FreiTemplate.delimiter self.template.safe_substitute.return_value = self._song_name + ' ' self.song = FreiSong(self.mp3, filesystem=self.filesystem) def test_getitem(self): self.assertEqual('Bob Marley', self.song['artist']) self.assertEqual('01', self.song['tracknumber']) self.assertEqual('', self.song['foo']) def test_setitem(self): self.song['title'] = 'Here I Come' self.mp3.__setitem__.assert_called_with('title', 'Here I Come') self.song['foo'] = 'bar' self.mp3.__setitem__.assert_not_called_with('foo', 'bar') def test_contains(self): self.assertTrue('artist' in self.song) def test_update(self): self.song.update({'artist': 'Dennis Brown', 'title': 'Here I Come', 'foo': 'bar'}) self.mp3.update.assert_called_with({'artist': 'Dennis Brown', 'title': 'Here I Come'}) def test_save(self): self.song.filename = self._new_filename self.song.save() self.mp3.save.assert_called_with() self.assertEquals(self._new_filename, self.mp3.filename) self.filesystem.rename.assert_called_with(self._filename, self._new_filename) self.song.save() self.filesystem.rename.assert_not_called_with(self._new_filename, self._new_filename)