-
Notifications
You must be signed in to change notification settings - Fork 6
Add approve user invite. #117
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
shuvyA
merged 4 commits into
main
from
shuvy/per-12868-add-approves-a-user-invite-in-permit-python-sdk
Sep 11, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,179 @@ | ||
| """ | ||
| 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: | ||
|
shuvyA marked this conversation as resolved.
|
||
| """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" | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.