Exemple #1
0
    def test_create_shipment_success(self):
        """With correct values, is a valid shipment created?"""

        # Get retailers and distribution centers
        retailers = retailer_service.get_retailers(self.loopback_token)
        distribution_centers = distribution_center_service.get_distribution_centers(
            self.loopback_token)

        # Create shipment
        shipment = dict()
        shipment['fromId'] = loads(distribution_centers)[0].get('id')
        shipment['toId'] = loads(retailers)[0].get('id')
        shipment['estimatedTimeOfArrival'] = "2016-07-14"
        created_shipment = shipment_service.create_shipment(
            self.loopback_token, shipment)

        # TODO: Update to use assertIsInstance(a,b)
        # Check all expected object values are present
        shipment_json = loads(created_shipment)
        # Check that the shipment is valid
        self.assertTrue(shipment_json.get('id'))
        self.assertTrue(shipment_json.get('status'))
        self.assertTrue(shipment_json.get('createdAt'))
        self.assertTrue(shipment_json.get('fromId'))
        self.assertTrue(shipment_json.get('toId'))
Exemple #2
0
    def test_get_retailer_inventory_invalid_token(self):
        """With an invalid token, are correct errors thrown?"""

        # Get retailers
        retailers = retailer_service.get_retailers(self.loopback_token)
        retailer_id = loads(retailers)[0].get('id')

        # Attempt to get retailer inventory with invalid token
        self.assertRaises(AuthenticationException,
                          retailer_service.get_retailer_inventory,
                          utils.get_bad_token(), retailer_id)
def get_retailers():
    """
    Get all retailer objects.

    :return: [{
        "id": "123",
        "address": {Address}
    }, {...}]

    """

    retailers = retailer_service.get_retailers(token=g.auth['loopback_token'])
    return Response(retailers, status=200, mimetype='application/json')
Exemple #4
0
    def test_get_shipments_retailer_id_filter_success(self):
        """Are correct retailers' shipments returned?"""

        # Get shipments intended for specific retailer
        retailers = retailer_service.get_retailers(self.loopback_token)
        retailer_id_filter = loads(retailers)[0].get('id')
        shipments = shipment_service.get_shipments(
            self.loopback_token, retailer_id=retailer_id_filter)

        # TODO: Update to use assertIsInstance(a,b)
        # Check all expected object values are present
        shipments_json = loads(shipments)
        # Check that the shipments have correct retailer ID (toId)
        for shipment_json in shipments_json:
            self.assertTrue(shipment_json.get('toId') == retailer_id_filter)
Exemple #5
0
    def test_get_retailer_inventory_success(self):
        """With correct values, is valid inventory returned?"""

        # Get retailer
        retailers = retailer_service.get_retailers(self.loopback_token)
        retailer_id = loads(retailers)[0].get('id')
        inventory = retailer_service.get_retailer_inventory(
            self.loopback_token, retailer_id)

        # TODO: Update to use assertIsInstance(a,b)
        # Check all expected object values are present
        inventories_json = loads(inventory)
        for inventory_json in inventories_json:
            self.assertTrue(inventory_json.get('id'))
            self.assertIsInstance(inventory_json.get('quantity'), IntType)
            self.assertTrue(inventory_json.get('productId'))
            self.assertTrue(inventory_json.get('locationId'))
            self.assertTrue(inventory_json.get('locationType'))
Exemple #6
0
    def test_create_shipment_invalid_token(self):
        """With an invalid token, are correct errors thrown?"""

        # Get retailers and distribution centers
        retailers = retailer_service.get_retailers(self.loopback_token)
        distribution_centers = distribution_center_service.get_distribution_centers(
            self.loopback_token)

        # Create shipment
        shipment = dict()
        shipment['fromId'] = loads(distribution_centers)[0].get('id')
        shipment['toId'] = loads(retailers)[0].get('id')
        shipment['estimatedTimeOfArrival'] = "2016-07-14"
        created_shipment = shipment_service.create_shipment(
            self.loopback_token, shipment)

        # Attempt to create a shipment with invalid token
        self.assertRaises(AuthenticationException,
                          shipment_service.create_shipment,
                          utils.get_bad_token(), shipment)
Exemple #7
0
    def test_retailers_success(self):
        """With correct values, are valid retailers returned?"""

        # Get retailers
        retailers = retailer_service.get_retailers(self.loopback_token)

        # TODO: Update to use assertIsInstance(a,b)
        # Check all expected object values are present
        retailers_json = loads(retailers)
        # Check that the retailers are valid
        for retailer_json in retailers_json:
            self.assertTrue(retailer_json.get('id'))

            # Check that retailer address is valid, if present
            if retailer_json.get('address'):
                self.assertTrue(retailer_json.get('address').get('city'))
                self.assertTrue(retailer_json.get('address').get('state'))
                self.assertTrue(retailer_json.get('address').get('country'))
                self.assertTrue(retailer_json.get('address').get('latitude'))
                self.assertTrue(retailer_json.get('address').get('longitude'))
Exemple #8
0
    def test_get_retailer_success(self):
        """With correct values, is a valid distribution center returned?"""

        # Get retailer
        retailers = retailer_service.get_retailers(self.loopback_token)
        retailer_id = loads(retailers)[0].get('id')
        retailer = retailer_service.get_retailer(self.loopback_token,
                                                 retailer_id)

        # TODO: Update to use assertIsInstance(a,b)
        # Check all expected object values are present
        retailer_json = loads(retailer)
        # Check that the retailer is valid
        self.assertTrue(retailer_json.get('id'))

        # Check that retailer address is valid, if present
        if retailer_json.get('address'):
            self.assertTrue(retailer_json.get('address').get('city'))
            self.assertTrue(retailer_json.get('address').get('state'))
            self.assertTrue(retailer_json.get('address').get('country'))
            self.assertTrue(retailer_json.get('address').get('latitude'))
            self.assertTrue(retailer_json.get('address').get('longitude'))
Exemple #9
0
    def test_create_shipment_invalid_ids(self):
        """With an invalid retailer/distribution center IDs, are correct errors thrown?"""

        # Get retailers and distribution centers
        retailers = retailer_service.get_retailers(self.loopback_token)
        distribution_centers = distribution_center_service.get_distribution_centers(
            self.loopback_token)

        # Create invalid shipments
        shipment_invalid_retailer = dict()
        shipment_invalid_retailer['fromId'] = loads(
            distribution_centers)[0].get('id')
        shipment_invalid_retailer['toId'] = "123321"
        shipment_invalid_dist = dict()
        shipment_invalid_dist['fromId'] = "123321"
        shipment_invalid_dist['toId'] = loads(retailers)[0].get('id')

        # Attempt to create a shipment with invalid IDs
        self.assertRaises(UnprocessableEntityException,
                          shipment_service.create_shipment,
                          self.loopback_token, shipment_invalid_retailer)
        self.assertRaises(UnprocessableEntityException,
                          shipment_service.create_shipment,
                          self.loopback_token, shipment_invalid_dist)