test_profile.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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_datastore()
  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.localpart))
  25. self.get_success(
  26. self.store.set_profile_displayname(self.u_frank.localpart, "Frank")
  27. )
  28. self.assertEquals(
  29. "Frank",
  30. (
  31. self.get_success(
  32. self.store.get_profile_displayname(self.u_frank.localpart)
  33. )
  34. ),
  35. )
  36. # test set to None
  37. self.get_success(
  38. self.store.set_profile_displayname(self.u_frank.localpart, None)
  39. )
  40. self.assertIsNone(
  41. self.get_success(self.store.get_profile_displayname(self.u_frank.localpart))
  42. )
  43. def test_avatar_url(self) -> None:
  44. self.get_success(self.store.create_profile(self.u_frank.localpart))
  45. self.get_success(
  46. self.store.set_profile_avatar_url(
  47. self.u_frank.localpart, "http://my.site/here"
  48. )
  49. )
  50. self.assertEquals(
  51. "http://my.site/here",
  52. (
  53. self.get_success(
  54. self.store.get_profile_avatar_url(self.u_frank.localpart)
  55. )
  56. ),
  57. )
  58. # test set to None
  59. self.get_success(
  60. self.store.set_profile_avatar_url(self.u_frank.localpart, None)
  61. )
  62. self.assertIsNone(
  63. self.get_success(self.store.get_profile_avatar_url(self.u_frank.localpart))
  64. )