-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtest_user_invite_approve_simple.py
More file actions
179 lines (149 loc) · 6.51 KB
/
test_user_invite_approve_simple.py
File metadata and controls
179 lines (149 loc) · 6.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
"""
Simple tests for user invite approve functionality.
These tests focus on the core implementation without complex API mocking.
"""
import uuid
import pytest
from unittest.mock import Mock, AsyncMock, patch
from permit.api.models import ElementsUserInviteApprove, ElementsUserInviteRead, UserInviteStatus
from permit.api.users import UsersApi
class TestUserInviteApproveSimple:
"""Simple test suite for user invite approve functionality."""
def test_approve_method_exists(self):
"""Test that the approve method exists in UsersApi."""
assert hasattr(UsersApi, 'approve')
assert callable(UsersApi.approve)
def test_approve_method_signature(self):
"""Test that the approve method has the correct signature."""
import inspect
method = getattr(UsersApi, 'approve')
signature = inspect.signature(method)
# Check parameter names
params = list(signature.parameters.keys())
assert 'self' in params
assert 'user_invite_id' in params
assert 'approve_data' in params
# Check return type annotation
assert signature.return_annotation.__name__ == 'ElementsUserInviteRead'
def test_approve_data_model_validation(self):
"""Test ElementsUserInviteApprove model validation."""
# Valid data
valid_data = ElementsUserInviteApprove(
email="test@example.com",
key="valid-key-123",
attributes={"role": "admin"}
)
assert valid_data.email == "test@example.com"
assert valid_data.key == "valid-key-123"
assert valid_data.attributes == {"role": "admin"}
def test_approve_data_model_email_validation(self):
"""Test ElementsUserInviteApprove email validation."""
# Test email validation
with pytest.raises(ValueError):
ElementsUserInviteApprove(
email="invalid-email",
key="valid-key-123",
attributes={}
)
def test_approve_data_model_key_validation(self):
"""Test ElementsUserInviteApprove key validation."""
# Test key validation (regex pattern)
with pytest.raises(ValueError):
ElementsUserInviteApprove(
email="test@example.com",
key="invalid key with spaces", # Should fail regex validation
attributes={}
)
def test_approve_data_model_with_complex_attributes(self):
"""Test ElementsUserInviteApprove with complex attributes."""
complex_attributes = {
"department": "Engineering",
"location": "San Francisco",
"role": "Developer",
"level": "Senior",
"permissions": ["read", "write"],
"metadata": {
"hire_date": "2024-01-01",
"manager": "john@example.com"
}
}
approve_data = ElementsUserInviteApprove(
email="test@example.com",
key="test-key-123",
attributes=complex_attributes
)
assert approve_data.attributes == complex_attributes
assert approve_data.attributes["permissions"] == ["read", "write"]
assert approve_data.attributes["metadata"]["hire_date"] == "2024-01-01"
def test_approve_data_model_with_empty_attributes(self):
"""Test ElementsUserInviteApprove with empty attributes."""
approve_data = ElementsUserInviteApprove(
email="test@example.com",
key="test-key-123",
attributes={} # Empty attributes should be allowed
)
assert approve_data.attributes == {}
def test_user_invite_status_enum(self):
"""Test UserInviteStatus enum values."""
assert UserInviteStatus.pending == 'pending'
assert UserInviteStatus.approved == 'approved'
def test_elements_user_invite_read_model(self):
"""Test ElementsUserInviteRead model creation."""
invite_data = ElementsUserInviteRead(
id=uuid.uuid4(),
organization_id=uuid.uuid4(),
project_id=uuid.uuid4(),
environment_id=uuid.uuid4(),
key="test-invite-key-123",
status=UserInviteStatus.approved,
email="test@example.com",
first_name="John",
last_name="Doe",
role_id=uuid.uuid4(),
tenant_id=uuid.uuid4(),
created_at="2024-01-01T00:00:00Z",
updated_at="2024-01-01T01:00:00Z"
)
assert invite_data.status == UserInviteStatus.approved
assert invite_data.email == "test@example.com"
assert invite_data.key == "test-invite-key-123"
def test_approve_parameter_types(self):
"""Test that the approve method parameters have correct types."""
import inspect
from typing import get_type_hints
method = getattr(UsersApi, 'approve')
type_hints = get_type_hints(method)
# Check parameter types
assert type_hints.get('user_invite_id') == str
assert type_hints.get('approve_data').__name__ == 'ElementsUserInviteApprove'
assert type_hints.get('return').__name__ == 'ElementsUserInviteRead'
def test_user_invite_models_exist(self):
"""Test that all required models are available."""
# Test that we can import all necessary models
from permit.api.models import (
ElementsUserInviteApprove,
ElementsUserInviteRead,
UserInviteStatus
)
assert ElementsUserInviteApprove is not None
assert ElementsUserInviteRead is not None
assert UserInviteStatus is not None
def test_approve_data_serialization(self):
"""Test that ElementsUserInviteApprove data can be serialized."""
approve_data = ElementsUserInviteApprove(
email="test@example.com",
key="test-key-123",
attributes={"role": "admin", "department": "Engineering"}
)
# Test dict() method
data_dict = approve_data.dict()
assert data_dict['email'] == "test@example.com"
assert data_dict['key'] == "test-key-123"
assert data_dict['attributes']['role'] == "admin"
assert data_dict['attributes']['department'] == "Engineering"
# Test JSON serialization
import json
json_str = approve_data.json()
parsed_data = json.loads(json_str)
assert parsed_data['email'] == "test@example.com"
assert parsed_data['key'] == "test-key-123"