test_presence.py 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 PresenceStoreTestCase(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_apple = UserID.from_string("@apple:test")
  25. self.u_banana = UserID.from_string("@banana:test")
  26. @defer.inlineCallbacks
  27. def test_presence_list(self):
  28. self.assertEquals(
  29. [],
  30. (
  31. yield self.store.get_presence_list(
  32. observer_localpart=self.u_apple.localpart
  33. )
  34. ),
  35. )
  36. self.assertEquals(
  37. [],
  38. (
  39. yield self.store.get_presence_list(
  40. observer_localpart=self.u_apple.localpart, accepted=True
  41. )
  42. ),
  43. )
  44. yield self.store.add_presence_list_pending(
  45. observer_localpart=self.u_apple.localpart,
  46. observed_userid=self.u_banana.to_string(),
  47. )
  48. self.assertEquals(
  49. [{"observed_user_id": "@banana:test", "accepted": 0}],
  50. (
  51. yield self.store.get_presence_list(
  52. observer_localpart=self.u_apple.localpart
  53. )
  54. ),
  55. )
  56. self.assertEquals(
  57. [],
  58. (
  59. yield self.store.get_presence_list(
  60. observer_localpart=self.u_apple.localpart, accepted=True
  61. )
  62. ),
  63. )
  64. yield self.store.set_presence_list_accepted(
  65. observer_localpart=self.u_apple.localpart,
  66. observed_userid=self.u_banana.to_string(),
  67. )
  68. self.assertEquals(
  69. [{"observed_user_id": "@banana:test", "accepted": 1}],
  70. (
  71. yield self.store.get_presence_list(
  72. observer_localpart=self.u_apple.localpart
  73. )
  74. ),
  75. )
  76. self.assertEquals(
  77. [{"observed_user_id": "@banana:test", "accepted": 1}],
  78. (
  79. yield self.store.get_presence_list(
  80. observer_localpart=self.u_apple.localpart, accepted=True
  81. )
  82. ),
  83. )
  84. yield self.store.del_presence_list(
  85. observer_localpart=self.u_apple.localpart,
  86. observed_userid=self.u_banana.to_string(),
  87. )
  88. self.assertEquals(
  89. [],
  90. (
  91. yield self.store.get_presence_list(
  92. observer_localpart=self.u_apple.localpart
  93. )
  94. ),
  95. )
  96. self.assertEquals(
  97. [],
  98. (
  99. yield self.store.get_presence_list(
  100. observer_localpart=self.u_apple.localpart, accepted=True
  101. )
  102. ),
  103. )