def test_get_download_file_exception(self): fake_cursor = StrictMock(Cursor, runtime_attrs=["fetchone"]) fake_cursor.fetchone = lambda: [] self.mock_callable(utils, "db_execute").for_call( """ "SELECT song_path \ FROM downloads \ WHERE download_url=? AND accessed=False""", (self.fake_download_url, )).to_raise(FileNotFoundError).and_assert_called_once() with patch.object(pathlib.Path, "exists") as fake_download_db: fake_download_db.return_value = True self.assertIsNone(utils.get_download_file(self.fake_download_url))
def test_get_download_file_successful(self): fake_song = 'path/to/song1' fake_cursor = StrictMock(Cursor, runtime_attrs=["fetchone"]) fake_cursor.fetchone = lambda: [(fake_song)] self.mock_callable(utils, "db_execute").for_call( """ "SELECT song_path \ FROM downloads \ WHERE download_url=? AND accessed=False""", (self.fake_download_url, )).to_return_value(fake_cursor).and_assert_called_once() with patch.object(pathlib.Path, "exists") as fake_download_db: fake_download_db.return_value = True self.assertEqual(pathlib.Path(fake_song), utils.get_download_file(self.fake_download_url))