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+ username = "test_user"
26+ 27+ expected_response = Mock ()
28+ self .requester .post .return_value = expected_response
29+
30+ result = self .client .fix_lti_user (username , email )
31+
32+ self .requester .post .assert_called_once_with (
33+ urljoin (self .base_url , '/api/lti-user-fix/' ),
34+ json = {'username' : username , 'email' : email }
35+ )
36+ assert result == expected_response
37+
38+ def test_fix_lti_user_with_different_credentials (self ):
39+ """Test fix_lti_user with different username and email"""
40+ username = "another_user"
41+ 42+ expected_response = Mock ()
43+ self .requester .post .return_value = expected_response
44+
45+ result = self .client .fix_lti_user (username , email )
46+
47+ self .requester .post .assert_called_once_with (
48+ urljoin (self .base_url , '/api/lti-user-fix/' ),
49+ json = {'username' : username , 'email' : email }
50+ )
51+ assert result == expected_response
52+
53+ def test_fix_lti_user_url_construction (self ):
54+ """Test that the correct URL is constructed"""
55+ username = "user"
56+ 57+
58+ self .client .fix_lti_user (username , email )
59+
60+ call_args = self .requester .post .call_args
61+ expected_url = urljoin (self .base_url , '/api/lti-user-fix/' )
62+ assert call_args [0 ][0 ] == expected_url
63+
64+ def test_fix_lti_user_request_data_format (self ):
65+ """Test that request data is formatted correctly"""
66+ username = "test_user"
67+ 68+
69+ self .client .fix_lti_user (username , email )
70+
71+ call_args = self .requester .post .call_args
72+ assert call_args [1 ]['json' ] == {'username' : username , 'email' : email }
0 commit comments