test_profile.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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.storage.profile import ProfileStore
  17. from synapse.types import UserID
  18. from tests import unittest
  19. from tests.utils import setup_test_homeserver
  20. class ProfileStoreTestCase(unittest.TestCase):
  21. @defer.inlineCallbacks
  22. def setUp(self):
  23. hs = yield setup_test_homeserver(self.addCleanup)
  24. self.store = ProfileStore(hs.get_db_conn(), hs)
  25. self.u_frank = UserID.from_string("@frank:test")
  26. @defer.inlineCallbacks
  27. def test_displayname(self):
  28. yield self.store.create_profile(self.u_frank.localpart)
  29. yield self.store.set_profile_displayname(self.u_frank.localpart, "Frank")
  30. self.assertEquals(
  31. "Frank", (yield self.store.get_profile_displayname(self.u_frank.localpart))
  32. )
  33. @defer.inlineCallbacks
  34. def test_avatar_url(self):
  35. yield self.store.create_profile(self.u_frank.localpart)
  36. yield self.store.set_profile_avatar_url(
  37. self.u_frank.localpart, "http://my.site/here"
  38. )
  39. self.assertEquals(
  40. "http://my.site/here",
  41. (yield self.store.get_profile_avatar_url(self.u_frank.localpart)),
  42. )