Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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."
         )
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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"