Beispiel #1
0
    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)
Beispiel #2
0
 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
Beispiel #3
0
    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
Beispiel #4
0
    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"
Beispiel #5
0
    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
Beispiel #6
0
    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
Beispiel #7
0
    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()
Beispiel #8
0
    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_)
Beispiel #9
0
    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)
Beispiel #10
0
 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()
Beispiel #11
0
    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
Beispiel #12
0
    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)
Beispiel #13
0
    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)
Beispiel #14
0
    def test_PackProductInvalidProductName(self):
        transportService = TransportService()
        package = PackageObjectMother.CreatePackageManyPickupNoReturn()

        with self.assertRaises(ValueError):
            transportService.PackProduct(package, "invalid product name")
Beispiel #15
0
    def test_ChangePackageStatusRaiseProperException(self):
        adminService = AdminService()
        package = PackageObjectMother.CreatePackageManyPickupNoReturn()

        with self.assertRaises(ValueError):
            adminService.ChangePackageStatus(package, "valid status name")