def get_shipments():
    """
    Get all shipment objects.

    :return: [{
        "id": "123",
        "status": "SHIPPED",
        "createdAt": "2015-11-05T22:00:51.692765",
        "updatedAt": "2015-11-08T22:00:51.692765",
        "deliveredAt": "2015-11-08T22:00:51.692765",
        "estimatedTimeOfArrival": "2015-11-07T22:00:51.692765",
        "currentLocation": {Address},
        "fromId": "D2",
        "toId:": "123"
    }, {...}]

    """

    status = request.args.get('status')
    retailer_id = request.args.get('rid')
    dc_id = request.args.get('did')
    shipments = shipment_service.get_shipments(token=g.auth['loopback_token'],
                                               status=status,
                                               retailer_id=retailer_id,
                                               dc_id=dc_id)
    return Response(shipments,
                    status=200,
                    mimetype='application/json')
示例#2
0
def get_shipments():
    """
    Get all shipment objects.

    :return: [{
        "id": "123",
        "status": "SHIPPED",
        "createdAt": "2015-11-05T22:00:51.692765",
        "updatedAt": "2015-11-08T22:00:51.692765",
        "deliveredAt": "2015-11-08T22:00:51.692765",
        "estimatedTimeOfArrival": "2015-11-07T22:00:51.692765",
        "currentLocation": {Address},
        "fromId": "D2",
        "toId:": "123"
    }, {...}]

    """

    status = request.args.get('status')
    retailer_id = request.args.get('rid')
    dc_id = request.args.get('did')
    shipments = shipment_service.get_shipments(token=g.auth['loopback_token'],
                                               status=status,
                                               retailer_id=retailer_id,
                                               dc_id=dc_id)
    return Response(shipments, status=200, mimetype='application/json')
示例#3
0
    def test_get_shipments_success(self):
        """With correct values, are valid shipments returned?"""

        # Get shipments
        shipments = shipment_service.get_shipments(self.loopback_token)

        # TODO: Update to use assertIsInstance(a,b)
        # Check all expected object values are present
        shipments_json = loads(shipments)
        # Check that the shipments are valid
        for shipment_json in shipments_json:
            self.assertTrue(shipment_json.get('id'))
            self.assertTrue(shipment_json.get('status'))
            self.assertTrue(shipment_json.get('createdAt'))
            self.assertTrue(shipment_json.get('estimatedTimeOfArrival'))
            self.assertTrue(shipment_json.get('fromId'))
            self.assertTrue(shipment_json.get('toId'))

            # Check that shipment address is valid, if present
            if shipment_json.get('currentLocation'):
                self.assertTrue(
                    shipment_json.get('currentLocation').get('city'))
                self.assertTrue(
                    shipment_json.get('currentLocation').get('state'))
                self.assertTrue(
                    shipment_json.get('currentLocation').get('country'))
                self.assertTrue(
                    shipment_json.get('currentLocation').get('latitude'))
                self.assertTrue(
                    shipment_json.get('currentLocation').get('longitude'))
def get_distribution_centers_shipments(dc_id):
    """
    Retrieve all shipments originating from the specified distribution center.

    :param dc_id:   The distribution center's id

    :return: [{
        "id": "123",
        "status": "SHIPPED",
        "createdAt": "2015-11-05T22:00:51.692765",
        "updatedAt": "2015-11-08T22:00:51.692765",
        "deliveredAt": "2015-11-08T22:00:51.692765",
        "estimatedTimeOfArrival": "2015-11-07T22:00:51.692765",
        "currentLocation": {Address},
        "fromId": "123",
        "toId:": "123"
    }, {...}]

    """
    check_null_input((dc_id, 'distribution center whose shipments you want to retrieve'))
    status = request.args.get('status')

    shipments = shipment_service.get_shipments(token=g.auth['loopback_token'],
                                               dc_id=dc_id,
                                               status=status)
    return Response(shipments,
                    status=200,
                    mimetype='application/json')
示例#5
0
    def test_delete_shipment_success(self):
        """With correct values, is the shipment deleted?"""

        # Get a specific shipment
        shipments = shipment_service.get_shipments(self.loopback_token)
        shipment_id = loads(shipments)[0].get('id')

        # Delete shipment and check for successful return
        self.assertTrue(
            shipment_service.delete_shipment(self.loopback_token, shipment_id)
            is None)
示例#6
0
    def test_delete_shipment_invalid_token(self):
        """With an invalid token, are correct errors thrown?"""

        # Get a specific shipment ID
        shipments = shipment_service.get_shipments(self.loopback_token)
        shipment_id = loads(shipments)[0].get('id')

        # Attempt to delete a shipment with invalid token
        self.assertRaises(AuthenticationException,
                          shipment_service.delete_shipment,
                          utils.get_bad_token(), shipment_id)
示例#7
0
    def test_get_shipment_no_items_filter_success(self):
        """With filter set to not include items, are they not returned?"""

        # Get a shipment
        shipments = shipment_service.get_shipments(self.loopback_token)
        shipment_id = loads(shipments)[0].get('id')
        shipment = shipment_service.get_shipment(self.loopback_token,
                                                 shipment_id,
                                                 include_items="0")

        # Make sure items are not returned
        self.assertFalse(loads(shipment).get('items'))
