def test_get_tags_response(self): print("Testing get tags by response id") auth = common.make_user(GATEWAY_URL, common.generate_user()) form1 = common.make_form(GATEWAY_URL, auth, common.generate_form()) form2 = common.make_form(GATEWAY_URL, auth, common.generate_form()) common.post_form_user(GATEWAY_URL, form1["id"], common.generate_response()) common.post_form_user(GATEWAY_URL, form2["id"], common.generate_response()) resp1 = common.get_responses_params(GATEWAY_URL, auth, {"formID": form1["id"]})[0] resp2 = common.get_responses_params(GATEWAY_URL, auth, {"formID": form2["id"]})[0] assert len(common.get_all_tags_response(GATEWAY_URL, auth, resp1["id"])) == 3 assert len(common.get_all_tags_response(GATEWAY_URL, auth, resp2["id"])) == 3 assert len( common.get_response(GATEWAY_URL, auth, resp1["id"])["tags"]) == 3 assert len( common.get_response(GATEWAY_URL, auth, resp2["id"])["tags"]) == 3 allresps = common.get_responses(GATEWAY_URL, auth) assert sum([len(res["tags"]) for res in allresps]) == 6
def test_get_responses_inquiry(self): print("Testing get responses (filter: inquiryType)") auth = common.make_user(GATEWAY_URL, common.generate_user()) form = common.make_form(GATEWAY_URL, auth, common.generate_form()) form2 = common.make_form(GATEWAY_URL, auth, common.generate_form()) resp1 = common.generate_response() resp1["inquiryType"] = "casework" resp2 = common.generate_response() resp2["inquiryType"] = "general" common.post_form_user(GATEWAY_URL, form["id"], resp1) common.post_form_user(GATEWAY_URL, form["id"], resp1) common.post_form_user(GATEWAY_URL, form["id"], resp2) common.post_form_user(GATEWAY_URL, form2["id"], resp1) common.post_form_user(GATEWAY_URL, form2["id"], resp2) assert len( common.get_responses_params(GATEWAY_URL, auth, {"inquiryType": "casework"})) == 3 assert len( common.get_responses_params(GATEWAY_URL, auth, {"inquiryType": "general"})) == 2 assert len( common.get_responses_params(GATEWAY_URL, auth, {"inquiryType": "INVALID"})) == 0
def test_create_tag(self): print("Testing create tag") auth = common.make_user(GATEWAY_URL, common.generate_user()) form = common.make_form(GATEWAY_URL, auth, common.generate_form()) common.post_form_user(GATEWAY_URL, form["id"], common.generate_response()) resp = common.get_responses_params(GATEWAY_URL, auth, {"formID": form["id"]})[0] common.make_tag(GATEWAY_URL, auth, resp["id"], common.randstr(5, 10))
def test_get_response(self): print("Testing get response") auth = common.make_user(GATEWAY_URL, common.generate_user()) form = common.make_form(GATEWAY_URL, auth, common.generate_form()) common.post_form_user(GATEWAY_URL, form["id"], common.generate_response()) resps = common.get_responses_params(GATEWAY_URL, auth, {"formID": form["id"]}) common.get_response(GATEWAY_URL, auth, resps[0]["id"])
def test_get_all_tags(self): print("Testing get tags") auth = common.make_user(GATEWAY_URL, common.generate_user()) form = common.make_form(GATEWAY_URL, auth, common.generate_form()) common.post_form_user(GATEWAY_URL, form["id"], common.generate_response()) resp = common.get_responses_params(GATEWAY_URL, auth, {"formID": form["id"]})[0] assert len(common.get_all_tags(GATEWAY_URL, auth)) == 3
def test_create_tag(self): auth = common.make_user(GATEWAY_URL, common.generate_user()) form = common.make_form(GATEWAY_URL, auth, common.generate_form()) common.post_form_user(GATEWAY_URL, form["id"], common.generate_response()) resp = common.get_responses_params(GATEWAY_URL, auth, {"formID": form["id"]})[0] N = 100 tag_vals = [f"test_{i}" for i in range(N)] @timeit("test_create_tag", N) def run(): for i in range(N): common.make_tag(GATEWAY_URL, auth, resp["id"], tag_vals[i]) run()
def test_patch_response(self): print("Testing patch response") auth = common.make_user(GATEWAY_URL, common.generate_user()) form = common.make_form(GATEWAY_URL, auth, common.generate_form()) common.post_form_user(GATEWAY_URL, form["id"], common.generate_response()) resp = common.get_responses_params(GATEWAY_URL, auth, {"formID": form["id"]})[0] common.patch_response(GATEWAY_URL, auth, resp["id"], False) updated = common.get_response(GATEWAY_URL, auth, resp["id"]) assert updated["active"] == False common.patch_response(GATEWAY_URL, auth, resp["id"], True) updated = common.get_response(GATEWAY_URL, auth, resp["id"]) assert updated["active"] == True
def test_get_responses_today(self): print("Testing get responses (filter: todayOnly)") auth = common.make_user(GATEWAY_URL, common.generate_user()) form = common.make_form(GATEWAY_URL, auth, common.generate_form()) form2 = common.make_form(GATEWAY_URL, auth, common.generate_form()) resp1 = common.generate_response() resp2 = common.generate_response() common.post_form_user(GATEWAY_URL, form["id"], resp1) common.post_form_user(GATEWAY_URL, form["id"], resp1) common.post_form_user(GATEWAY_URL, form["id"], resp2) common.post_form_user(GATEWAY_URL, form2["id"], resp1) common.post_form_user(GATEWAY_URL, form2["id"], resp2) assert len( common.get_responses_params(GATEWAY_URL, auth, {"todayOnly": True})) == 5
def test_get_responses_name(self): print("Testing get responses (filter: name)") auth = common.make_user(GATEWAY_URL, common.generate_user()) form = common.make_form(GATEWAY_URL, auth, common.generate_form()) form2 = common.make_form(GATEWAY_URL, auth, common.generate_form()) resp1 = common.generate_response() resp2 = common.generate_response() common.post_form_user(GATEWAY_URL, form["id"], resp1) common.post_form_user(GATEWAY_URL, form["id"], resp1) common.post_form_user(GATEWAY_URL, form["id"], resp2) common.post_form_user(GATEWAY_URL, form2["id"], resp1) common.post_form_user(GATEWAY_URL, form2["id"], resp2) assert len( common.get_responses_params(GATEWAY_URL, auth, {"name": resp1["name"]})) == 3
def test_patch_response(self): auth = common.make_user(GATEWAY_URL, common.generate_user()) form = common.make_form(GATEWAY_URL, auth, common.generate_form()) common.post_form_user(GATEWAY_URL, form["id"], common.generate_form()) resp = common.get_responses_params(GATEWAY_URL, auth, {"formID": form["id"]})[0] N = 100 @timeit(f"test_patch_response", N) def run(): new_state = False for _ in range(N): common.patch_response(GATEWAY_URL, auth, resp["id"], new_state) new_state = not new_state run()
def test_get_responses_active(self): print("Testing get responses (filter: activeOnly)") auth = common.make_user(GATEWAY_URL, common.generate_user()) form = common.make_form(GATEWAY_URL, auth, common.generate_form()) form2 = common.make_form(GATEWAY_URL, auth, common.generate_form()) resp1 = common.generate_response() resp2 = common.generate_response() common.post_form_user(GATEWAY_URL, form["id"], resp1) common.post_form_user(GATEWAY_URL, form["id"], resp1) common.post_form_user(GATEWAY_URL, form["id"], resp2) common.post_form_user(GATEWAY_URL, form2["id"], resp1) common.post_form_user(GATEWAY_URL, form2["id"], resp2) # mark 3 of the responses as non-active, leaving 2 active resps = common.get_responses(GATEWAY_URL, auth) for resp in resps[:3]: common.patch_response(GATEWAY_URL, auth, resp["id"], False) assert len( common.get_responses_params(GATEWAY_URL, auth, {"activeOnly": True})) == 2