示例#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)
示例#2
0
    def test_AccomplishDeliveryProperChangePackageStatus(self):
        transportService = TransportService()
        package = PackageObjectMother.CreatePackageManyPickupPackedNoReturn()

        transportService.AccomplishDelivery(package)

        self.assertEqual(package.GetStatus().Name, DELIVERY_SUCCESS_STATUS)
示例#3
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"
示例#4
0
    def test_MakeReturnWithDifferentValueThanDeclared(self):
        package = PackageObjectMother.CreatePackageManyPickupPackedNoReturn()

        package.MakeReturn(
            "Odbiorca twierdzi, że niczego nie zamawiał. Nie przyjął przesyłki.",
            123)
        package.GetStatus().Name = DELIVERY_FAILURE_STATUS

        self.assertEqual(package.GetReturn().Sum, 123)
示例#5
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
示例#6
0
    def test_UnpackingPickups(self):
        package = PackageObjectMother.CreatePackageManyPickupPackedNoReturn()

        pickups = package.GetPackageProducts()
        for pickup in pickups:
            package.UndoMarkPackedProduct(pickup.Name)

        pickups = package.GetPackageProducts()
        for pickup in pickups:
            self.assertEqual(pickup.IsPacked, False)
示例#7
0
    def test_DeliveryFailureProperChangePackageStatus(self):
        transportService = TransportService()
        package = PackageObjectMother.CreatePackageManyPickupPackedNoReturn()

        transportService.DeliveryFailure(package,
                                         "Odmówienie odbioru przesyłki")
        return_ = package.GetReturn()

        self.assertEqual(package.GetStatus().Name, DELIVERY_FAILURE_STATUS)
        self.assertEqual(return_.Status, RETURN_STARTING_STATUS)
示例#8
0
    def test_BadPackageStateChangeRaisesException(self):
        package = PackageObjectMother.CreatePackageManyPickupPackedNoReturn()

        with self.assertRaises(ValueError):
            package.GetStatus().Name = 14

        with self.assertRaises(ValueError):
            package.GetStatus().Name = ""

        with self.assertRaises(ValueError):
            package.GetStatus().Name = "nieistniejący stan przesyłki"
示例#9
0
    def test_BadMakingReturnInputRaisesException(self):
        package = PackageObjectMother.CreatePackageManyPickupPackedNoReturn()

        with self.assertRaises(ValueError):
            package.MakeReturn("")

        with self.assertRaises(ValueError):
            package.MakeReturn(17)

        with self.assertRaises(ValueError):
            package.MakeReturn("opis szkody", -100)
示例#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()
示例#11
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)
示例#12
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)
示例#13
0
    def test_DeliveryFailureMakeReturn(self):
        package = PackageObjectMother.CreatePackageManyPickupPackedNoReturn()

        package.MakeReturn(
            "Odbiorca twierdzi, że niczego nie zamawiał. Nie przyjął przesyłki."
        )
        package.GetStatus().Name = DELIVERY_FAILURE_STATUS

        self.assertEqual(package.GetReturn().Sum, package.DeclaredValue)
        self.assertEqual(package.GetReturn().Status, RETURN_STARTING_STATUS)
        self.assertEqual(package.GetReturn().ReportDate.date(),
                         datetime.now().date())
        self.assertEqual(package.GetReturn().Accepted, False)
        self.assertEqual(
            package.GetReturn().Description,
            "Odbiorca twierdzi, że niczego nie zamawiał. Nie przyjął przesyłki."
        )
示例#14
0
    def test_BadPackingInputRaisesException(self):
        package = PackageObjectMother.CreatePackageManyPickupPackedNoReturn()
        pickup = package.GetPackageProducts()[0]

        with self.assertRaises(ValueError):
            package.MarkPackedProduct("")

        with self.assertRaises(ValueError):
            package.MarkPackedProduct("nieistniejacy produkt")

        with self.assertRaises(ValueError):
            package.AddDeliveryProduct(pickup.Name, 1)

        with self.assertRaises(ValueError):
            package.AddDeliveryProduct("", 1)

        with self.assertRaises(ValueError):
            package.AddDeliveryProduct("książka", 0)