示例#8
0
    def test_get_shipments_multiple_filters_success(self):
        """Are correct shipments returned when using multiple filters?"""

        # Get filter values applicable to at least one shipment
        shipments = shipment_service.get_shipments(self.loopback_token)
        shipment = loads(shipments)[0]
        status_filter = shipment.get('status')
        retailer_id_filter = shipment.get('toId')
        dc_id_filter = shipment.get('fromId')
        shipments = shipment_service.get_shipments(
            self.loopback_token,
            status=status_filter,
            retailer_id=retailer_id_filter,
            dc_id=dc_id_filter)

        # Check that the shipments have correct values
        shipments_json = loads(shipments)
        for shipment_json in shipments_json:
            self.assertTrue(shipment_json.get('status') == status_filter)
            self.assertTrue(shipment_json.get('toId') == retailer_id_filter)
            self.assertTrue(shipment_json.get('fromId') == dc_id_filter)
示例#9
0
    def test_get_shipments_status_filter_success(self):
        """Are correct status shipments returned?"""

        # Get shipments with specific status
        query_status = 'DELIVERED'
        shipments = shipment_service.get_shipments(self.loopback_token,
                                                   status=query_status)

        # TODO: Update to use assertIsInstance(a,b)
        # Check all expected object values are present
        shipments_json = loads(shipments)
        # Check that the shipments have correct status
        for shipment_json in shipments_json:
            self.assertTrue(shipment_json.get('status') == query_status)
示例#10
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)
示例#11
0
    def test_update_invalid_status(self):
        """With incorrect status updates, is the correct exception sent?"""

        # List of statuses progression
        prev_status = statuses[-1]
        for status in statuses:
            # Get an existing shipment with the current status
            shipments = shipment_service.get_shipments(self.loopback_token,
                                                       status=status)
            shipment = loads(shipments)[0]
            shipment['status'] = prev_status

            # Attempt to update the status to an invalid value
            self.assertRaises(ValidationException,
                              shipment_service.update_shipment,
                              self.loopback_token, shipment.get('id'),
                              shipment)
            prev_status = status
示例#12
0
    def test_update_shipment_success(self):
        """With correct values, is the shipment updated?"""

        # Get a specific shipment
        shipments = shipment_service.get_shipments(self.loopback_token,
                                                   status=statuses.pop(0))
        shipment_id = loads(shipments)[0].get('id')

        # Iterate through shipment statuses and update shipment accordingly
        shipment = dict()
        for status in statuses:
            if isinstance(shipment, unicode):
                shipment = loads(shipment)
            shipment['status'] = status
            shipment = shipment_service.update_shipment(
                self.loopback_token, shipment_id, shipment)

            # TODO: Update to use assertIsInstance(a,b)
            # Check all expected object values are present
            shipment_json = loads(shipment)
            # Check that the shipments are valid
            self.assertTrue(shipment_json.get('id'))
            self.assertTrue(shipment_json.get('status') == status)
            self.assertTrue(shipment_json.get('createdAt'))
            self.assertTrue(shipment_json.get('estimatedTimeOfArrival'))
            self.assertTrue(shipment_json.get('fromId'))
            self.assertTrue(shipment_json.get('toId'))

            # Check that shipment address is valid, if present
            if shipment_json.get('currentLocation'):
                self.assertTrue(
                    shipment_json.get('currentLocation').get('city'))
                self.assertTrue(
                    shipment_json.get('currentLocation').get('state'))
                self.assertTrue(
                    shipment_json.get('currentLocation').get('country'))
                self.assertTrue(
                    shipment_json.get('currentLocation').get('latitude'))
                self.assertTrue(
                    shipment_json.get('currentLocation').get('longitude'))
示例#13
0
    def test_get_shipment_success(self):
        """With correct values, is a valid shipment returned?"""

        # Get a shipment
        shipments = shipment_service.get_shipments(self.loopback_token)
        shipment_id = loads(shipments)[0].get('id')
        shipment = shipment_service.get_shipment(self.loopback_token,
                                                 shipment_id)

        # TODO: Update to use assertIsInstance(a,b)
        # Check all expected object values are present
        shipment_json = loads(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('estimatedTimeOfArrival'))
        self.assertTrue(shipment_json.get('fromId'))
        self.assertTrue(shipment_json.get('toId'))

        # Check that shipment address is valid, if present
        if shipment_json.get('currentLocation'):
            self.assertTrue(shipment_json.get('currentLocation').get('city'))
            self.assertTrue(shipment_json.get('currentLocation').get('state'))
            self.assertTrue(
                shipment_json.get('currentLocation').get('country'))
            self.assertTrue(
                shipment_json.get('currentLocation').get('latitude'))
            self.assertTrue(
                shipment_json.get('currentLocation').get('longitude'))

        # Check that the shipment's items are valid
        for item_json in shipment_json.get('items'):
            # Check that the item is valid
            self.assertTrue(item_json.get('id'))
            self.assertTrue(item_json.get('shipmentId'))
            self.assertTrue(item_json.get('productId'))
            self.assertTrue(item_json.get('quantity'))