def read_users( skip: int = 0, limit: int = 10, db: _orm.Session = _fastapi.Depends(_services.get_db), ): users = _services.get_users(db=db, skip=skip, limit=limit) return users
def test_request_response(self): response = get_users() # Check that below is a subset of response.headers self.assertTrue({'Content-Type': 'application/json; charset=utf-8'}.items() <= response.headers.items()) self.assertTrue(response.ok) self.assertIsInstance(response.json(), list)
def getusers(request): """ Return online users """ try: online_users = services.get_users() except Exception: online_users = None data = json.dumps(online_users) response = HttpResponse() response['Content-Type'] = "text/javascript" response.write(data) return response
def test_request_response(self): mock_users_url = 'http://localhost:{port}/users'.format( port=self.mock_server_port) # Patch USERS_URL so that the service uses the mock server URL instead of the real URL. with patch.dict('project.services.__dict__', {'USERS_URL': mock_users_url}): response = get_users() assert_dict_contains_subset( {'Content-Type': 'application/json; charset=utf-8'}, response.headers) assert_true(response.ok) assert_list_equal(response.json(), [])
def test_request_response(self): mock_users_url = 'http://localhost:{port}/users'.format( port=self.mock_server_port) # Patch USERS_URL so that the service uses the mock server URL instead of the real URL with patch.dict('services.__dict__', {'USERS_URL': mock_users_url}): response = get_users() self.assertTrue({'Content-Type': 'application/json; charset=utf-8' }.items() <= response.headers.items()) self.assertTrue(response.ok) self.assertListEqual(response.json(), [])
def users(): users = services.get_users() l = list(map(lambda u: u.toJSON(), users)) return flask.jsonify(l)