|
9 | 9 |
|
10 | 10 |
|
11 | 11 | class TestUsers: |
12 | | - """Test suite for user resource operations.""" |
| 12 | + """Test suite for user resource operations.""" |
13 | 13 |
|
14 | | - @pytest.fixture |
15 | | - def mock_transport(self): |
16 | | - """Mock HTTP transport.""" |
17 | | - return Mock() |
| 14 | + @pytest.fixture |
| 15 | + def mock_transport(self): |
| 16 | + """Mock HTTP transport.""" |
| 17 | + return Mock() |
18 | 18 |
|
19 | | - @pytest.fixture |
20 | | - def users_service(self, mock_transport): |
21 | | - """Create users service with mocked transport.""" |
22 | | - return Users(mock_transport) |
| 19 | + @pytest.fixture |
| 20 | + def users_service(self, mock_transport): |
| 21 | + """Create users service with mocked transport.""" |
| 22 | + return Users(mock_transport) |
23 | 23 |
|
24 | | - @pytest.fixture |
25 | | - def sample_user_response(self): |
26 | | - """Sample JSON:API response for a user.""" |
27 | | - return { |
28 | | - "data": { |
29 | | - "id": "user-MA4GL63FmYRpSFxa", |
30 | | - "type": "users", |
31 | | - "attributes": { |
32 | | - "username": "admin", |
33 | | - "email": "admin@example.com", |
34 | | - "is-service-account": False, |
35 | | - "auth-method": "hcp_sso", |
36 | | - "avatar-url": "https://example.com/avatar.png", |
37 | | - "v2-only": True, |
38 | | - "permissions": { |
39 | | - "can-create-organizations": False, |
40 | | - "can-change-email": True, |
41 | | - "can-change-username": True, |
42 | | - }, |
43 | | - }, |
44 | | - } |
45 | | - } |
| 24 | + @pytest.fixture |
| 25 | + def sample_user_response(self): |
| 26 | + """Sample JSON:API response for a user.""" |
| 27 | + return { |
| 28 | + "data": { |
| 29 | + "id": "user-MA4GL63FmYRpSFxa", |
| 30 | + "type": "users", |
| 31 | + "attributes": { |
| 32 | + "username": "admin", |
| 33 | + "email": "admin@example.com", |
| 34 | + "is-service-account": False, |
| 35 | + "auth-method": "hcp_sso", |
| 36 | + "avatar-url": "https://example.com/avatar.png", |
| 37 | + "v2-only": True, |
| 38 | + "permissions": { |
| 39 | + "can-create-organizations": False, |
| 40 | + "can-change-email": True, |
| 41 | + "can-change-username": True, |
| 42 | + }, |
| 43 | + }, |
| 44 | + } |
| 45 | + } |
46 | 46 |
|
47 | | - def test_read_user(self, users_service, mock_transport, sample_user_response): |
48 | | - """Test reading a specific user by ID.""" |
49 | | - mock_transport.request.return_value.json.return_value = sample_user_response |
| 47 | + def test_read_user(self, users_service, mock_transport, sample_user_response): |
| 48 | + """Test reading a specific user by ID.""" |
| 49 | + mock_transport.request.return_value.json.return_value = sample_user_response |
50 | 50 |
|
51 | | - user_id = "user-MA4GL63FmYRpSFxa" |
52 | | - user = users_service.read(user_id) |
| 51 | + user_id = "user-MA4GL63FmYRpSFxa" |
| 52 | + user = users_service.read(user_id) |
53 | 53 |
|
54 | | - mock_transport.request.assert_called_once_with( |
55 | | - "GET", f"/api/v2/users/{user_id}" |
56 | | - ) |
57 | | - assert isinstance(user, User) |
58 | | - assert user.id == user_id |
59 | | - assert user.username == "admin" |
60 | | - assert user.email == "admin@example.com" |
61 | | - assert user.is_service_account is False |
62 | | - assert user.auth_method == "hcp_sso" |
63 | | - assert user.avatar_url == "https://example.com/avatar.png" |
64 | | - assert user.v2_only is True |
65 | | - assert user.permissions == { |
66 | | - "can-create-organizations": False, |
67 | | - "can-change-email": True, |
68 | | - "can-change-username": True, |
69 | | - } |
| 54 | + mock_transport.request.assert_called_once_with( |
| 55 | + "GET", f"/api/v2/users/{user_id}" |
| 56 | + ) |
| 57 | + assert isinstance(user, User) |
| 58 | + assert user.id == user_id |
| 59 | + assert user.username == "admin" |
| 60 | + assert user.email == "admin@example.com" |
| 61 | + assert user.is_service_account is False |
| 62 | + assert user.auth_method == "hcp_sso" |
| 63 | + assert user.avatar_url == "https://example.com/avatar.png" |
| 64 | + assert user.v2_only is True |
| 65 | + assert user.permissions == { |
| 66 | + "can-create-organizations": False, |
| 67 | + "can-change-email": True, |
| 68 | + "can-change-username": True, |
| 69 | + } |
70 | 70 |
|
71 | | - def test_read_user_invalid_id(self, users_service): |
72 | | - """Test reading a user with an invalid user ID.""" |
73 | | - with pytest.raises(ValueError, match="invalid user id"): |
74 | | - users_service.read("") |
| 71 | + def test_read_user_invalid_id(self, users_service): |
| 72 | + """Test reading a user with an invalid user ID.""" |
| 73 | + with pytest.raises(ValueError, match="invalid user id"): |
| 74 | + users_service.read("") |
0 commit comments