1+ """Tests for LTI Tools API client"""
2+
3+ from unittest .mock import Mock
4+ from urllib .parse import urljoin
5+
6+ from edx_api .lti_tools import LTITools
7+
8+
9+ class TestLTITools :
10+ """Tests for LTITools class"""
11+
12+ def setup_method (self ):
13+ """Set up test fixtures"""
14+ self .requester = Mock ()
15+ self .base_url = "https://example.edx.org"
16+ self .client = LTITools (self .requester , self .base_url )
17+
18+ def test_init (self ):
19+ """Test LTITools initialization"""
20+ assert self .client .requester == self .requester
21+ assert self .client .base_url == self .base_url
22+
23+ def test_fix_lti_user_success (self ):
24+ """Test fix_lti_user with successful response"""
25+ 26+ expected_response = Mock ()
27+ self .requester .post .return_value = expected_response
28+
29+ result = self .client .fix_lti_user (email )
30+
31+ self .requester .post .assert_called_once_with (
32+ urljoin (self .base_url , '/api/lti-user-fix/' ),
33+ json = {"email" : email }
34+ )
35+ assert result == expected_response
36+
37+ def test_fix_lti_user_with_different_credentials (self ):
38+ """Test fix_lti_user with email"""
39+ 40+ expected_response = Mock ()
41+ self .requester .post .return_value = expected_response
42+
43+ result = self .client .fix_lti_user (email )
44+
45+ self .requester .post .assert_called_once_with (
46+ urljoin (self .base_url , '/api/lti-user-fix/' ),
47+ json = {"email" : email }
48+ )
49+ assert result == expected_response
50+
51+ def test_fix_lti_user_url_construction (self ):
52+ """Test that the correct URL is constructed"""
53+ 54+
55+ self .client .fix_lti_user (email )
56+
57+ call_args = self .requester .post .call_args
58+ expected_url = urljoin (self .base_url , '/api/lti-user-fix/' )
59+ assert call_args [0 ][0 ] == expected_url
60+
61+ def test_fix_lti_user_request_data_format (self ):
62+ """Test that request data is formatted correctly"""
63+ 64+
65+ self .client .fix_lti_user (email )
66+
67+ call_args = self .requester .post .call_args
68+ assert call_args [1 ]['json' ] == {"email" : email }
0 commit comments