Example #1
0
    def test_invalid_sku(self):
        fixup_payload = self.raw_payload.decode('utf-8').replace(
            "course-v1:org+course+run1",  # noqa: E501
            "course-v1:org+nosuchcourse+run1")  # noqa: E501
        fixup_json_payload = json.loads(fixup_payload)
        fixup_webhook_data = JSONWebhookData(headers={},
                                             body=b'',
                                             content=fixup_json_payload)
        fixup_webhook_data.save()
        order, created = record_order(fixup_webhook_data)

        result = None
        with requests_mock.Mocker() as m:
            m.register_uri('POST', self.token_uri, json=self.token_response)
            m.register_uri('POST', self.enroll_uri, status_code=400)
            with self.assertRaises(HTTPError):
                result = process.delay(fixup_json_payload)
                result.get(5)

        self.assertEqual(result.state, 'FAILURE')

        # Even with the exception raised, it's the task failure
        # handler's job to set the status to ERROR. Given the async
        # nature of the task, though, the object reference doesn't
        # learn of the update until we read back the order. This can't
        # just use refresh_from_db(), because of the FSM-protected
        # status field.
        order = Order.objects.get(pk=order.id)
        self.assertEqual(order.status, Order.ERROR)
Example #2
0
    def test_invalid_sku(self):
        fixup_payload = self.raw_payload.decode('utf-8').replace(
            "course-v1:org+course+run1",  # noqa: E501
            "course-v1:org+nosuchcourse+run1")  # noqa: E501
        fixup_json_payload = json.loads(fixup_payload)
        fixup_webhook_data = JSONWebhookData(headers={},
                                             body=b'',
                                             content=fixup_json_payload)
        fixup_webhook_data.save()

        order, created = record_order(fixup_webhook_data)

        with requests_mock.Mocker() as m:
            m.register_uri('POST', self.token_uri, json=self.token_response)
            m.register_uri('POST', self.enroll_uri, status_code=404)
            # Non-existent course should raise a 404
            with self.assertRaises(HTTPError):
                process_order(order, fixup_json_payload)

        # At this stage, the order is still PROCESSING -- it's the
        # task failure handler's job to set the status to ERROR
        self.assertEqual(order.status, Order.PROCESSING)
Example #3
0
 def setup_webhook_data(self):
     self.webhook_data = JSONWebhookData(headers={},
                                         body=b'',
                                         content=self.json_payload)
     self.webhook_data.save()