def __init__(self): self._packages = [] self._packages.append( Package(City="Wrocław", PostalCode="50-043", StreetAddress="Ruska 38", ClientId=1, DeliveryType="Ekonomiczny", DeclaredValue=100)) self._packages.append( Package(City="Wrocław", PostalCode="51-152", StreetAddress="Piłsudskiego 7", ClientId=2, DeliveryType="Standard")) self._packages.append( Package(City="Wrocław", PostalCode="53-659", StreetAddress="Sikorskiego 10", ClientId=3, DeliveryType="Standard", DeclaredValue=50)) self._packages.append( Package(City="Wrocław", PostalCode="53-609", StreetAddress="Fabryczna 12", ClientId=4, DeliveryType="Ekonomiczny", DeclaredValue=200))
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 CreatePackageNoPickupsNoReturn(): return Package(City="Wrocław", PostalCode="51-152", StreetAddress="Piłsudskiego 7", ClientId=1, DeliveryType="Standard", DeclaredValue=100)
def test_AllReturnStatuses(self): return_ = PackageObjectMother.CreateConfirmedReturn() statuses = Package.FindAllReturnStatuses() for status in statuses: return_.Status = status self.assertEqual(return_.Status, status)
def CreatePackageManyPickupPackedNoReturn(): package = Package(City="Wrocław", PostalCode="51-152", StreetAddress="Piłsudskiego 7", ClientId=1, DeliveryType="Standard", DeclaredValue=100) package.AddDeliveryProduct("Pan Tadeusz", 1) package.AddDeliveryProduct("Biblia", 3) package.AddDeliveryProduct(".net oczami developera", 1) package.GetStatus().NextDeliveryStep() package.MarkPackedProduct("Pan Tadeusz") package.MarkPackedProduct("Biblia") package.MarkPackedProduct(".net oczami developera") # Status == Wysłane package.GetStatus().NextDeliveryStep() return package
def CreateUnconfirmedReturn(): package = Package(City="Wrocław", PostalCode="51-152", StreetAddress="Piłsudskiego 7", ClientId=1, DeliveryType="Standard", DeclaredValue=100) package.AddDeliveryProduct("Pan Tadeusz", 1) package.AddDeliveryProduct("Biblia", 3) package.AddDeliveryProduct(".net oczami developera", 1) package.MarkPackedProduct("Pan Tadeusz") package.MarkPackedProduct("Biblia") package.MarkPackedProduct(".net oczami developera") package.MakeReturn( "Odbiorca twierdzi, że niczego nie zamawiał. Nie przyjął przesyłki." ) return package.GetReturn()
def CreatePackedPickups(): package = Package(City="Wrocław", PostalCode="51-152", StreetAddress="Piłsudskiego 7", ClientId=1, DeliveryType="Standard", DeclaredValue=100) package.AddDeliveryProduct("Pan Tadeusz", 1) package.AddDeliveryProduct("Biblia", 3) package.AddDeliveryProduct(".net oczami developera", 1) package.MarkPackedProduct("Pan Tadeusz") package.MarkPackedProduct("Biblia") package.MarkPackedProduct(".net oczami developera") return package.GetPackageProducts()
def test_GettingLimitedPackagesRepoReturnsStatusValidPackages(self): transportService = TransportService() statuses = Package.FindAllLimitedPackageStatuses() package = PackageObjectMother.CreatePackageNoPickupsNoReturn() for status in statuses: package.GetStatus().Name = status.Name with patch.object(PackageRepository, 'Find', return_value=package): self.assertEqual(package, transportService.GetLimitedPackage(32423))
def NewDelivery(self, city: str, postalCode: str, streetAddress: str, client_id: int, delivery_method: str, value: int, items: {str: int}): if not city or not isinstance(city, str) \ or not postalCode or not isinstance(postalCode, str)\ or not streetAddress or not isinstance(streetAddress, str) \ or not isinstance(client_id, int) or client_id<0\ or not delivery_method or not isinstance(delivery_method, str) \ or not isinstance(value, int) or value<0\ or not items or not isinstance(items, dict): raise ValueError("Invalid parameters type") package = Package(City=city, PostalCode=postalCode, StreetAddress=streetAddress, ClientId=client_id, DeliveryType=delivery_method, DeclaredValue=value) for item, quantity in items.items(): package.AddDeliveryProduct(product_name=item, quantity=quantity) self.packageRepository.Insert(package)
def GetLimitedPackage(self, package_code): package = self.packageRepository.Find(package_code) if not package: return None valid_statuses_obj = Package.FindAllLimitedPackageStatuses() valid_statuses = [] for status_obj in valid_statuses_obj: valid_statuses.append(status_obj.Name) if package.GetStatus().Name in valid_statuses: return package return None
def GetAllLimitedPackages(self): packages = self.packageRepository.FindAll() valid_statuses_obj = Package.FindAllLimitedPackageStatuses() valid_statuses = [] for status_obj in valid_statuses_obj: valid_statuses.append(status_obj.Name) matched = [] for package in packages: if package.GetStatus().Name in valid_statuses: matched.append(package) return matched
def test_GetLimitedPackageStatusesReturnsValidSortedStatuses(self): transportService = TransportService() validStatuses = Package.FindAllLimitedPackageStatuses() validStatusNames = [status.Name for status in validStatuses] statuses = transportService.GetLimitedPackageSatuses() for status in statuses: self.assertIn(status.Name, validStatusNames) for i in range(len(statuses) - 1): self.assertLess(statuses[i].DeliveryStep, statuses[i + 1].DeliveryStep)
def test_ChangePackageStatusForwardAndBackward(self): package = PackageObjectMother.CreatePackageNoPickupsNoReturn() package2 = PackageObjectMother.CreatePackageNoPickupsNoReturn() statuses = Package.FindAllPackageStatuses() statusNames = [status.Name for status in statuses] for i in range(10): for j in range(i): package.GetStatus().NextDeliveryStep() assert package.GetStatus().Name in statusNames for j in range(i): package.GetStatus().PrevDeliveryStep() assert package.GetStatus().Name == package2.GetStatus().Name
def test_ChangingPackageStatuses(self): # DeliveryStep = 0, first status package = PackageObjectMother.CreatePackageNoPickupsNoReturn() package2 = PackageObjectMother.CreatePackageNoPickupsNoReturn() statuses = Package.FindAllPackageStatuses() for status in statuses: package.GetStatus().Name = status.Name self.assertEqual(package.GetStatus().Name, package2.GetStatus().Name) self.assertEqual(package.GetStatus().DeliveryStep, package2.GetStatus().DeliveryStep) package2.GetStatus().NextDeliveryStep()
def GetAllReturnStatuses(self): return Package.FindAllReturnStatuses()
def GetLimitedPackageSatuses(self): return Package.FindAllLimitedPackageStatuses()