def test_post_outcome_request(self): request_headers = {"User-Agent": "unit-test"} request = OutcomeRequest(headers=request_headers) self.assertRaises(InvalidLTIConfigError, request.post_outcome_request) request.consumer_key = 'consumer' request.consumer_secret = 'secret' request.lis_outcome_service_url = 'http://example.edu/' request.lis_result_sourcedid = 'foo' request.operation = REPLACE_REQUEST with HTTMock(response_content): resp = request.post_outcome_request(nonce='my_nonce', timestamp='1234567890') self.assertIsInstance(resp, OutcomeResponse) request = resp.post_response.request self.assertTrue('authorization' in request.headers) self.assertEqual(request.headers.get('user-agent'), b"unit-test") self.assertEqual(request.headers.get('content-type'), b"application/xml") auth_header = unquote(request.headers['authorization'].decode('utf-8')) correct = ('OAuth ' 'oauth_nonce="my_nonce", oauth_timestamp="1234567890", ' 'oauth_version="1.0", oauth_signature_method="HMAC-SHA1", ' 'oauth_consumer_key="consumer", ' 'oauth_body_hash="glWvnsZZ8lMif1ATz8Tx64CTTaY=", ' 'oauth_signature="XR6A1CmUauXZdJZXa1pJpTQi6OQ="') self.assertEqual(auth_header, correct)
def test_has_required_attributes(self): request = OutcomeRequest() self.assertFalse(request.has_required_attributes()) request.consumer_key = 'foo' request.consumer_secret = 'bar' self.assertFalse(request.has_required_attributes()) request.lis_outcome_service_url = 'http://example.edu/' request.lis_result_sourcedid = 1 request.operation = 'baz' self.assertTrue(request.has_required_attributes())
def test_post_outcome_request(self): request = OutcomeRequest() self.assertRaises(InvalidLTIConfigError, request.post_outcome_request) request.consumer_key = 'consumer' request.consumer_secret = 'secret' request.lis_outcome_service_url = 'http://example.edu/' request.lis_result_sourcedid = 'foo' request.operation = REPLACE_REQUEST with HTTMock(response_content): resp = request.post_outcome_request( nonce='my_nonce', timestamp='1234567890' ) self.assertIsInstance(resp, OutcomeResponse) request = resp.post_response.request self.assertTrue('authorization' in request.headers) auth_header = unquote(request.headers['authorization'].decode('utf-8')) correct = ('OAuth ' 'oauth_nonce="my_nonce", oauth_timestamp="1234567890", ' 'oauth_version="1.0", oauth_signature_method="HMAC-SHA1", ' 'oauth_consumer_key="consumer", ' 'oauth_body_hash="glWvnsZZ8lMif1ATz8Tx64CTTaY=", ' 'oauth_signature="XR6A1CmUauXZdJZXa1pJpTQi6OQ="') self.assertEqual(auth_header, correct)