def test_qm_usergroup_iterate_complete(): with mock.patch("umapi_client.connection.requests.Session.get") as mock_get: mock_get.side_effect = [MockResponse(200, [{"name": "n1", "type": "user-group"}, {"name": "n2", "type": "user-group"}], {"X-Total-Count": "4", "X-Page-Count": "2", "X-Current-Page": "1", "X-Page-Size:": "2"}), MockResponse(200, [{"name": "n3", "type": "user-group"}, {"name": "n4", "type": "user-group"}], {"X-Total-Count": "4", "X-Page-Count": "2", "X-Current-Page": "2", "X-Page-Size:": "2"})] conn = Connection(**mock_connection_params) qm = QueryMultiple(conn, "user-group") for obj in qm: if obj["name"] == "n3": break assert qm.all_results() == [{"name": "n1", "type": "user-group"}, {"name": "n2", "type": "user-group"}, {"name": "n3", "type": "user-group"}, {"name": "n4", "type": "user-group"}]
def test_qm_user_reload(): with mock.patch("umapi_client.connection.requests.Session.get") as mock_get: mock_get.side_effect = [MockResponse(200, {"result": "success", "lastPage": False, "users": [{"name": "n1", "type": "user"}, {"name": "n2", "type": "user"}]}), MockResponse(200, {"result": "success", "lastPage": True, "users": [{"name": "n3", "type": "user"}, {"name": "n4", "type": "user"}]}), MockResponse(200, {"result": "success", "lastPage": False, "users": [{"name": "n5", "type": "user"}, {"name": "n6", "type": "user"}]}), MockResponse(200, {"result": "success", "lastPage": True, "users": [{"name": "n7", "type": "user"}, {"name": "n8", "type": "user"}]})] conn = Connection(**mock_connection_params) qm = QueryMultiple(conn, "user") assert list(qm) == [{"name": "n1", "type": "user"}, {"name": "n2", "type": "user"}, {"name": "n3", "type": "user"}, {"name": "n4", "type": "user"}] qm.reload() assert qm.all_results() == [{"name": "n5", "type": "user"}, {"name": "n6", "type": "user"}, {"name": "n7", "type": "user"}, {"name": "n8", "type": "user"}]
def test_qm_user_iterate_complete(): with mock.patch( "umapi_client.connection.requests.Session.get") as mock_get: mock_get.side_effect = [ MockResponse( 200, { "result": "success", "lastPage": False, "users": [{ "name": "n1", "type": "user" }, { "name": "n2", "type": "user" }] }), MockResponse( 200, { "result": "success", "lastPage": True, "users": [{ "name": "n3", "type": "user" }, { "name": "n4", "type": "user" }] }) ] conn = Connection(**mock_connection_params) qm = QueryMultiple(conn, "user") for obj in qm: if obj["name"] == "n3": break assert qm.all_results() == [{ "name": "n1", "type": "user" }, { "name": "n2", "type": "user" }, { "name": "n3", "type": "user" }, { "name": "n4", "type": "user" }]
def test_qm_usergroup_iterate_partial(): with mock.patch("umapi_client.connection.requests.Session.get") as mock_get: mock_get.side_effect = [MockResponse(200, [{"name": "n1", "type": "user-group"}, {"name": "n2", "type": "user-group"}], {"X-Total-Count": "6", "X-Page-Count": "3", "X-Current-Page": "1", "X-Page-Size:": "2"}), MockResponse(200, [{"name": "n1", "type": "user-group"}, {"name": "n2", "type": "user-group"}], {"X-Total-Count": "6", "X-Page-Count": "3", "X-Current-Page": "2", "X-Page-Size:": "2"}), MockResponse(400, text="400 bad request")] conn = Connection(**mock_connection_params) qm = QueryMultiple(conn, "user-group") for obj in qm: if obj["name"] == "n2": break for obj in qm: if obj["name"] == "n2": break pytest.raises(RequestError, qm.all_results)
def test_qm_usergroup_reload(): with mock.patch("umapi_client.connection.requests.Session.get") as mock_get: mock_get.side_effect = [MockResponse(200, [{"name": "n1", "type": "user-group"}, {"name": "n2", "type": "user-group"}], {"X-Total-Count": "4", "X-Page-Count": "2", "X-Current-Page": "1", "X-Page-Size:": "2"}), MockResponse(200, [{"name": "n3", "type": "user-group"}, {"name": "n4", "type": "user-group"}], {"X-Total-Count": "4", "X-Page-Count": "2", "X-Current-Page": "2", "X-Page-Size:": "2"}), MockResponse(200, [{"name": "n5", "type": "user-group"}, {"name": "n6", "type": "user-group"}], {"X-Total-Count": "4", "X-Page-Count": "2", "X-Current-Page": "1", "X-Page-Size:": "2"}), MockResponse(200, [{"name": "n7", "type": "user-group"}, {"name": "n8", "type": "user-group"}], {"X-Total-Count": "4", "X-Page-Count": "2", "X-Current-Page": "2", "X-Page-Size:": "2"})] conn = Connection(**mock_connection_params) qm = QueryMultiple(conn, "user-group") assert list(qm) == [{"name": "n1", "type": "user-group"}, {"name": "n2", "type": "user-group"}, {"name": "n3", "type": "user-group"}, {"name": "n4", "type": "user-group"}] qm.reload() assert qm.all_results() == [{"name": "n5", "type": "user-group"}, {"name": "n6", "type": "user-group"}, {"name": "n7", "type": "user-group"}, {"name": "n8", "type": "user-group"}]
def test_qm_user_iterate_partial(): with mock.patch( "umapi_client.connection.requests.Session.get") as mock_get: mock_get.side_effect = [ MockResponse( 200, { "result": "success", "lastPage": False, "users": [{ "name": "n1", "type": "user" }, { "name": "n2", "type": "user" }] }), MockResponse( 200, { "result": "success", "lastPage": False, "users": [{ "name": "n1", "type": "user" }, { "name": "n2", "type": "user" }] }), MockResponse(200, {"result": "error"}) ] conn = Connection(**mock_connection_params) qm = QueryMultiple(conn, "user") for obj in qm: if obj["name"] == "n2": break for obj in qm: if obj["name"] == "n2": break pytest.raises(ClientError, qm.all_results)