Esempio n. 1
0
 def test_use_validators_jmespath_fail(self):
     try:
         import jmespath
     except ImportError:
         print("Skipping jmespath import test because library absent")
         raise unittest.SkipTest("JMESPath module absent")
     """ Test validators that should fail """
     test = Test()
     test.url = self.prefix + '/api/person/'
     test.validators = list()
     cfg_exists = {'jmespath': 'objects[500]', 'test': 'exists'}
     test.validators.append(
         validators.parse_validator('extract_test', cfg_exists))
     cfg_not_exists = {'jmespath': "objects[1]", 'test': 'not_exists'}
     test.validators.append(
         validators.parse_validator('extract_test', cfg_not_exists))
     cfg_compare = {
         'jmespath': "objects[1].last_name",
         'expected': 'NotJenkins'
     }
     test.validators.append(
         validators.parse_validator('compare', cfg_compare))
     test_response = resttest.run_test(test)
     self.assertFalse(test_response.passed)
     self.assertTrue(test_response.failures)
     self.assertEqual(3, len(test_response.failures))
Esempio n. 2
0
    def test_get_validators(self):
        """ Test that validators work correctly """
        test = Test()
        test.url = self.prefix + "/api/person/"

        # Validators need library calls to configure them
        test.validators = list()
        cfg_exists = {"jsonpath_mini": "objects.0", "test": "exists"}
        test.validators.append(validators.parse_validator("extract_test", cfg_exists))
        cfg_exists_0 = {"jsonpath_mini": "meta.offset", "test": "exists"}
        test.validators.append(validators.parse_validator("extract_test", cfg_exists_0))
        cfg_not_exists = {"jsonpath_mini": "objects.100", "test": "not_exists"}
        test.validators.append(validators.parse_validator("extract_test", cfg_not_exists))
        cfg_compare_login = {"jsonpath_mini": "objects.0.login", "expected": "gbaltar"}
        test.validators.append(validators.parse_validator("compare", cfg_compare_login))
        cfg_compare_id = {"jsonpath_mini": "objects.1.id", "comparator": "gt", "expected": -1}
        test.validators.append(validators.parse_validator("compare", cfg_compare_id))

        test_response = resttest.run_test(test)
        for failure in test_response.failures:
            print("REAL FAILURE")
            print("Test Failure, failure type: {0}, Reason: {1}".format(failure.failure_type, failure.message))
            if failure.details:
                print("Validator/Error details: " + str(failure.details))
        self.assertFalse(test_response.failures)
        self.assertTrue(test_response.passed)
Esempio n. 3
0
    def test_get_validators(self):
        """ Test that validators work correctly """
        test = Test()
        test.url = self.prefix + '/api/person/'
        
        # Validators need library calls to configure them
        test.validators = list()
        cfg_exists = {'jsonpath_mini': "objects.0", 'test':'exists'}
        test.validators.append(validators.parse_validator('extract_test', cfg_exists))
        cfg_exists_0 = {'jsonpath_mini': "meta.offset", 'test':'exists'}
        test.validators.append(validators.parse_validator('extract_test', cfg_exists_0))
        cfg_not_exists = {'jsonpath_mini': "objects.100", 'test':'not_exists'}
        test.validators.append(validators.parse_validator('extract_test', cfg_not_exists))
        cfg_compare_login = {'jsonpath_mini': 'objects.0.login', 'expected': 'gbaltar'}
        test.validators.append(validators.parse_validator('compare', cfg_compare_login))
        cfg_compare_id = {'jsonpath_mini': 'objects.1.id', 'comparator':'gt', 'expected': -1}
        test.validators.append(validators.parse_validator('compare', cfg_compare_id))

        test_response = resttest.run_test(test)
        for failure in test_response.failures:
            print "REAL FAILURE"
            print "Test Failure, failure type: {0}, Reason: {1}".format(failure.failure_type, failure.message)
            if failure.details:
                print "Validator/Error details: "+str(failure.details)
        self.assertFalse(test_response.failures)
        self.assertTrue(test_response.passed)
Esempio n. 4
0
    def test_header_validators(self):
        test = Test()
        test.url = self.prefix + "/api/person/1/"
        config = {"header": "server", "comparator": "contains", "expected": "WSGI"}
        test.validators = list()
        test.validators.append(validators.parse_validator("comparator", config))
        result = resttest.run_test(test)

        if result.failures:
            for fail in result.failures:
                print(fail)
        self.assertTrue(result.passed)
Esempio n. 5
0
 def test_get_validators_fail(self):
     """ Test validators that should fail """
     test = Test()
     test.url = self.prefix + "/api/person/"
     test.validators = list()
     cfg_exists = {"jsonpath_mini": "objects.500", "test": "exists"}
     test.validators.append(validators.parse_validator("extract_test", cfg_exists))
     cfg_not_exists = {"jsonpath_mini": "objects.1", "test": "not_exists"}
     test.validators.append(validators.parse_validator("extract_test", cfg_not_exists))
     cfg_compare = {"jsonpath_mini": "objects.1.last_name", "expected": "NotJenkins"}
     test.validators.append(validators.parse_validator("compare", cfg_compare))
     test_response = resttest.run_test(test)
     self.assertFalse(test_response.passed)
     self.assertTrue(test_response.failures)
     self.assertEqual(3, len(test_response.failures))
Esempio n. 6
0
 def test_get_validators_fail(self):
     """ Test validators that should fail """
     test = Test()
     test.url = self.prefix + '/api/person/'
     test.validators = list()
     cfg_exists = {'jsonpath_mini': "objects.500", 'test':'exists'}
     test.validators.append(validators.parse_validator('extract_test', cfg_exists))
     cfg_not_exists = {'jsonpath_mini': "objects.1", 'test':'not_exists'}
     test.validators.append(validators.parse_validator('extract_test', cfg_not_exists))
     cfg_compare = {'jsonpath_mini': "objects.1.last_name", 'expected':'NotJenkins'}
     test.validators.append(validators.parse_validator('compare', cfg_compare))
     test_response = resttest.run_test(test)
     self.assertFalse(test_response.passed)
     self.assertTrue(test_response.failures)
     self.assertEqual(3, len(test_response.failures))
Esempio n. 7
0
    def test_header_validators(self):
        test = Test()
        test.url = self.prefix + '/api/person/1/'
        config = {
            'header': 'server',
            'comparator': 'contains',
            'expected': 'WSGI'
        }
        test.validators = list()
        test.validators.append(validators.parse_validator(
            'comparator', config))
        result = resttest.run_test(test)

        if result.failures:
            for fail in result.failures:
                print(fail)
        self.assertTrue(result.passed)
Esempio n. 8
0
    def test_header_validators(self):
        test = Test()
        test.url = self.prefix + '/api/person/1/'
        config = {
            'header': 'server',
            'comparator': 'contains',
            'expected': 'WSGI'
        }
        test.validators = list()
        test.validators.append(
            validators.parse_validator('comparator', config))
        result = resttest.run_test(test)

        if result.failures:
            for fail in result.failures:
                print(fail)
        self.assertTrue(result.passed)