summary refs log tree commit diff
path: root/tests/federation
diff options
context:
space:
mode:
authorPaul "LeoNerd" Evans <paul@matrix.org>2014-08-13 16:55:53 +0100
committerPaul "LeoNerd" Evans <paul@matrix.org>2014-08-13 17:23:49 +0100
commit827de7cee98d0626f3ca24a04955df2ff1bdfc41 (patch)
tree96e24102fda4523aab3e010f9f5e38efb4e144b8 /tests/federation
parentUpdate get_json()'s documentation to match the actual observed behaviour (diff)
downloadsynapse-827de7cee98d0626f3ca24a04955df2ff1bdfc41.tar.xz
Define the concept of a 'federation Query'; creating API for making and handling Queries on the Federation's increasingly-inaccurately-named ReplicationLayer
Diffstat (limited to 'tests/federation')
-rw-r--r--tests/federation/test_federation.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/federation/test_federation.py b/tests/federation/test_federation.py
index f493ee253e..a3bcb5ede8 100644
--- a/tests/federation/test_federation.py
+++ b/tests/federation/test_federation.py
@@ -62,6 +62,7 @@ class FederationTestCase(unittest.TestCase):
     def setUp(self):
         self.mock_http_server = MockHttpServer()
         self.mock_http_client = Mock(spec=[
+            "get_json",
             "put_json",
         ])
         self.mock_persistence = Mock(spec=[
@@ -253,3 +254,40 @@ class FederationTestCase(unittest.TestCase):
         recv_observer.assert_called_with(
                 "remote", {"testing": "reply here"}
         )
+
+    @defer.inlineCallbacks
+    def test_send_query(self):
+        self.mock_http_client.get_json.return_value = defer.succeed(
+            {"your": "response"}
+        )
+
+        response = yield self.federation.make_query(
+            destination="remote",
+            query_type="a-question",
+            args={"one": "1", "two": "2"}
+        )
+
+        self.assertEquals({"your": "response"}, response)
+
+        self.mock_http_client.get_json.assert_called_with(
+            destination="remote",
+            path="/matrix/federation/v1/query/a-question",
+            args={"one": "1", "two": "2"}
+        )
+
+    @defer.inlineCallbacks
+    def test_recv_query(self):
+        recv_handler = Mock()
+        recv_handler.return_value = defer.succeed({"another": "response"})
+
+        self.federation.register_query_handler("a-question", recv_handler)
+
+        code, response = yield self.mock_http_server.trigger("GET",
+            "/matrix/federation/v1/query/a-question?three=3&four=4", None)
+
+        self.assertEquals(200, code)
+        self.assertEquals({"another": "response"}, response)
+
+        recv_handler.assert_called_with(
+            {"three": "3", "four": "4"}
+        )