test_models.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. # Copyright 2022 The Matrix.org Foundation C.I.C.
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. import unittest
  15. from pydantic import ValidationError
  16. from synapse.rest.client.models import EmailRequestTokenBody
  17. class EmailRequestTokenBodyTestCase(unittest.TestCase):
  18. base_request = {
  19. "client_secret": "hunter2",
  20. "email": "alice@wonderland.com",
  21. "send_attempt": 1,
  22. }
  23. def test_token_required_if_id_server_provided(self) -> None:
  24. with self.assertRaises(ValidationError):
  25. EmailRequestTokenBody.parse_obj(
  26. {
  27. **self.base_request,
  28. "id_server": "identity.wonderland.com",
  29. }
  30. )
  31. with self.assertRaises(ValidationError):
  32. EmailRequestTokenBody.parse_obj(
  33. {
  34. **self.base_request,
  35. "id_server": "identity.wonderland.com",
  36. "id_access_token": None,
  37. }
  38. )
  39. def test_token_typechecked_when_id_server_provided(self) -> None:
  40. with self.assertRaises(ValidationError):
  41. EmailRequestTokenBody.parse_obj(
  42. {
  43. **self.base_request,
  44. "id_server": "identity.wonderland.com",
  45. "id_access_token": 1337,
  46. }
  47. )