コード例 #1
0
 def test_whoami_unauth(self):
     mapi = api.MatrixHttpApi("http://example.com")
     whoami_url = "http://example.com/_matrix/client/r0/account/whoami"
     responses.add(responses.GET,
                   whoami_url,
                   body='{"user_id": "%s"}' % self.user_id)
     with pytest.raises(MatrixError):
         mapi.whoami()
コード例 #2
0
 def test_whoami(self):
     mapi = api.MatrixHttpApi("http://example.com", token=self.token)
     whoami_url = "http://example.com/_matrix/client/r0/account/whoami"
     responses.add(responses.GET,
                   whoami_url,
                   body='{"user_id": "%s"}' % self.user_id)
     mapi.whoami()
     req = responses.calls[0].request
     assert req.method == 'GET'
     assert whoami_url in req.url
コード例 #3
0
 def test_send_token_header(self):
     mapi = api.MatrixHttpApi("http://example.com", token=self.token)
     responses.add(responses.GET,
                   mapi._base_url + MATRIX_V2_API_PATH + self.test_path,
                   body='{"application/json": {"user_id": "%s"}}' %
                   self.user_id)
     mapi._send("GET", self.test_path)
     req = responses.calls[0].request
     assert req.method == 'GET'
     assert req.headers['Authorization'] == 'Bearer %s' % self.token
コード例 #4
0
 def test_send_user_id(self):
     mapi = api.MatrixHttpApi("http://example.com",
                              token=self.token,
                              identity=self.user_id)
     responses.add(responses.GET,
                   mapi._base_url + MATRIX_V2_API_PATH + self.test_path,
                   body='{"application/json": {"user_id": "%s"}}' %
                   self.user_id)
     mapi._send("GET", self.test_path)
     req = responses.calls[0].request
     assert "user_id" in req.url
コード例 #5
0
 def test_send_user_agent_header(self):
     mapi = api.MatrixHttpApi("http://example.com")
     responses.add(responses.GET,
                   mapi._base_url + MATRIX_V2_API_PATH + self.test_path,
                   body='{"application/json": {"user_id": "%s"}}' %
                   self.user_id)
     mapi._send("GET", self.test_path)
     req = responses.calls[0].request
     assert req.method == 'GET'
     assert req.headers[
         'User-Agent'] == 'matrix-python-sdk/%s' % lib_version
コード例 #6
0
 def test_send_request_error(self):
     mapi = api.MatrixHttpApi("http://example.com")
     with pytest.raises(MatrixHttpLibError):
         mapi._send("GET", self.test_path)
コード例 #7
0
 def test_send_unsup_method(self):
     mapi = api.MatrixHttpApi("http://example.com")
     with pytest.raises(MatrixError):
         mapi._send("GOT", self.test_path)