def test_repository_handles_connection_errors(self, repo: Repository) -> None: """ Given: A database url pointing to an inexistent file When: the repository is initialized with an inexistent directory Then: a ConnectionError is raised. This doesn't apply to FakeRepository as it doesn't create a database """ with pytest.raises(ConnectionError): repo.__class__(database_url="/inexistent_dir/database.db") # act
def test_repository_handles_inexistent_database_file( self, repo: Repository, tmpdir: LocalPath) -> None: """ Given: A database url pointing to an inexistent file When: the repository is initialized Then: The object is well initialized, and the database file is created. The FakeRepository should not create any file, as all entities are stored in memory. """ database_url = str(tmpdir.join("inexistent.db")) # type: ignore result = repo.__class__(database_url=database_url) assert isinstance(result, repo.__class__) if result.__class__.__name__ != "FakeRepository": assert os.path.isfile(database_url) result.close()