Пример #1
0
    def test_endpoint_optional_not_int(self, idx_sequence):
        input_file_path = './test_input/valid.json'
        # open input file and check if it is a json
        try:
            with open(input_file_path) as json_file:
                input_dict = json.load(json_file)        
        except:
            raise pytest.fail("The given file is not a json or it could not be read: {}".format(input_file_path))
        
        input_dict['test_sequence'][idx_sequence]['endpoint']['t-way'] = []
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]         
        input_dict['test_sequence'][idx_sequence]['endpoint']['t-way'] = {}
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]   
        input_dict['test_sequence'][idx_sequence]['endpoint']['t-way'] = "test"
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]   
        input_dict['test_sequence'][idx_sequence]['endpoint']['t-way'] = 1
        result = input_json_structure_validator(input_dict)
        assert result[0] == True, result[1]   

        input_dict['test_sequence'][idx_sequence]['endpoint']['allow-duplicities'] = 'test'
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]   
        input_dict['test_sequence'][idx_sequence]['endpoint']['allow-duplicities'] = {}
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1] 
        input_dict['test_sequence'][idx_sequence]['endpoint']['allow-duplicities'] = []
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1] 
        input_dict['test_sequence'][idx_sequence]['endpoint']['allow-duplicities'] = 1521615
        result = input_json_structure_validator(input_dict)
        assert result[0] == True, result[1] 
Пример #2
0
    def test_not_valid_input_json(self, input_file_path):
        conf = read_config_file(config_file)

        # open input file
        with pytest.raises(InputFileError):
            file_content = open_input_json_file(input_file_path)
            assert input_json_structure_validator(file_content)
Пример #3
0
    def test_endpoint_local_params_not_array(self, idx_sequence):
        input_file_path = './test_input/valid.json'
        # open input file and check if it is a json
        try:
            with open(input_file_path) as json_file:
                input_dict = json.load(json_file)        
        except:
            raise pytest.fail("The given file is not a json or it could not be read: {}".format(input_file_path))
        
        input_dict['test_sequence'][idx_sequence]['endpoint']['local_params'] = {}
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]    

        input_dict['test_sequence'][idx_sequence]['endpoint']['local_params'] = 'test'
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1] 
Пример #4
0
    def test_global_params_not_list(self):
        input_file_path = './test_input/valid.json'
        # open input file and check if it is a json
        try:
            with open(input_file_path) as json_file:
                input_dict = json.load(json_file)        
        except:
            raise pytest.fail("The given file is not a json or it could not be read: {}".format(input_file_path))

        input_dict['global_params'] = []
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]
        input_dict['global_params'] = 123456
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]
        input_dict['global_params'] = 'test'
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]
Пример #5
0
    def test_method_is_not_dict(self, idx_sequence):
        input_file_path = './test_input/valid.json'
        # open input file and check if it is a json
        try:
            with open(input_file_path) as json_file:
                input_dict = json.load(json_file)        
        except:
            raise pytest.fail("The given file is not a json or it could not be read: {}".format(input_file_path))

        input_dict['test_sequence'][idx_sequence]['method'] = []
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]
        input_dict['test_sequence'][idx_sequence]['method'] = 'GET'
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]
        input_dict['test_sequence'][idx_sequence]['method'] = 165156
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]
Пример #6
0
    def test_endpoint_does_not_exist(self, idx_sequence):
        input_file_path = './test_input/valid.json'
        # open input file and check if it is a json
        try:
            with open(input_file_path) as json_file:
                input_dict = json.load(json_file)        
        except:
            raise pytest.fail("The given file is not a json or it could not be read: {}".format(input_file_path))

        del input_dict['test_sequence'][idx_sequence]['endpoint']
        assert input_json_structure_validator(input_dict)[0] == False
Пример #7
0
    def test_sequence_calls_array(self):
        input_file_path = './test_input/valid.json'
        # open input file and check if it is a json
        try:
            with open(input_file_path) as json_file:
                input_dict = json.load(json_file)        
        except:
            raise pytest.fail("The given file is not a json or it could not be read: {}".format(input_file_path))
        
        # empty array
        input_dict['test_sequence'] = []
        input_dict['test_sequence'].append([])
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]

        # something is in array
        input_dict['test_sequence'] = []
        input_dict['test_sequence'].append(["test"])
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]
Пример #8
0
 def test_mandatory_is_missing(self, mandatory_elements):
     input_file_path = './test_input/valid.json'
     # open input file and check if it is a json
     try:
         with open(input_file_path) as json_file:
             input_dict = json.load(json_file)        
     except:
         raise pytest.fail("The given file is not a json or it could not be read: {}".format(input_file_path))
     
     del input_dict[mandatory_elements]
     result = input_json_structure_validator(input_dict)
     assert result[0] == False, result[1]
Пример #9
0
    def test_global_params_content_empty_array(self):
        input_file_path = './test_input/valid.json'
        # open input file and check if it is a json
        try:
            with open(input_file_path) as json_file:
                input_dict = json.load(json_file)        
        except:
            raise pytest.fail("The given file is not a json or it could not be read: {}".format(input_file_path))

        input_dict['global_params']['variable1'] = [1,2,3,45,6]
        input_dict['global_params']['variable2'] = []
        result = input_json_structure_validator(input_dict)
        assert result[0] == False, result[1]
Пример #10
0
    def test_missing_endpoint_optional(self, idx_sequence):   
        input_file_path = './test_input/valid.json'
        # open input file and check if it is a json
        try:
            with open(input_file_path) as json_file:
                input_dict = json.load(json_file)        
        except:
            raise pytest.fail("The given file is not a json or it could not be read: {}".format(input_file_path))
        
        input_dict['test_sequence'][idx_sequence]['endpoint']['t-way'] = 1
        input_dict['test_sequence'][idx_sequence]['endpoint']['allow-duplicities'] = 1

        # t-way is missing
        del input_dict['test_sequence'][idx_sequence]['endpoint']['t-way']
        result = input_json_structure_validator(input_dict)
        assert result[0] == True, result[1]

        # allow-duplicities is missing
        input_dict['test_sequence'][idx_sequence]['endpoint']['t-way'] = 1
        del input_dict['test_sequence'][idx_sequence]['endpoint']['allow-duplicities']
        result = input_json_structure_validator(input_dict)
        assert result[0] == True, result[1]
Пример #11
0
     logging.debug('Parsing the arguments')
     args = argument_parser()
     input_file_path = args.filename
     framework = args.framework
     output_path = args.output
 except:
     message = 'Something went wrong with parsing of arguments'
     raise ArgumentError(__name__, "main", message)
 """
 Check the input json file structure
 * Retrieve the data from input json file
 * Create an object 'inputClass' and store those data into it
 """
 logging.debug('Checking the input json file structure')
 file_content = open_input_json_file(input_file_path)
 is_valid = input_json_structure_validator(file_content)
 if is_valid[0] == False:
     message = is_valid[1]
     raise InputFileError(__name__, "main", message)
 globe.inputData = globe.InputDataClass(file_content)
 """
 Create a input file for templator module
 * Go through all requests in test sequence
 ** Get the information about each mandatory key (endpoint, method, header, body)
 *** call a combine if the 't-way' element is inside
 ** Call a combine to get all requests with combined values of endpoint, method, header and body
 * Combine all the resulted requests together with other requests in sequence
 """
 preparator_output_file = './result/preparator_output'
 combined_requests = create_input_file_for_templator(
     file_content, preparator_output_file)