1
0

test_profile.py 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2016 OpenMarket Ltd
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. from twisted.internet import defer
  16. from synapse.types import UserID
  17. from tests import unittest
  18. from tests.utils import setup_test_homeserver
  19. class ProfileStoreTestCase(unittest.TestCase):
  20. @defer.inlineCallbacks
  21. def setUp(self):
  22. hs = yield setup_test_homeserver(self.addCleanup)
  23. self.store = hs.get_datastore()
  24. self.u_frank = UserID.from_string("@frank:test")
  25. @defer.inlineCallbacks
  26. def test_displayname(self):
  27. yield defer.ensureDeferred(self.store.create_profile(self.u_frank.localpart))
  28. yield defer.ensureDeferred(
  29. self.store.set_profile_displayname(self.u_frank.localpart, "Frank")
  30. )
  31. self.assertEquals(
  32. "Frank",
  33. (
  34. yield defer.ensureDeferred(
  35. self.store.get_profile_displayname(self.u_frank.localpart)
  36. )
  37. ),
  38. )
  39. # test set to None
  40. yield defer.ensureDeferred(
  41. self.store.set_profile_displayname(self.u_frank.localpart, None)
  42. )
  43. self.assertIsNone(
  44. (
  45. yield defer.ensureDeferred(
  46. self.store.get_profile_displayname(self.u_frank.localpart)
  47. )
  48. )
  49. )
  50. @defer.inlineCallbacks
  51. def test_avatar_url(self):
  52. yield defer.ensureDeferred(self.store.create_profile(self.u_frank.localpart))
  53. yield defer.ensureDeferred(
  54. self.store.set_profile_avatar_url(
  55. self.u_frank.localpart, "http://my.site/here"
  56. )
  57. )
  58. self.assertEquals(
  59. "http://my.site/here",
  60. (
  61. yield defer.ensureDeferred(
  62. self.store.get_profile_avatar_url(self.u_frank.localpart)
  63. )
  64. ),
  65. )
  66. # test set to None
  67. yield defer.ensureDeferred(
  68. self.store.set_profile_avatar_url(self.u_frank.localpart, None)
  69. )
  70. self.assertIsNone(
  71. (
  72. yield defer.ensureDeferred(
  73. self.store.get_profile_avatar_url(self.u_frank.localpart)
  74. )
  75. )
  76. )