def test_delete(self, mock_requests):

        mock_requests.register_uri(
            'DELETE', ("https://api.chartmogul.com/v1/invoices"
                       "/inv_f466e33d-ff2b-4a11-8f85-417eb02157a7"),
            request_headers={'Authorization': 'Basic dG9rZW46c2VjcmV0'},
            status_code=204)

        config = Config("token", "secret")  # is actually checked in mock
        result = Invoice.destroy(
            config, uuid='inv_f466e33d-ff2b-4a11-8f85-417eb02157a7').get()

        self.assertEqual(mock_requests.call_count, 1, "expected call")
        self.assertEqual(mock_requests.last_request.qs, {})
        self.assertTrue(result is None)
    def test_delete_not_found(self, mock_requests):

        mock_requests.register_uri(
            'DELETE', ("https://api.chartmogul.com/v1/invoices"
                       "/inv_f466e33d-ff2b-4a11-8f85-417eb02157a7"),
            request_headers={'Authorization': 'Basic dG9rZW46c2VjcmV0'},
            headers={'Content-Type': 'application/json'},
            status_code=404,
            json={'error': 'Invoice not found'})

        config = Config("token", "secret")  # is actually checked in mock
        with self.assertRaises(APIError) as context:
            result = Invoice.destroy(
                config, uuid='inv_f466e33d-ff2b-4a11-8f85-417eb02157a7').get()

        self.assertEqual(mock_requests.call_count, 1, "expected call")
Пример #3
0
def _delete_invoice(result):
    return Invoice.destroy(config, uuid=result.invoices[0].uuid)