def test_get_all_returns_all_when_catalog_contains_one_entry(self): repo = CatalogRepo(TEST_SESSION_FACTORY) user_repo = UserRepo(TEST_SESSION_FACTORY) owner = User(username="******", email="bob@bob") user_repo.add_user(owner) catalog = Catalog(owner_id=owner.id, name="Bob's catalog.") repo.add(catalog) catalogs = repo.get_all() self.assertEqual(1, len(catalogs)) self.assertEqual(owner.id, catalogs[0].owner_id) self.assertEqual(catalog.name, catalogs[0].name) self.assertIsNone(catalogs[0].description) self.assertIsNotNone(catalogs[0].created_at_utc)
def test_get_all_returns_all_when_catalog_contains_more_than_one_entry(self): repo = CatalogRepo(TEST_SESSION_FACTORY) user_repo = UserRepo(TEST_SESSION_FACTORY) owner = User(username="******", email="bob@bob") user_repo.add_user(owner) expected_catalogs = [] expected_catalogs.append(Catalog(owner_id=owner.id, name="A")) expected_catalogs.append(Catalog(owner_id=owner.id, name="B")) expected_catalogs.append(Catalog(owner_id=owner.id, name="C")) for catalog in expected_catalogs: repo.add(catalog) actual_catalogs = repo.get_all() self.assertEqual(sorted(expected_catalogs), sorted(actual_catalogs))
def test_can_add_two_catalogs_with_same_name_and_different_owner(self): repo = CatalogRepo(TEST_SESSION_FACTORY) user_repo = UserRepo(TEST_SESSION_FACTORY) bob = User(username="******", email="bob@bob") user_repo.add_user(bob) tony = User(username="******", email="tony@tony") user_repo.add_user(tony) expected_catalogs = [] catalog = Catalog(owner_id=bob.id, name="A") expected_catalogs.append(catalog) repo.add(catalog) catalog = Catalog(owner_id=tony.id, name="A") repo.add(catalog) expected_catalogs.append(catalog) self.assertEqual(sorted(expected_catalogs), sorted(repo.get_all()))
def test_blank_database_has_no_catalogs(self): repo = CatalogRepo(TEST_SESSION_FACTORY) self.assertEqual([], repo.get_all())