Ejemplo n.º 1
0
    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
Ejemplo n.º 2
0
    def test_expired_token(self):
        """
        If our token expires after some call, make sure to get it again.

        Make a call, have the token expire after waiting some time (technically no time since time is frozen),
        and make a call again and notice 2 OAuth calls in total are required.
        """
        responses.add(responses.POST,
                      self.oauth_url,
                      json={
                          "expires_in": 0,
                          "access_token": self.access_token
                      },
                      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) == 4
        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.oauth_url
        assert responses.calls[3].request.url == self.course_url
Ejemplo n.º 3
0
    def test_delete_content_metadata(self):
        """
        ``delete_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.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)
        assert len(responses.calls) == 2
        assert responses.calls[0].request.url == self.oauth_url
        assert responses.calls[1].request.url == self.course_url
Ejemplo n.º 4
0
    def test_oauth_response_missing_keys(self):
        """
        A ``requests.RequestException`` is raised when the call for an OAuth2 access token returns no data.
        """
        responses.add(responses.POST, self.oauth_url, json={}, status=200)
        responses.add(responses.DELETE, self.course_url, json={}, status=200)

        degreed_api_client = DegreedAPIClient(self.enterprise_config)
        with pytest.raises(ClientError):
            degreed_api_client.delete_content_metadata({})