Beispiel #1
0
    def clean_tracking_code(self):
        tracking_code = self.cleaned_data.get('tracking_code')

        self.instance.markers.marker('valid_usps_tracking_marker').issue_signals(request=self,
                                                                                 instance=self.instance,
                                                                                 actor=self.instance.user,
                                                                                 tracking_code=tracking_code)

        service = USPSTrackingService()

        try:
            usps_response = service.track(tracking_code=tracking_code)
            service.record(instance=self.instance, usps_response=usps_response)
        except Exception as e:
            logger.error('Invalid Tracking Code %s' % (tracking_code,))
            #raise forms.ValidationError('The Tracking code is not valid: %s' % e)

        return tracking_code
Beispiel #2
0
class USPSUndeliveredTrackingCodeResponseTest(BaseUSPSTrackingCode):
    """
    Test the expected USPS XML response, which is undelivered
    """
    @httpretty.activate
    def setUp(self):
        httpretty.register_uri(httpretty.POST, "http://production.shippingapis.com/ShippingAPI.dll",
                               body=TRACK_UNDELIVERED_RESPONSE_XML_BODY,
                               status=200)

        super(USPSUndeliveredTrackingCodeResponseTest, self).setUp()
        self.subject = USPSTrackingService()
        self.response = self.subject.track(tracking_code=TRACKING_CODE)

    def test_usps_response_identity(self):
        self.assertEqual(self.response.identity, '9:24 pm-March 28, 2001-50395')

    def test_usps_response_status(self):
        self.assertEqual(self.response.status, 'ENROUTE')

    def test_usps_response_is_delivered(self):
        self.assertEqual(self.response.is_delivered, False)
Beispiel #3
0
class USPSTrackingCodeResponseTest(BaseUSPSTrackingCode):
    """
    Test the expected USPS XML response
    """
    def setUp(self):
        super(USPSTrackingCodeResponseTest, self).setUp()

        self.subject = USPSTrackingService()
        self.response = self.subject.track(tracking_code=TRACKING_CODE)

    def test_we_have_correct_service_as_subject(self):
        self.assertEqual(type(self.subject), USPSTrackingService)

    def test_service_properties(self):
        """
        Ensure properties are set
        """
        self.assertTrue(hasattr(self.subject, 'USERID'))
        self.assertTrue(hasattr(self.subject, 'PASSWORD'))
        self.assertTrue(self.subject.USERID not in [None, ''])
        self.assertTrue(self.subject.PASSWORD not in [None, ''])

        self.assertTrue(hasattr(self.subject, 'USPS_CONNECTION'))
        self.assertEqual(self.subject.USPS_CONNECTION, USPS_CONNECTION)  # is a live connection

    def test_service_uses_correct_usps_xml_class(self):
        """
        Ensure were using the USPS TrackFields service
        """
        self.assertEqual(type(self.subject.service), TrackConfirmWithFields)

    def test_track_usps_response(self):
        self.assertEqual(type(self.response), USPSResponse)

    def test_usps_response_properties(self):
        self.assertEqual(type(self.response.as_json), str)
        self.assertEqual(type(self.response.summary), dict)
        self.assertEqual(type(self.response.status), str)
        self.assertEqual(type(self.response.is_delivered), bool)
        self.assertEqual(type(self.response.description()), str)
        self.assertEqual(type(self.response.waypoints), list)

    def test_usps_response_summary(self):
        self.assertEqual(self.response.summary, {'EventTime': '12:12 pm', 'AuthorizedAgent': None, 'FirmName': None, 'EventCountry': None, 'EventZIPCode': '50208', 'Event': 'DELIVERED', 'EventCity': 'NEWTON', 'EventState': 'IA', 'EventDate': 'May 21, 2001', 'Name': None})

    def test_usps_response_identity(self):
        self.assertEqual(self.response.identity, '12:12 pm-May 21, 2001-50208')

    def test_usps_response_status(self):
        self.assertEqual(self.response.status, 'DELIVERED')

    def test_usps_response_is_delivered(self):
        self.assertEqual(self.response.is_delivered, True)

    def test_usps_response_description(self):
        self.assertEqual(self.response.description(), 'Current package status : DELIVERED in NEWTON IA 50208, USA. Last Updated :  May 21, 2001:12:12 pm')

    def test_usps_response_waypoints(self):
        self.assertEqual(self.response.waypoints, [{'EventTime': '12:12 pm',
                                                     'AuthorizedAgent': None,
                                                     'FirmName': None,
                                                     'EventCountry': None,
                                                     'EventZIPCode': '50208',
                                                     'Event': 'DELIVERED',
                                                     'EventCity': 'NEWTON',
                                                     'EventState': 'IA',
                                                     'EventDate': 'May 21, 2001',
                                                     'Name': None},
                                                    {'AuthorizedAgent': None,
                                                      'Event': 'ENROUTE',
                                                      'EventCity': 'DES MOINES',
                                                      'EventCountry': None,
                                                      'EventDate': 'March 28, 2001',
                                                      'EventState': 'IA',
                                                      'EventTime': '9:24 pm',
                                                      'EventZIPCode': '50395',
                                                      'FirmName': None,
                                                      'Name': None},
                                                    {'AuthorizedAgent': None,
                                                      'Event': 'ACCEPTANCE',
                                                      'EventCity': 'BLAINE',
                                                      'EventCountry': None,
                                                      'EventDate': 'March 27, 2001',
                                                      'EventState': 'WA',
                                                      'EventTime': '10:00 pm',
                                                      'EventZIPCode': '98231',
                                                      'FirmName': None,
                                                      'Name': None}])