test_sync.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. # -*- coding: utf-8 -*-
  2. # Copyright 2018 New Vector
  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 mock import Mock
  16. from synapse.rest.client.v2_alpha import sync
  17. from tests import unittest
  18. class FilterTestCase(unittest.HomeserverTestCase):
  19. user_id = "@apple:test"
  20. servlets = [sync.register_servlets]
  21. def make_homeserver(self, reactor, clock):
  22. hs = self.setup_test_homeserver(
  23. "red", http_client=None, federation_client=Mock()
  24. )
  25. return hs
  26. def test_sync_argless(self):
  27. request, channel = self.make_request("GET", "/sync")
  28. self.render(request)
  29. self.assertEqual(channel.code, 200)
  30. self.assertTrue(
  31. set(
  32. [
  33. "next_batch",
  34. "rooms",
  35. "presence",
  36. "account_data",
  37. "to_device",
  38. "device_lists",
  39. ]
  40. ).issubset(set(channel.json_body.keys()))
  41. )
  42. def test_sync_presence_disabled(self):
  43. """
  44. When presence is disabled, the key does not appear in /sync.
  45. """
  46. self.hs.config.use_presence = False
  47. request, channel = self.make_request("GET", "/sync")
  48. self.render(request)
  49. self.assertEqual(channel.code, 200)
  50. self.assertTrue(
  51. set(
  52. ["next_batch", "rooms", "account_data", "to_device", "device_lists"]
  53. ).issubset(set(channel.json_body.keys()))
  54. )