Ejemplo n.º 1
0
 def test_config_ValidArguments_ReturnDict(self, config_file):
     """
     Test that given valid arguments, the function returns a valid dict
     """
     block_dict = {
         "args": {
             "path": config_file,
             "format": "config",
             'pattern': ".*(3|1).*",
             'ignore_pattern': ".*3.*",
             'dictsep': "=",
             'valsep': ';',
             'subsep': ':'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = True, {
         "APP_ATTRIBUTES": {
             "cluster_role": "worker",
             "zone": "1",
             "provider": "aws"
         }
     }
     assert expected_status == status
     assert expected_ret == ret['result']
Ejemplo n.º 2
0
    def test_json_InvalidPath_EmptyReturn(self):
        """
        Test that given an invalid path, the json function returns False status
        and None value
        """
        block_dict = {"args": {"path": "test", "format": "json"}}
        check_id = "test-1"
        status, ret = readfile.execute(check_id, block_dict)

        expected_status, expected_ret = False, {'error': 'file_not_found'}
        assert expected_status == status
        assert expected_ret == ret
Ejemplo n.º 3
0
 def test_config_InvalidPath_ReturnNone(self):
     """
     Test that given an invalid ``path``, the function returns ``None``
     """
     block_dict = {
         "args": {
             "path": '/invalid/path',
             "format": "config",
             'subkey': 'invalid_key'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = False, None
     assert expected_status == status
Ejemplo n.º 4
0
 def test_config_EmptyArguments_ReturnList(self, config_file):
     """
     Test that given empty arguemtsn, the function returns a list with lines as elements
     """
     block_dict = {
         "args": {
             "path": config_file,
             "format": "config",
             'subkey': 'invalid_key'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = True, self.generate_config_data()
     assert expected_status == status
     assert expected_ret == ret['result']
Ejemplo n.º 5
0
 def test_yaml_InvalidSingleSubkey_EmptyReturn(self, yaml_file):
     """
     Test that given an invalid single subkey argument,
     the function returns False status and empty value
     """
     block_dict = {
         "args": {
             "path": yaml_file,
             "format": "yaml",
             'subkey': 'invalid_key'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = False, None
     assert expected_status == status
Ejemplo n.º 6
0
 def test_yaml_InvalidPath_EmptyReturn(self):
     """
     Test that given an invalid path, the yaml function returns False status
     and an empty return value
     """
     block_dict = {
         "args": {
             "path": '/invalid/path',
             "format": "yaml",
             'subkey': 'id'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = False, None
     assert expected_status == status
Ejemplo n.º 7
0
 def test_yaml_SingleSubkey_ReturnsValue(self, yaml_file):
     """
     Test that given a single subkey argument, the function extracts the appropriated value
     """
     block_dict = {
         "args": {
             "path": yaml_file,
             "format": "yaml",
             'subkey': 'id'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = True, "file"
     assert expected_status == status
     assert expected_ret == ret['result']
Ejemplo n.º 8
0
 def _test_yaml_InvalidJsonFile_EmptyReturn(self, yaml_file):
     """
     Test that given an invalid yaml file, the function returns False status and None value
     """
     with open(yaml_file, 'w+') as invalid_file:
         invalid_file.write("invalidyaml")
     block_dict = {
         "args": {
             "path": yaml_file,
             "format": "yaml",
             'subkey': 'id'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = False, None
     assert expected_status == status
Ejemplo n.º 9
0
 def test_yaml_IndexSubkey_ReturnsValue(self, yaml_file):
     """
     Test that given an index as subkey, the function returns the appropriate value
     """
     block_dict = {
         "args": {
             "path": yaml_file,
             "format": "yaml",
             'subkey': 'menuitem,1',
             'sep': ','
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = True, "item2"
     assert expected_status == status
     assert expected_ret == ret['result']
Ejemplo n.º 10
0
 def test_yaml_InvalidSep_EmptyReturn(self, yaml_file):
     """
     Test that given multiple subkeys separated by an invalid ``sep``,
     the function returns a False status and None value
     """
     block_dict = {
         "args": {
             "path": yaml_file,
             "format": "yaml",
             'subkey': 'value,key2,key3',
             'sep': '/'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = False, None
     assert expected_status == status
Ejemplo n.º 11
0
 def test_yaml_InvalidIndexSubkey_EmptyReturn(self, yaml_file):
     """
     Test that given an index as subkey that exceeds the list length,
     the function returns False status and None value
     """
     block_dict = {
         "args": {
             "path": yaml_file,
             "format": "yaml",
             'subkey': 'menuitem,15',
             'sep': ','
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = False, None
     assert expected_status == status
Ejemplo n.º 12
0
 def test_yaml_MultipleSubkeys_ReturnsValue(self, yaml_file):
     """
     Test that given multiple subkeys, separated by a valid separator,
     the function returns the appropriate value
     """
     block_dict = {
         "args": {
             "path": yaml_file,
             "format": "yaml",
             'subkey': 'value,key2,key3',
             'sep': ','
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = True, "value2"
     assert expected_status == status
     assert expected_ret == ret['result']
Ejemplo n.º 13
0
 def test_json_EmptyFile_EmptyReturn(self, json_file):
     """
     Test that given an empty json file, the function returns False status and None value
     """
     with open(json_file, 'r+') as invalid_file:
         invalid_file.truncate(0)
     block_dict = {
         "args": {
             "path": json_file,
             "format": "json",
             'subkey': 'id'
         }
     }
     check_id = "test-1"
     status, ret = readfile.execute(check_id, block_dict)
     expected_status, expected_ret = False, None
     assert expected_status == status
Ejemplo n.º 14
0
 def test_json_IndexSubkey_ReturnsValue(self, json_file):
     """
     Test that given an index as subkey, the function returns the correct value
     """
     block_dict = {
         "args": {
             "path": json_file,
             "format": "json",
             'subkey': 'menuitem,1',
             'sep': ','
         }
     }
     check_id = "test-1"
     status, ret = readfile.execute(check_id, block_dict)
     expected_status, expected_ret = True, "item2"
     assert expected_status == status
     assert expected_ret == ret['result']
Ejemplo n.º 15
0
 def test_json_InvalidSep_EmptyReturn(self, json_file):
     """
     Test that given multiple subkeys separated by an invalid separator``sep``,
     the function returns False status and None value
     """
     block_dict = {
         "args": {
             "path": json_file,
             "format": "json",
             'subkey': 'value,key2,key3',
             'sep': '/'
         }
     }
     check_id = "test-1"
     status, ret = readfile.execute(check_id, block_dict)
     expected_status, expected_ret = False, None
     assert expected_status == status
Ejemplo n.º 16
0
 def test_config_SamePatternIgnore_ReturnEmptyDict(self, config_file):
     """
     Test that given the same ``pattern`` and ``ignore_pattern``
     """
     block_dict = {
         "args": {
             "path": config_file,
             "format": "config",
             'pattern': "APP_ATTRIBUTES",
             'ignore_pattern': "APP_ATTRIBUTES",
             'dictsep': "="
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = True, {}
     assert expected_status == status
     assert expected_ret == ret['result']
Ejemplo n.º 17
0
    def test_json_SingleSubkey_ReturnsValue(self, json_file):
        """
        Test that given a single subkey argument, the function extracts the correct value
        """
        block_dict = {
            "args": {
                "path": json_file,
                "format": "json",
                "subkey": 'id'
            }
        }
        check_id = "test-1"
        status, ret = readfile.execute(check_id, block_dict)

        expected_status, expected_ret = True, "file"
        assert expected_status == status
        assert expected_ret == ret['result']
Ejemplo n.º 18
0
    def test_json_InvalidSingleSubkey_EmptyReturn(self, json_file):
        """
        Test that given an invalid single subkey argument,
        the function returns False status and None value
        """
        block_dict = {
            "args": {
                "path": json_file,
                "format": "json",
                "subkey": 'invalid_key'
            }
        }
        check_id = "test-1"
        status, ret = readfile.execute(check_id, block_dict)
        expected_status, expected_ret = False, {'error': 'KeyError'}

        assert expected_status == status
        assert expected_ret == ret
Ejemplo n.º 19
0
    def test_json_MultipleSubkeys_ReturnsValue(self, json_file):
        """
        Test that given multiple subkeys, separated by a valid separator ``sep``,
        the function returns the correct value
        """
        block_dict = {
            "args": {
                "path": json_file,
                "format": "json",
                "subkey": 'value,key2,key3',
                "sep": ','
            }
        }
        check_id = "test-1"
        status, ret = readfile.execute(check_id, block_dict)

        expected_status, expected_ret = True, "value2"
        assert expected_status == status
        assert expected_ret == ret['result']
Ejemplo n.º 20
0
 def test_config_OnlyDictsep_ReturnDict(self, config_file):
     """
     Test that given a valid ``dictsep`` and empty arguments,
     the function returns a valid ``dict``
     """
     block_dict = {
         "args": {
             "path": config_file,
             "format": "config",
             'dictsep': "="
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     sample_data = self.generate_config_data()
     expected_status, expected_ret = True, {
         "APP_ATTRIBUTES": [x.split("=")[1] for x in sample_data]
     }
     assert expected_status == status
     assert expected_ret == ret['result']
Ejemplo n.º 21
0
 def test_config_EmptySubsep_ReturnDict(self, config_file):
     """
     Test that given valid arguments and an empty ``subsep``,
     the function returns a dict with a list as value
     """
     block_dict = {
         "args": {
             "path": config_file,
             "format": "config",
             'ignore_pattern': ".*(worker|master).*",
             'dictsep': "=",
             'valsep': ';'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = True, {
         "APP_ATTRIBUTES":
         ["cluster_role:control", "zone:3", "provider:aws"]
     }
     assert expected_status == status
     assert expected_ret == ret['result']
Ejemplo n.º 22
0
 def test_config_EmptyValsep_ReturnDict(self, config_file):
     """
     Test that given valid arguments and an empty ``valsep``,
     the function returns an incomplete dict
     """
     block_dict = {
         "args": {
             "path": config_file,
             "format": "config",
             'pattern': ".*control.*",
             'dictsep': "=",
             'subsep': ':'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     expected_status, expected_ret = True, {
         "APP_ATTRIBUTES": {
             "cluster_role": "control;zone:3;provider:aws"
         }
     }
     assert expected_status == status
     assert expected_ret == ret['result']
Ejemplo n.º 23
0
 def test_config_InvalidDictsep_ReturnDict(self, config_file):
     """
     Test that given an invalid ``dictsep`` and valid arguments,
     the function returns a dict with values of ``None``
     """
     block_dict = {
         "args": {
             "path": config_file,
             "format": "config",
             'ignore_pattern': ".*master.*",
             'dictsep': "?",
             'valsep': ';',
             'subsep': ':'
         }
     }
     status, ret = readfile.execute("test-1", block_dict)
     sample_data = self.generate_config_data()
     expected_status, expected_ret = True, {
         x: None
         for x in sample_data if "master" not in x
     }
     assert expected_status == status
     assert expected_ret == ret['result']