コード例 #1
0
 def test_get_records_created_in_date_range_requires_query_table(self):
     r = RESTQuery()
     with pytest.raises(AssertionError) as e:
         r.get_records_created_in_date_range("1970-01-01 00:01:00",
                                             "2012-12-12 10:10:45")
     assert "Query table must already be specified in this test case, but is not." in str(
         e)
コード例 #2
0
 def test_cannot_add_query_parameter_first(self):
     r = RESTQuery()
     with pytest.raises(AssertionError) as e:
         r.add_query_parameter("AND", "sys_id", "EQUALS",
                               "546565465e4f654efewfweefeewz")
     assert "No query parameters have been specified yet. Use the ``Required Query Parameter Is`` keyword first." in str(
         e)
コード例 #3
0
 def test_new_rest_query_instance(self):
     r = RESTQuery(host="iceqa.service-now.com")
     assert r.instance == "iceqa"
     with pytest.raises(AssertionError) as e:
         r = RESTQuery(host="")
     assert "Unable to determine SNOW Instance. Verify that the SNOW_TEST_URL environment variable been set." in str(
         e)
コード例 #4
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)
コード例 #5
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
コード例 #6
0
 def test_get_records_created_in_date_range_invalid_format(self):
     r = RESTQuery()
     r.query_table_is("ticket")
     with pytest.raises(AssertionError) as e:
         r.get_records_created_in_date_range("1970-01-01", "2012-12-12")
     assert "Input date arguments were not provided in the correct format. Verify that they are in the format YYYY-MM-DD hh:mm:ss." in str(
         e)
     with pytest.raises(AssertionError) as e:
         r.get_records_created_in_date_range("Michael Rules", "2012-12-12")
     assert "Input date arguments were not provided in the correct format. Verify that they are in the format YYYY-MM-DD hh:mm:ss." in str(
         e)
コード例 #7
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)
コード例 #8
0
 def test_default_new_rest_query_object(self):
     r = RESTQuery()
     assert r.instance == "iceuat", "SNOW_TEST_URL environment variable has not been set correctly, it should be configured to the iceuat instance."
     assert r.user is not None and r.user == os.environ.get(
         "SNOW_REST_USER"
     ), "SNOW_REST_USER environment variable has not been set."
     assert r.password is not None and r.password == os.environ.get(
         "SNOW_REST_PASS"
     ), "SNOW_REST_PASS environment variable has not been set."
     assert r.client
     assert r.query_table is None
     assert r.response is None
コード例 #9
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."
         )
コード例 #10
0
 def test_add_fields_to_desired_response_fields(self):
     r = RESTQuery()
     r.include_fields_in_response("number")
     r.include_fields_in_response("state", "location.name")
     assert len(r.desired_response_fields) == 3
     assert ("number" in r.desired_response_fields
             and "state" in r.desired_response_fields
             and "location.name" in r.desired_response_fields)
コード例 #11
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)
コード例 #12
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)
コード例 #13
0
 def test_desired_response_fields_empty_by_default(self):
     r = RESTQuery()
     assert r.desired_response_fields == []
コード例 #14
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)
コード例 #15
0
 def test_get_record_by_sys_id_no_table(self):
     r = RESTQuery()
     with pytest.raises(AssertionError) as e:
         r.get_record_by_sys_id("ehe876387364nkje")
     assert "Query table must already be specified in this test case, but is not." in str(
         e)
コード例 #16
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"
コード例 #17
0
 def test_get_response_field_values_raise_if_response_empty(self):
     r = RESTQuery()
     with pytest.raises(QueryNotExecuted) as e:
         r.get_response_field_values("sys_created_on")
     assert "No query has been executed." in str(e)
コード例 #18
0
 def test_get_individual_response_field_no_response(self):
     r = RESTQuery()
     with pytest.raises(AssertionError) as e:
         r.get_individual_response_field("test_no_response")
     assert "Failed to retrieve data required for this test." in str(e)
コード例 #19
0
 def test_get_record_count_raises_when_not_set(self):
     r = RESTQuery()
     with pytest.raises(QueryNotExecuted) as e:
         r.get_response_record_count()
     assert "No query has been executed. Use the Execute Query keyword to retrieve records." in str(
         e)
コード例 #20
0
 def test_get_response_record_count_when_set(self):
     r = RESTQuery()
     r.record_count = 10
     assert r.record_count == r.get_response_record_count()
コード例 #21
0
 def test_get_individual_response_field_wrong_field(self):
     response = {
         'bill_to': '',
         'init_request': '',
         'short_description': 'PO 76069-14341 - 95032',
         'total_cost': '0',
         'due_by': '',
         'description': '',
         'requested_for': '',
         'sys_updated_on': '2018-08-08 14:40:48',
         'budget_number': '',
         'u_received_cost': '0',
         'u_business': '',
         'number': 'PO0022269',
         'sys_id': '0407cfa5dbb75b00fdd99257db9619e5',
         'sys_updated_by': 'michael.rose',
         'shipping': '',
         'terms': '',
         'sys_created_on': '2018-08-08 14:40:48',
         'vendor': {
             'link':
             'https://iceuat.service-now.com/api/now/table/core_company/4407cfa5dbb75b00fdd99257db9619e3',
             'value': '4407cfa5dbb75b00fdd99257db9619e3'
         },
         'sys_domain': {
             'link':
             'https://iceuat.service-now.com/api/now/table/sys_user_group/global',
             'value': 'global'
         },
         'department': '',
         'u_po_number': '76069-14341',
         'sys_created_by': 'michael.rose',
         'assigned_to': '',
         'ordered': '',
         'po_date': '7413-01-11 00:10:28',
         'vendor_contract': '',
         'contract': '',
         'expected_delivery': '',
         'sys_mod_count': '0',
         'u_project': {
             'link':
             'https://iceuat.service-now.com/api/now/table/planned_task/02d1a2fa0f94fe809d486eb8b1050e86',
             'value': '02d1a2fa0f94fe809d486eb8b1050e86'
         },
         'received': '',
         'sys_tags': '',
         'requested': '2018-08-08 04:00:00',
         'requested_by': '',
         'u_import_source': {
             'link':
             'https://iceuat.service-now.com/api/now/table/sys_import_set/e2f68fa5dbb75b00fdd99257db961950',
             'value': 'e2f68fa5dbb75b00fdd99257db961950'
         },
         'ship_rate': '0',
         'location': '',
         'vendor_account': '',
         'ship_to': '',
         'status': 'ordered'
     }
     r = RESTQuery(query_table="proc_po", response=response)
     with pytest.raises(AssertionError) as e:
         r.get_individual_response_field("po_aint_got_no_field")
     assert "Field not found in response from proc_po: po_aint_got_no_field" in str(
         e)
コード例 #22
0
 def test_new_rest_query_instance_whitespace_in_host_is_trimmed(self):
     r = RESTQuery(host="    https://iceuat.service-now.com/  ")
     assert r.host == "https://iceuat.service-now.com/"
     assert r.instance == "iceuat"