コード例 #1
0
 def test_reset_query(self):
     r = RESTQuery()
     r.required_query_parameter_is("active", "EQUALS", "true")
     r.include_fields_in_response("name", "short_description")
     r._reset_query()  # Called at the end of execute_query in practice
     assert r._query_is_empty()
     assert not r.desired_response_fields
コード例 #2
0
 def test_two_params_too_many_unless_between(self):
     r = RESTQuery()
     with pytest.raises(AssertionError) as e:
         r.required_query_parameter_is("my_field",
                                       "CONTAINs",
                                       param_1="Lily",
                                       param_2="Callie")
     assert "Unexpected arguments for condition type CONTAINS: expected 0 or 1 argument, but got 2." in str(
         e)
コード例 #3
0
 def test_execute_query_no_table(self):
     r = RESTQuery()
     r.required_query_parameter_is(field="sys_id",
                                   condition_type="EQUALS",
                                   param_1="ehe876387364nkje")
     with pytest.raises(AssertionError) as e:
         r.execute_query()
     assert "Query table must already be specified in this test case, but is not." in str(
         e)
コード例 #4
0
 def test_is_empty_query_required_if_no_params(self):
     r = RESTQuery()
     with pytest.raises(AssertionError) as e:
         r.required_query_parameter_is("my_field", "equals")
     assert "Unexpected arguments for condition type EQUALS: expected 1 or 2 arguments, but got none." in str(
         e)
     r.required_query_parameter_is(field="sys_id",
                                   condition_type="EQUALS",
                                   param_1="ehe876387364nkje")
     with pytest.raises(AssertionError) as e:
         r.add_query_parameter("AND", "my_field", "greater than")
     assert "Unexpected arguments for condition type GREATER THAN: expected 1 or 2 arguments, but got none." in str(
         e)
コード例 #5
0
 def test_required_query_parameter_is_date_field(self):
     r = RESTQuery()
     r.query_table_is("incident")
     try:
         r.required_query_parameter_is("sys_created_on",
                                       "BETWEEN",
                                       "2016-05-02 09:45:01",
                                       "2016-05-09 09:45:01",
                                       is_date_field=True)
         r.add_query_parameter("OR", "sys_updated_on", "EQUALS",
                               "2018-08-10 10:23:40")
     except AssertionError:
         pytest.fail(
             "Unexpected AssertionError raised when setting date field query parameter."
         )
コード例 #6
0
 def test_invalid_query_condition_type(self):
     r = RESTQuery()
     with pytest.raises(AssertionError) as e:
         r.required_query_parameter_is(field="sys_id",
                                       condition_type="INVALID",
                                       param_1="ehe876387364nkje")
     assert "Invalid condition type specified." in str(e)
     r.required_query_parameter_is(field="sys_id",
                                   condition_type="EQUALS",
                                   param_1="ehe876387364nkje")
     with pytest.raises(AssertionError) as e:
         r.add_query_parameter("INVALID",
                               field="number",
                               condition_type="EQUALS",
                               param_1="TKT546259")
     assert "Invalid operand" in str(e)
コード例 #7
0
 def test_one_parameter_not_enough_for_between_condition(self):
     r = RESTQuery()
     with pytest.raises(AssertionError) as e:
         r.required_query_parameter_is("my_field", "BeTWeeN", param_1=10)
     assert "Unexpected arguments for condition type BETWEEN: expected 0 or 2 arguments, but got 1." in str(
         e)
コード例 #8
0
 def test_add_parameter_with_nq(self):
     r = RESTQuery()
     r.required_query_parameter_is("description", "CONTAINS", "michael")
     r.add_query_parameter("NQ", "status", "EQUALS", "Open")
     assert r.query._query[-2] == "^NQ"