Ejemplo n.º 1
0
    def setUp(self):

        curr_dir = os.path.dirname(__file__)
        file_path = 'assets/config.yaml'
        # get the yaml file
        with open(os.path.join(curr_dir, file_path), 'r') as stream:
            try:
                self.normal_content = yaml.safe_load(stream)
            except yaml.YAMLError as err:
                Logger.error('error load yaml file ' + str(err))

        self.vault_data_key = {'db': {'password': '******'}}
        self.kv_sample = {
            'appmode': 'development',
            'db': {
                'username': '******',
                'host': 'localhost',
                'port': 1234
            },
            'elasticsearch': {
                'host': 'localhost',
                'port': 9200
            }
        }
        Outfit.setup(path='tests/assets/config.yaml')
Ejemplo n.º 2
0
    def test_setup_log_py(self):
        self.delete_all_log_files()
        Outfit.setup('./tests/assets/config-log-py.yaml')
        Logger.info('test_info')
        with open('tests/logs/info.log', 'r') as finfo:
            temp_info = finfo.readlines()
            last_line = temp_info[len(temp_info) - 1]
            self.assertTrue('test_info' in last_line)

        Logger.debug('test_debug')
        with open('tests/logs/debug.log', 'r') as fdebug:
            temp_debug = fdebug.readlines()
            last_line = temp_debug[len(temp_debug) - 1]
            self.assertTrue('test_debug' in last_line)

        Logger.error('test_error')
        with open('tests/logs/errors.log', 'r') as ferrors:
            temp_errors = ferrors.readlines()
            last_line = temp_errors[len(temp_errors) - 1]
            self.assertTrue('test_error' in last_line)

        Logger.critical('test_critical')
        with open('tests/logs/errors.log', 'r') as fcritical:
            temp_critical = fcritical.readlines()
            last_line = temp_critical[len(temp_critical) - 1]
            self.assertTrue('test_critical' in last_line)
Ejemplo n.º 3
0
    def test_setup_log_consulkv_failed(self, mock_kv):
        self.delete_all_log_files()

        from outfit.utils.io import load_yaml
        mock_kv.return_value = logging

        Outfit.setup('./tests/assets/config-log-kv.yaml')

        Logger.info('test_info')
        with open('tests/test_logs/info.log', 'r') as finfo:
            temp_info = finfo.readlines()
            print(temp_info)
            print(len(temp_info))
            last_line = temp_info[len(temp_info) - 1]
            self.assertTrue('test_info' in last_line)

        Logger.debug('test_debug')
        with open('tests/test_logs/debug.log', 'r') as fdebug:
            temp_debug = fdebug.readlines()
            last_line = temp_debug[len(temp_debug) - 1]
            self.assertTrue('test_debug' in last_line)

        Logger.error('test_error')
        with open('tests/test_logs/errors.log', 'r') as ferrors:
            temp_errors = ferrors.readlines()
            last_line = temp_errors[len(temp_errors) - 1]
            self.assertTrue('test_error' in last_line)

        Logger.critical('test_critical')
        with open('tests/test_logs/errors.log', 'r') as fcritical:
            temp_critical = fcritical.readlines()
            last_line = temp_critical[len(temp_critical) - 1]
            self.assertTrue('test_critical' in last_line)
Ejemplo n.º 4
0
def main():
    tShirt = Tops(
        "637387222", "Tretch Muscle Fit Polo",
        "A comfortable, cotton-blend polo made with stretch, featuring an icon at left chest. Designed in a muscle-defining, super slim fit through the chest, waist and arms. Muscle Fit. Imported",
        "White", "Flat", "Cotton", "Male", "Hollister", "Classic", "N/A")
    short = Bottons("001987623", "Minimal pink short",
                    "Minimalistic and moder short great for the summer",
                    "Pink", "Flat", "Cotton", "Male", "Hollister", "Modern",
                    "N/A")
    toms = Shoewear("908876789", "Ericsons",
                    "Gret comfort toms ideal for hot climates", "White",
                    "Flat", "Polyester", "Unisex", "Toms", "Modern", "N/A")

    acc = Accessories("099897789", "Leo Dimond ring",
                      "2k white gold luxury ring", "Silver", "N/A", "N/A",
                      "Male", "Leo Dimond", "Classic", "N/A")

    suit = Fullbody("N/A", "N/A", "N/A", "N/a", "N/A", "N/A", "N/A", "N/A",
                    "N/A", "N/A")

    firstOutfit = Outfit(tShirt, short, toms, acc, suit)

    def getItemInList():
        topDict = {}
        topDict["Product Number"] = tShirt.getProductNumber()
        topDict["Product Name"] = tShirt.getProductName()
        topDict["Product Description"] = tShirt.getProductDescription()
        topDict["Color"] = tShirt.getColor()
        topDict["Texture"] = tShirt.getTexture()
        topDict["Material"] = tShirt.getMaterial()
        topDict["Sex"] = tShirt.getSex()
        topDict["Brand"] = tShirt.getBrand()
        topDict["Style"] = tShirt.getStyle()
        topDict["Pattern"] = tShirt.getPattern()

        bottomDict = {}
        bottomDict["Product Number"] = short.getProductNumber()
        bottomDict["Product Name"] = short.getProductName()
        bottomDict["Product Description"] = short.getProductDescription()
        bottomDict["Color"] = short.getColor()
        bottomDict["Texture"] = short.getTexture()
        bottomDict["Material"] = short.getMaterial()
        bottomDict["Sex"] = short.getSex()
        bottomDict["Brand"] = short.getBrand()
        bottomDict["Style"] = short.getStyle()
        bottomDict["Pattern"] = short.getPattern()

        print(topDict)
        print(bottomDict)

    getItemInList()
    print(firstOutfit.getTop())
    print(firstOutfit.getBottom())
    print(firstOutfit.getShoeware())
    print(firstOutfit.getFullbody())
    print(firstOutfit.getAccesory())

    print(firstOutfit.getOutfit())
