Path: blob/master/src/python/cocalc-api/tests/test_org_basic.py
5608 views
"""1Basic Organization functionality tests.23This file contains tests that verify the organization API is properly exposed4and accessible, without necessarily requiring full admin privileges or server connectivity.5"""6import pytest789class TestOrganizationAPIExposure:10"""Test that organization API methods are properly exposed."""1112def test_org_module_available(self, hub):13"""Test that the org module is accessible from hub."""14assert hasattr(hub, 'org')15assert hub.org is not None1617def test_all_org_methods_available(self, hub):18"""Test that all expected organization methods are available and callable."""19org = hub.org2021expected_methods = [22'get_all', 'create', 'get', 'set', 'add_admin', 'add_user', 'create_user', 'create_token', 'expire_token', 'get_users', 'remove_user',23'remove_admin', 'message'24]2526for method_name in expected_methods:27assert hasattr(org, method_name), f"Method {method_name} not found"28method = getattr(org, method_name)29assert callable(method), f"Method {method_name} is not callable"3031print(f"✓ All {len(expected_methods)} organization methods are properly exposed")3233def test_org_methods_are_api_decorated(self, hub):34"""Test that org methods make actual API calls (not just stubs)."""35# We can verify this by attempting to call a method that should fail36# with authentication/permission errors rather than NotImplementedError3738with pytest.raises(Exception) as exc_info:39# This should make an actual API call and fail with auth or server error,40# not with NotImplementedError41hub.org.get("nonexistent-org-for-testing-12345")4243# Should NOT be NotImplementedError (which would indicate the method isn't implemented)44assert not isinstance(exc_info.value, NotImplementedError), \45"Organization methods should make actual API calls, not raise NotImplementedError"4647print(f"✓ Organization methods make actual API calls: {type(exc_info.value).__name__}")4849def test_message_method_signature(self, hub):50"""Test that the message method has the correct signature."""51import inspect5253sig = inspect.signature(hub.org.message)54params = list(sig.parameters.keys())5556# Should have name, subject, body parameters57required_params = ['name', 'subject', 'body']58for param in required_params:59assert param in params, f"Message method missing required parameter: {param}"6061print("✓ Message method has correct parameters:", params)6263def test_create_user_method_signature(self, hub):64"""Test that create_user method has the correct signature."""65import inspect6667sig = inspect.signature(hub.org.create_user)68params = sig.parameters6970# Check required parameters71assert 'name' in params, "create_user missing 'name' parameter"72assert 'email' in params, "create_user missing 'email' parameter"7374# Check optional parameters75optional_params = ['firstName', 'lastName', 'password']76for param in optional_params:77assert param in params, f"create_user missing optional parameter: {param}"78# Optional params should have default values79assert params[param].default is not inspect.Parameter.empty, \80f"Optional parameter {param} should have a default value"8182print("✓ create_user method has correct parameter signature")8384def test_create_token_return_annotation(self, hub):85"""Test that create_token has proper return type annotation."""86import inspect8788sig = inspect.signature(hub.org.create_token)89return_annotation = sig.return_annotation9091# Should be annotated to return TokenType92assert return_annotation.__name__ == 'TokenType', \93f"create_token should return TokenType, got {return_annotation}"9495print("✓ create_token method has correct return type annotation")969798class TestOrganizationImportIntegrity:99"""Test that the organization refactoring didn't break anything."""100101def test_organizations_class_imported_correctly(self, hub):102"""Test that Organizations class is properly imported in hub."""103# The hub.org should be an instance of the Organizations class104from cocalc_api.org import Organizations105106assert isinstance(hub.org, Organizations), \107"hub.org should be an instance of Organizations class"108109print("✓ Organizations class properly imported and instantiated")110111def test_original_hub_functionality_preserved(self, hub):112"""Test that refactoring didn't break other hub functionality."""113# Test that other hub properties still work114assert hasattr(hub, 'system'), "Hub should still have system property"115assert hasattr(hub, 'projects'), "Hub should still have projects property"116assert hasattr(hub, 'messages'), "Hub should still have messages property"117118# Test that projects.delete is still available (from main task)119assert hasattr(hub.projects, 'delete'), "Projects should still have delete method"120assert callable(hub.projects.delete), "Projects delete should be callable"121122print("✓ All original Hub functionality preserved after org refactoring")123124125def test_make_check_compatibility():126"""Test that the refactoring passes all static analysis checks."""127# This test exists to document that the refactored code should pass128# make check (ruff, mypy, pyright) - the actual checking is done by CI/make129print("✓ Organization refactoring should pass make check (ruff, mypy, pyright)")130assert True131132133