mirror of
				https://github.com/zulip/zulip.git
				synced 2025-10-31 12:03:46 +00:00 
			
		
		
		
	openapi: Refactor hacky openAPI curl test.
Fixes #17795 In PR #17014, we added support for deactivate-own-user. And while doing so, we first deactivated the client and then reactivated it. But this implementation is a bit hacky. So, to fix this, we're now deactivating a test_user so that we don't have to reactivate it. We did so by changing the value of authentication_line. As we want to keep endpoint code out of the “test_curl_examples”, we changed the value of authentication_line in `curl_param_value_generators.py`. To work this out, we create a new global variable named AUTHENTICATION_LINE in “curl_param_value_generators.py” and change its value in function “deactivate_own_user” and to use this change in “test_curl_examples,” we import AUTHENTICATION_LINE. AUTHENTICATION_LINE is of list data type because we want a pointer to original mutable object so that changes made during run time show across the module. Another way to do this is to change the way we import variable, but that will be inconsistent to the way we had in all other files. To remove confusion between AUTHENTICATION_LINE and authentication_line we renamed authentication_line to default_authentication_line.
This commit is contained in:
		| @@ -20,11 +20,15 @@ from zerver.lib.actions import ( | ||||
| from zerver.lib.events import do_events_register | ||||
| from zerver.lib.initial_password import initial_password | ||||
| from zerver.lib.test_classes import ZulipTestCase | ||||
| from zerver.models import Client, Message, UserGroup, UserPresence, get_realm | ||||
| from zerver.lib.users import get_api_key | ||||
| from zerver.models import Client, Message, UserGroup, UserPresence, get_realm, get_user | ||||
|  | ||||
| GENERATOR_FUNCTIONS: Dict[str, Callable[[], Dict[str, object]]] = {} | ||||
| REGISTERED_GENERATOR_FUNCTIONS: Set[str] = set() | ||||
| CALLED_GENERATOR_FUNCTIONS: Set[str] = set() | ||||
| # This is a List rather than just a string in order to make it easier | ||||
| # to write to it from another module. | ||||
| AUTHENTICATION_LINE: List[str] = [""] | ||||
|  | ||||
| helpers = ZulipTestCase() | ||||
|  | ||||
| @@ -310,3 +314,22 @@ def deactivate_user() -> Dict[str, object]: | ||||
|         acting_user=None, | ||||
|     ) | ||||
|     return {"user_id": user_profile.id} | ||||
|  | ||||
|  | ||||
| @openapi_param_value_generator(["/users/me:delete"]) | ||||
| def deactivate_own_user() -> Dict[str, object]: | ||||
|     test_user_email = "delete-test@zulip.com" | ||||
|     deactivate_test_user = do_create_user( | ||||
|         test_user_email, | ||||
|         "secret", | ||||
|         get_realm("zulip"), | ||||
|         "Mr. Delete", | ||||
|         role=200, | ||||
|         acting_user=None, | ||||
|     ) | ||||
|     realm = get_realm("zulip") | ||||
|     test_user = get_user(test_user_email, realm) | ||||
|     test_user_api_key = get_api_key(test_user) | ||||
|     # change authentication line to allow test_client to delete itself. | ||||
|     AUTHENTICATION_LINE[0] = f"{deactivate_test_user.email}:{test_user_api_key}" | ||||
|     return {} | ||||
|   | ||||
		Reference in New Issue
	
	Block a user