You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.5 KiB

  1. from keycloak.keycloak_admin import KeycloakAdmin
  2. def find_code_blocks(readme_text):
  3. code_blocks = list()
  4. start_index = readme_text.find("```python")
  5. if start_index == -1:
  6. return list()
  7. code_block_full = readme_text[start_index + 9 :] # noqa: E203
  8. end_index = code_block_full.find("```")
  9. code_block = code_block_full[:end_index]
  10. code_blocks.append(code_block)
  11. code_blocks.extend(find_code_blocks(code_block_full[end_index + 3 :])) # noqa: E203
  12. return code_blocks
  13. def test_readme(admin: KeycloakAdmin):
  14. admin.create_realm(payload={"realm": "example_realm", "enabled": True})
  15. admin.realm_name = "example_realm"
  16. admin.create_client(
  17. payload={
  18. "name": "example_client",
  19. "enabled": True,
  20. "protocol": "openid-connect",
  21. "publicClient": False,
  22. "redirectUris": ["http://localhost/*"],
  23. "webOrigins": ["+"],
  24. "clientId": "example_client",
  25. "secret": "secret",
  26. "clientAuthenticatorType": "client-secret",
  27. }
  28. )
  29. admin.create_user(
  30. payload={
  31. "username": "user",
  32. "email": "user@test.test",
  33. "enabled": True,
  34. "credentials": [{"type": "password", "value": "password"}],
  35. }
  36. )
  37. with open("README.md", "r") as fp:
  38. readme = fp.read()
  39. code_blocks = find_code_blocks(readme)
  40. for code in code_blocks:
  41. print("=" * 50)
  42. print(code)
  43. exec(code)
  44. print("OK")
  45. print("=" * 50)