Пример #1
0
    def test_degreed_api_application_error(self):
        """
        ``create_content_metadata`` should raise ClientError when API request fails with an application error.
        """
        responses.add(
            responses.POST,
            self.oauth_url,
            json=self.expected_token_response_body,
            status=200
        )
        responses.add(
            responses.POST,
            self.course_url,
            json={'message': 'error'},
            status=400
        )

        payload = {
            'orgCode': 'org-code',
            'providerCode': 'provider-code',
            'courses': [{
                'contentId': 'content-id',
            }],
        }
        with pytest.raises(ClientError):
            degreed_api_client = DegreedAPIClient(self.enterprise_config)
            degreed_api_client.create_content_metadata(payload)
Пример #2
0
    def test_create_content_metadata(self):
        """
        ``create_content_metadata`` should use the appropriate URLs for transmission.
        """
        responses.add(
            responses.POST,
            self.oauth_url,
            json=self.expected_token_response_body,
            status=200
        )
        responses.add(
            responses.POST,
            self.course_url,
            json='{}',
            status=200
        )

        payload = {
            'orgCode': 'org-code',
            'providerCode': 'provider-code',
            'courses': [{
                'contentId': 'content-id',
                'authors': [],
                'categoryTags': [],
                'url': 'url',
                'imageUrl': 'image-url',
                'videoUrl': 'video-url',
                'title': 'title',
                'description': 'description',
                'difficulty': 'difficulty',
                'duration': 20,
                'publishDate': '2017-01-01',
                'format': 'format',
                'institution': 'institution',
                'costType': 'paid',
                'language': 'en'
            }],
        }
        degreed_api_client = DegreedAPIClient(self.enterprise_config)
        degreed_api_client.create_content_metadata(payload)
        assert len(responses.calls) == 2
        assert responses.calls[0].request.url == self.oauth_url
        assert responses.calls[1].request.url == self.course_url