def test_insert(self): # Given fixture = ShopFixture() fixture.create2Shops() givenShop01 = fixture.shops[0] givenShop02 = fixture.shops[1] sut = TinyShopDao(self.testDBPath) sut.connection.open() # When sut.insert(data=givenShop01) # Then allShops = sut.loadAll() self.assertIsInstance(allShops, list) self.assertEqual(1, len(allShops)) self.assertEqual(givenShop01, allShops[0]) # When sut.insert(data=givenShop02) # Then # We use client code here for convenience to convert saved data back to # Shop objects, which is not perfect. allShops = sut.loadAll() self.assertIsInstance(allShops, list) self.assertEqual(2, len(allShops)) self.assertEqual(givenShop01, allShops[0]) self.assertEqual(givenShop02, allShops[1]) sut.connection.close()
def test_loadAll(self): # Given assert self.testDBPath.exists() # Precondition for the test fixture = ShopFixture() fixture.create2Shops() # Generate test-data sut = TinyShopDao(self.testDBPath) sut.connection.open() sut.saveAll(data=fixture.shops) # When # We use client code here for convenience to convert saved data back to # Shop objects, which is not perfect. loadedShops = sut.loadAll() sut.connection.close() # Then self.assertIsInstance(loadedShops, list) self.assertEqual(2, len(loadedShops)) self.assertEqual(fixture.shops[0], loadedShops[0]) self.assertEqual(fixture.shops[1], loadedShops[1])