Ejemplo n.º 5
0
    def test_setup_log_consulkv(self, mock_kv):
        self.delete_all_log_files()

        from outfit.utils.io import load_yaml
        mock_kv.return_value = logging

        #result = convert_yaml(self.normal_content)

        Outfit.setup('./tests/assets/config-log-kv.yaml')

        m = minfo = mock_open(
            read_data='INFO:test_utilslogger.py(50)> test_info')
        mdebug = mock_open(
            read_data='ERROR:test_utilslogger.py(62)> test_debug')
        merror = mock_open(
            read_data='ERROR:test_utilslogger.py(62)> test_error')
        mcritical = mock_open(
            read_data='ERROR:test_utilslogger.py(62)> test_critical')
        m.side_effect = [
            minfo.return_value, mdebug.return_value, merror.return_value,
            mcritical.return_value
        ]

        with patch('builtins.open', m):

            Logger.info('test_info')
            with open('tests/test_logs/info.log', 'r') as finfo:
                temp_info = finfo.read()
                last_line = temp_info[len(temp_info) - 1]
                self.assertTrue('test_info' in temp_info)

            Logger.debug('test_debug')
            with open('tests/test_logs/debug.log', 'r') as fdebug:
                temp_debug = fdebug.readlines()
                last_line = temp_debug[len(temp_debug) - 1]
                self.assertTrue('test_debug' in last_line)

            Logger.error('test_error')
            with open('tests/test_logs/errors.log', 'r') as ferrors:
                temp_errors = ferrors.readlines()
                last_line = temp_errors[len(temp_errors) - 1]
                self.assertTrue('test_error' in last_line)

            Logger.critical('test_critical')
            with open('tests/test_logs/errors.log', 'r') as fcritical:
                temp_critical = fcritical.readlines()
                last_line = temp_critical[len(temp_critical) - 1]
                self.assertTrue('test_critical' in last_line)
Ejemplo n.º 6
0
    def setUp(self):

        curr_dir = os.path.dirname(__file__)
        file_path = 'assets/config.yaml'
        # get the yaml file
        with open(os.path.join(curr_dir, file_path), 'r') as stream:
            try:
                self.normal_content = yaml.safe_load(stream)
            except yaml.YAMLError as err:
                Logger.error('error load yaml file ' + str(err))

        self.vault_data_key = {'db': {'password': '******'}}
        self.kv_sample = {
            'appmode': 'development',
            'db': {
                'username': '******',
                'host': 'localhost',
                'port': 1234
            },
            'elasticsearch': {
                'host': 'localhost',
                'port': 9200
            }
        }
        Outfit.setup(path='tests/assets/config.yaml')
        os.environ['host_vault'] = 'localhost'
        os.environ['port_vault'] = '12345'
        os.environ['scheme_vault'] = 'http'
        os.environ['token_vault'] = 'qwerty123'
        os.environ['path_vault'] = 'application'

        os.environ['host_consul'] = 'localhost'
        os.environ['port_consul'] = '12345'
        os.environ['scheme_consul'] = 'http'
        os.environ['token_consul'] = 'qwerty123'
        os.environ['path_consul'] = 'application'

        os.environ['LOG_MODE'] = 'development'
        os.environ['LOG_LOCATION'] = './tests/assets/logging.yaml'
        os.environ['LOG_TYPE'] = 'yaml_file'
        os.environ['DEFAULT_TYPE'] = 'yaml_file'
        os.environ['DEFAULT_LOCATION'] = './tests/assets/logging.yaml'
Ejemplo n.º 7
0
Archivo: bot.py Proyecto: Mikeyspud/bot
    def __init__(self, outfit_name: str, guild_id: int, member_role_id: int, *args, **kwargs):

        super().__init__(*args, **kwargs)
        self.guild_id = guild_id
        self.member_role_id = member_role_id
        self.outfit = Outfit(name=outfit_name)
        self.database = Database(tag=self.outfit.alias)()
        self.Member = Member(database=self.database.members)
        self.Ops = Ops
        self.ops_list = dict()
        self.add_commands()
Ejemplo n.º 8
0
    def test_env_var(self, mock_consul_kv, mock_vault_kv):
        mock_consul_kv.return_value = [
            None, {
                'Value': json.dumps(self.kv_sample).encode()
            }
        ]
        mock_vault_kv.return_value = {'data': secret_kv}

        Outfit.setup('tests/assets/config-env.yaml')
        vault = VaultCon()
        consul = ConsulCon()

        result_vault = vault.get_secret_kv()
        result_consul = consul.get_kv()

        result = merge_dict(result_vault, result_consul)

        self.assertEqual(result['big_query']['client_id'], '1234567',
                         ' client id from vault not match')
        self.assertEqual(result['appmode'], 'development',
                         ' appmode from consul not match')