def test_update_content_metadata(self): """ ``update_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.update_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
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)
def test_existing_token_is_valid(self): """ On a second call in the same session, if the token isn't expired we shouldn't need to do another OAuth2 call. """ responses.add(responses.POST, self.oauth_url, json=self.expected_token_response_body, status=200) responses.add(responses.DELETE, self.course_url, json='{}', status=200) payload = { 'orgCode': 'org-code', 'providerCode': 'provider-code', 'courses': [{ 'contentId': 'content-id', }], } degreed_api_client = DegreedAPIClient(self.enterprise_config) degreed_api_client.delete_content_metadata(payload) degreed_api_client.delete_content_metadata(payload) assert len(responses.calls) == 3 assert responses.calls[0].request.url == self.oauth_url assert responses.calls[1].request.url == self.course_url assert responses.calls[2].request.url == self.course_url