예제 #1
0
    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
예제 #2
0
    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