Esempio n. 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)
Esempio n. 2
0
    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
Esempio n. 3
0
    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()
Esempio n. 4
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()
Esempio n. 5
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)
Esempio n. 6
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)
Esempio n. 7
0
    def test_AccomplishDeliveryProperChangePackageStatus(self):
        transportService = TransportService()
        package = PackageObjectMother.CreatePackageManyPickupPackedNoReturn()

        transportService.AccomplishDelivery(package)

        self.assertEqual(package.GetStatus().Name, DELIVERY_SUCCESS_STATUS)
Esempio n. 8
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
Esempio n. 9
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
Esempio n. 10
0
    def test_UniquePackageCodes(self):
        packages = []
        for i in range(1000):
            packages.append(
                PackageObjectMother.CreatePackageNoPickupsNoReturn())

        self.assertEqual(len(packages), len(set(packages)))
Esempio n. 11
0
    def test_AllReturnStatuses(self):
        return_ = PackageObjectMother.CreateConfirmedReturn()

        statuses = Package.FindAllReturnStatuses()

        for status in statuses:
            return_.Status = status
            self.assertEqual(return_.Status, status)
Esempio n. 12
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
Esempio n. 13
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_)
Esempio n. 14
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)
Esempio n. 15
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()
Esempio n. 16
0
    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))
Esempio n. 17
0
    def test_UpdateReturnUseProperRepositoryMethod(self):
        adminService = AdminService()
        package = PackageObjectMother.CreatePackageManyPickupPackedUnconfirmedReturn(
        )
        return_ = package.GetReturn()

        with patch.object(PackageRepository, 'Update'):
            adminService.UpdateReturn(package, return_)

            PackageRepository.Update.assert_called_with(package)
Esempio n. 18
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)
Esempio n. 19
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)
Esempio n. 20
0
    def test_AddPickupsCheckNotPacked(self):
        package = PackageObjectMother.CreatePackageNoPickupsNoReturn()

        package.AddDeliveryProduct("Pan Tadeusz", 1)
        package.AddDeliveryProduct("Biblia", 3)
        package.AddDeliveryProduct(".net oczami developera", 1)

        pickups = package.GetPackageProducts()
        for pickup in pickups:
            self.assertEqual(pickup.IsPacked, False)
Esempio n. 21
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)
Esempio n. 22
0
    def test_BadReturnStateChangeRaisesException(self):
        return_ = PackageObjectMother.CreateConfirmedReturn()

        with self.assertRaises(ValueError):
            return_.Status = ""

        with self.assertRaises(ValueError):
            return_.Status = 13

        with self.assertRaises(ValueError):
            return_.Status = "zły stan, nie ma go"
Esempio n. 23
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"
Esempio n. 24
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)
Esempio n. 25
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"
Esempio n. 26
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
Esempio n. 27
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
Esempio n. 28
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."
        )
Esempio n. 29
0
    def test_AllDeliveryStepsDuringSuccessfulDelivery(self):
        package = PackageObjectMother.CreatePackageNoPickupsNoReturn()

        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")
        package.GetStatus().NextDeliveryStep()
        # Status == Dostarczone
        package.GetStatus().NextDeliveryStep()
        package.DeliveryDate = datetime.now()

        self.assertEqual(package.GetReturn(), None)
        self.assertEqual(package.GetStatus().Name, DELIVERY_SUCCESS_STATUS)
        self.assertEqual(package.DeliveryDate.date(), datetime.now().date())
Esempio n. 30
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)