1
0

test_profile.py 2.3 KB

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