'Testing the sale invalidating scenario.'

def test_invalidate_sale_record(self):

    for i in range(2):
        course_registration_code = CourseRegistrationCode(code='sale_invoice{}'.format(i), course_id=self.course.id.to_deprecated_string(), created_by=self.instructor, invoice=self.sale_invoice_1, invoice_item=self.invoice_item, mode_slug='honor')
        course_registration_code.save()
    data = {'invoice_number': self.sale_invoice_1.id, 'event_type': 'invalidate'}
    url = reverse('sale_validation', kwargs={'course_id': self.course.id.to_deprecated_string()})
    self.assert_request_status_code(200, url, method='POST', data=data)
    test_data_1 = {'invoice_number': 100, 'event_type': 'invalidate'}
    self.assert_request_status_code(404, url, method='POST', data=test_data_1)
    response = self.assert_request_status_code(400, url, method='POST', data=data)
    self.assertIn('The    sale    associated    with    this    invoice    has    already    been    invalidated.', response.content)
    data['event_type'] = 're_validate'
    self.assert_request_status_code(200, url, method='POST', data=data)
    response = self.assert_request_status_code(400, url, method='POST', data=data)
    self.assertIn('This    invoice    is    already    active.', response.content)
    test_data_2 = {'invoice_number': self.sale_invoice_1.id}
    response = self.assert_request_status_code(400, url, method='POST', data=test_data_2)
    self.assertIn('Missing    required    event_type    parameter', response.content)
    test_data_3 = {'event_type': 're_validate'}
    response = self.assert_request_status_code(400, url, method='POST', data=test_data_3)
    self.assertIn('Missing    required    invoice_number    parameter', response.content)
    data['invoice_number'] = 'testing'
    response = self.assert_request_status_code(400, url, method='POST', data=data)
    self.assertIn('invoice_number    must    be    an    integer,    {value}    provided'.format(value=data['invoice_number']), response.content)
