def test_post_course_certificate(self): """ Ensure the correct API call gets made """ test_client = EdxRestApiClient('http://test-server', jwt='test-token') httpretty.register_uri( httpretty.POST, 'http://test-server/credentials/', ) visible_date = datetime.now() tasks.post_course_certificate(test_client, self.student.username, self.certificate, visible_date) expected_body = { 'username': self.student.username, 'status': 'awarded', 'credential': { 'course_run_key': str(self.certificate.course_id), 'mode': self.certificate.mode, 'type': tasks.COURSE_CERTIFICATE, }, 'attributes': [{ 'name': 'visible_date', 'value': visible_date.strftime( '%Y-%m-%dT%H:%M:%SZ') # text representation of date }] } last_request_body = httpretty.last_request().body.decode('utf-8') assert json.loads(last_request_body) == expected_body
def test_post_course_certificate(self, mock_get_api_base_url): """ Ensure the correct API call gets made """ mock_get_api_base_url.return_value = 'http://test-server/' test_client = requests.Session() test_client.auth = SuppliedJwtAuth('test-token') httpretty.register_uri( httpretty.POST, 'http://test-server/credentials/', ) visible_date = datetime.now() tasks.post_course_certificate(test_client, self.student.username, self.certificate, visible_date) expected_body = { 'username': self.student.username, 'status': 'awarded', 'credential': { 'course_run_key': str(self.certificate.course_id), 'mode': self.certificate.mode, 'type': tasks.COURSE_CERTIFICATE, }, 'date_override': None, 'attributes': [{ 'name': 'visible_date', 'value': visible_date.strftime( '%Y-%m-%dT%H:%M:%SZ') # text representation of date }] } last_request_body = httpretty.last_request().body.decode('utf-8') assert json.loads(last_request_body) == expected_body