Exemple #1
0
 def _test_login(self, digest):
     endpoint = 'http://localhost:8080/client/api'
     username = '******'
     password = '******'
     client = CookieClient(endpoint, username, password, digest=digest)
     # モックアウト
     response_mock = mock.Mock()
     response_mock.status_code = 200
     response_mock.json = lambda: {
         'loginresponse': {
             'sessionkey': 'hoge',
         },
     }
     client.request = mock.MagicMock(return_value=response_mock)
     # 実行
     client.login(username, password, digest)
     # 検証
     params = {
         'response': 'json',
     }
     headers = {
         'Content-Type': 'application/x-www-form-urlencoded',
     }
     password = self._md5(password) if digest else password
     data = {
         'command': 'login',
         'username': username,
         'password': password,
         'domain': '/',
     }
     calls = [
         mock.call('POST', params, headers, data)
     ]
     client.request.assert_has_calls(calls)
Exemple #2
0
 def test_request(self):
     endpoint = 'http://localhost:8080/client/api'
     username = '******'
     password = '******'
     client = CookieClient(endpoint, username, password)
     # モックアウト
     sessionkey = 'hogehoge'
     client.login = mock.MagicMock(return_value=sessionkey)
     response = mock.Mock()
     response.status_code = 200
     response.headers = {}
     response.json = lambda: {}
     client.request = mock.Mock(return_value=response)
     # 実行
     params = {
         'account': 'admin',
         'response': 'json',
     }
     client.listUsers(**params)
     # 検証
     calls = [
         mock.call(username, password, False)
     ]
     client.login.assert_has_calls(calls)
     params['command'] = 'listUsers'
     params['sessionkey'] = sessionkey
     calls = [
         mock.call(ApiRequest('GET', params, None, None))
     ]
     client.request.assert_has_calls(calls)