def test_GetAllLimitedPackages(self): with patch.object( PackageRepository, 'Find', return_value=[ PackageObjectMother.CreatePackageManyPickupNoReturn(), PackageObjectMother.CreatePackageManyPickupNoReturn(), PackageObjectMother.CreatePackageManyPickupPackedNoReturn( ), PackageObjectMother.CreatePackageManyPickupPackedNoReturn( ), PackageObjectMother. CreatePackageManyPickupPackedUnconfirmedReturn(), PackageObjectMother. CreatePackageManyPickupPackedUnconfirmedReturn(), PackageObjectMother. CreateDeliveredPackageManyPickupPackedNoReturn(), PackageObjectMother. CreateDeliveredPackageManyPickupPackedNoReturn(), ]): transportService = TransportService() statuses_obj = Package.FindAllLimitedPackageStatuses() statuses = [status.Name for status in statuses_obj] packages = transportService.GetAllLimitedPackages() for package in packages: self.assertIn(package.GetStatus().Name, statuses)
def test_GetPackageStatusReturnsProperStatus(self): package = PackageObjectMother.CreatePackageManyPickupNoReturn() status = package.GetStatus() with patch.object(PackageRepository, 'Find', return_value=package): shopService = ShopService() assert shopService.GetPackageStatus( package.PackageCode) == status.Name
def test_FindInsertedPackages(self): packageRepository = PackageRepository() package = PackageObjectMother.CreatePackageManyPickupNoReturn() package2 = PackageObjectMother.CreatePackageManyPickupNoReturn() package3 = PackageObjectMother.CreatePackageManyPickupNoReturn() packageRepository.Insert(package) packageRepository.Insert(package2) packageRepository.Insert(package3) assert package.PackageCode == packageRepository.Find( package.PackageCode).PackageCode assert package2.PackageCode == packageRepository.Find( package2.PackageCode).PackageCode assert package3.PackageCode == packageRepository.Find( package3.PackageCode).PackageCode
def test_FindUpdatedPackageReturnsSamePackage(self): packageRepository = PackageRepository() packageRepository.Insert( PackageObjectMother.CreatePackageNoPickupsNoReturn()) packageRepository.Insert( PackageObjectMother.CreatePackageManyPickupNoReturn()) packageRepository.Insert( PackageObjectMother.CreatePackageManyPickupPackedNoReturn()) packageRepository.Insert( PackageObjectMother.CreateDeliveredPackageManyPickupPackedNoReturn( )) packageRepository.Insert( PackageObjectMother.CreatePackageManyPickupPackedUnconfirmedReturn( )) packageRepository.Insert( PackageObjectMother.CreatePackageManyPickupPackedConfirmedReturn()) packages = packageRepository.FindAll() package = packages[0] package.DeliveryDate = datetime(2018, 12, 30) package.GetStatus().NextDeliveryStep() return_ = package.GetReturn() if not return_: package.MakeReturn("Sample text") else: return_.Description = "Sample text" packageRepository.Update(package) packageAfterInsert = packageRepository.Find(package.PackageCode) assert packageAfterInsert.PackageCode == package.PackageCode assert packageAfterInsert.DeliveryDate == datetime(2018, 12, 30).date() assert packageAfterInsert.GetReturn().Description == "Sample text"
def test_ChangePackageStatusProperlyChangeStatus(self): adminService = AdminService() package = PackageObjectMother.CreatePackageManyPickupNoReturn() statuses = adminService.GetAllPackageStatuses() adminService.ChangePackageStatus(package, statuses[-1].Name) assert package.GetStatus().Name == statuses[-1].Name
def test_GetAllReturnsProperlyPullsOutAllReturns(self): adminService = AdminService() packages = \ [PackageObjectMother.CreatePackageManyPickupNoReturn(), PackageObjectMother.CreatePackageManyPickupNoReturn(), PackageObjectMother.CreatePackageManyPickupPackedNoReturn(), PackageObjectMother.CreatePackageManyPickupPackedNoReturn(), PackageObjectMother.CreatePackageManyPickupPackedUnconfirmedReturn(), PackageObjectMother.CreatePackageManyPickupPackedUnconfirmedReturn(), PackageObjectMother.CreateDeliveredPackageManyPickupPackedNoReturn(), PackageObjectMother.CreateDeliveredPackageManyPickupPackedNoReturn() ] packageReturns = [package.GetReturn() for package in packages] with patch.object(PackageRepository, 'FindAll', return_value=packages): servicePackageReturns = adminService.GetAllReturns() for return_ in servicePackageReturns: assert return_ in packageReturns
def test_ChangePackageStatusUseProperRepositoryMethod(self): adminService = AdminService() package = PackageObjectMother.CreatePackageManyPickupNoReturn() statuses = adminService.GetAllPackageStatuses() with patch.object(Package, 'GetStatus'): adminService.ChangePackageStatus(package, statuses[-1].Name) Package.GetStatus.assert_called_once()
def test_UpdateReturnRaiseExceptionWhenPackageDoesntHaveReturn(self): adminService = AdminService() package = PackageObjectMother.CreatePackageManyPickupNoReturn() with patch.object(PackageRepository, 'Update'): return_ = package.GetReturn() with self.assertRaises(ValueError): adminService.UpdateReturn(package, return_)
def test_PackPickups(self): package = PackageObjectMother.CreatePackageManyPickupNoReturn() pickups = package.GetPackageProducts() for pickup in pickups: package.MarkPackedProduct(pickup.Name) pickups = package.GetPackageProducts() for pickup in pickups: self.assertEqual(pickup.IsPacked, True)
def test_CreateAllObjectsFromObjectMother(self): p = PackageObjectMother.CreatePackageNoPickupsNoReturn() p = PackageObjectMother.CreatePackageManyPickupNoReturn() p = PackageObjectMother.CreatePackageManyPickupPackedNoReturn() p = PackageObjectMother.CreateDeliveredPackageManyPickupPackedNoReturn( ) p = PackageObjectMother.CreatePackageManyPickupPackedUnconfirmedReturn( ) p = PackageObjectMother.CreatePackageManyPickupPackedConfirmedReturn() p = PackageObjectMother.CreateUnpackedPickups() p = PackageObjectMother.CreatePackedPickups() p = PackageObjectMother.CreateUnconfirmedReturn() p = PackageObjectMother.CreateConfirmedReturn()
def test_FindInsertedPackageInFindAll(self): packageRepository = PackageRepository() insertedPackage = PackageObjectMother.CreatePackageManyPickupNoReturn() packageRepository.Insert(insertedPackage) packages = packageRepository.FindAll() foundInsertedPackage = False for package in packages: if insertedPackage.PackageCode == package.PackageCode: foundInsertedPackage = True break assert foundInsertedPackage == True
def test_UndoPackingProductChangeStatusProperly(self): transportService = TransportService() package = PackageObjectMother.CreatePackageManyPickupPackedNoReturn() products = package.GetPackageProducts() for product in products: transportService.UndoPackingProduct(package, product.Name) unpackedPackage = PackageObjectMother.CreatePackageManyPickupNoReturn() unpackedStatus = unpackedPackage.GetStatus() products = package.GetPackageProducts() for product in products: self.assertEqual(product.IsPacked, False) self.assertEqual(package.GetStatus().Name, unpackedStatus.Name)
def test_PackProductPackAllProducts(self): transportService = TransportService() package = PackageObjectMother.CreatePackageManyPickupNoReturn() products = package.GetPackageProducts() for product in products: transportService.PackProduct(package, product.Name) packedPackage = PackageObjectMother.CreatePackageManyPickupPackedNoReturn( ) packedStatus = packedPackage.GetStatus() products = package.GetPackageProducts() for product in products: self.assertEqual(product.IsPacked, True) self.assertEqual(package.GetStatus().Name, packedStatus.Name)
def test_PackProductInvalidProductName(self): transportService = TransportService() package = PackageObjectMother.CreatePackageManyPickupNoReturn() with self.assertRaises(ValueError): transportService.PackProduct(package, "invalid product name")
def test_ChangePackageStatusRaiseProperException(self): adminService = AdminService() package = PackageObjectMother.CreatePackageManyPickupNoReturn() with self.assertRaises(ValueError): adminService.ChangePackageStatus(package, "valid status name")