test_profile.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright 2014-2021 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. from synapse.types import UserID
  15. from tests import unittest
  16. class ProfileStoreTestCase(unittest.HomeserverTestCase):
  17. def prepare(self, reactor, clock, hs):
  18. self.store = hs.get_datastore()
  19. self.u_frank = UserID.from_string("@frank:test")
  20. def test_displayname(self):
  21. self.get_success(self.store.create_profile(self.u_frank.localpart))
  22. self.get_success(
  23. self.store.set_profile_displayname(self.u_frank.localpart, "Frank")
  24. )
  25. self.assertEquals(
  26. "Frank",
  27. (
  28. self.get_success(
  29. self.store.get_profile_displayname(self.u_frank.localpart)
  30. )
  31. ),
  32. )
  33. # test set to None
  34. self.get_success(
  35. self.store.set_profile_displayname(self.u_frank.localpart, None)
  36. )
  37. self.assertIsNone(
  38. self.get_success(self.store.get_profile_displayname(self.u_frank.localpart))
  39. )
  40. def test_avatar_url(self):
  41. self.get_success(self.store.create_profile(self.u_frank.localpart))
  42. self.get_success(
  43. self.store.set_profile_avatar_url(
  44. self.u_frank.localpart, "http://my.site/here"
  45. )
  46. )
  47. self.assertEquals(
  48. "http://my.site/here",
  49. (
  50. self.get_success(
  51. self.store.get_profile_avatar_url(self.u_frank.localpart)
  52. )
  53. ),
  54. )
  55. # test set to None
  56. self.get_success(
  57. self.store.set_profile_avatar_url(self.u_frank.localpart, None)
  58. )
  59. self.assertIsNone(
  60. self.get_success(self.store.get_profile_avatar_url(self.u_frank.localpart))
  61. )