Exemplo n.º 1
0
    def test_empty_embed_field(self):
        """
        Empty names or values should not be carried into the embed. The pastebin has no secondary defense value
        :return:
        """
        demo_profile_link = 'https://pastebin.com/X8XNW4EU'
        demo_author = None
        xml, web_poe_token, paste_key = PoBCog._fetch_xml(
            demo_author, demo_profile_link)
        if xml and web_poe_token:
            build_embed = PoBCog._generate_embed(web_poe_token,
                                                 xml,
                                                 demo_author,
                                                 paste_key,
                                                 minify=True)

        self.assertTrue(isinstance(build_embed, Embed))
        fields = build_embed._fields
        for field in fields:
            self.assertIsNotNone(field['name'])
            self.assertIsNotNone(field['value'])

        self.assertEqual([], [
            field['name']
            for field in fields if "Secondary Defense" in field['name']
        ], "Build should not have secondary defense field in embed")
Exemplo n.º 2
0
    def test_bot_parse_routine(self):
        """
        Tests whether all links inside of the file can be successfully parsed
        """
        links = get_links()
        xml_keys = file_loader.get_pastebin_keys()

        for link in links:
            if "https://pastebin.com/" in link:
                key = link.split("/")[-1]
                if key not in xml_keys:
                    log.warning(f"Downloading xml from pastebin for key={key}")
                    PastebinHelper.fetch_pastebin(key)

        xml_file_paths = file_loader.get_pastebin_file_dir_files()
        for file_path in xml_file_paths:
            test_path = get_test_path(
                os.path.join(file_loader.pastebin_xmls_file, file_path))
            with open(test_path, "r") as f:
                demo_author = None
                log.info(f"Testing whether we can parse '{test_path}'")
                xml_tree = ET.fromstring(f.read())

                build_embed = PoBCog._generate_embed(
                    None, xml_tree, demo_author,
                    f"https://pastebin.com/{file_path.split('.xml')[0]}")
                self.assertTrue(isinstance(build_embed, Embed))
Exemplo n.º 3
0
    def test_bot_parse_routine(self):
        """
        Tests whether all links inside of the file can be successfully parsed.
        The key in the json has to either be  "level", "ascendency", "skill" or any of the categories in the bot output.
        I.e. "Offense", "Defense", ...
        """
        demo_author = None

        json = load_json_file("in/specific_builds.json")

        for build in json['builds']:
            with self.subTest(i=build['name']):
                build_embed = PoBCog._parse_pob(demo_author, build['pastebin'])
                self.assertTrue(isinstance(build_embed, Embed))
                embed_dict = build_embed.to_dict()
                print(embed_dict)
                for assertion in build['assertions']:
                    print(assertion)
                    key, value, negated = assertion.get(
                        'key',
                        ''), assertion.get('value',
                                           ''), assertion.get('not', False)

                    if key in ['level', 'lvl', 'title']:
                        assertion_succeeded = value in embed_dict.get(
                            'title', '')
                        if not negated:
                            self.assertTrue(
                                assertion_succeeded,
                                msg=
                                f"Assertion ({key}:'{value}') in embed={embed_dict} failed."
                            )
                        else:
                            self.assertFalse(
                                assertion_succeeded,
                                msg=
                                f"Assertion ({key}:'{value}') in embed={embed_dict} failed."
                            )
                    elif 'ascendancy' in key:
                        assertion_succeeded = value in embed_dict.get(
                            'title', '')
                        assertion_succeeded = assertion_succeeded or value in embed_dict.get(
                            'thumbnail', '').get('url', '')
                        self.assertTrue(
                            assertion_succeeded,
                            msg=
                            f"Assertion ({key}:'{value}') in embed={embed_dict} failed."
                        )
                    elif 'skill' in key:
                        assertion_succeeded = value in embed_dict.get(
                            'title', '')
                        self.assertTrue(
                            assertion_succeeded,
                            msg=
                            f"Assertion ({key}:'{value}') in embed={embed_dict} failed."
                        )
                    else:
                        for field in embed_dict['fields']:
                            self.single_assert(field, key, value, negated)
Exemplo n.º 4
0
 def test_bot_parse_routine(self):
     """
     Tests whether all links inside of the file can be successfully parsed
     """
     links = get_links()
     for link in links:
         with self.subTest(i=link):
             demo_author = None
             build_embed = PoBCog._parse_pob(demo_author, link)
             self.assertTrue(isinstance(build_embed, Embed))
Exemplo n.º 5
0
    def test_empty_embed_field(self):
        """
        Empty names or values should not be carried into the embed. The pastebin has no secondary defense value
        :return:
        """
        demo_profile_link = 'https://pastebin.com/X8XNW4EU'
        demo_author = None
        build_embed = PoBCog._parse_pob(demo_author, demo_profile_link)
        self.assertTrue(isinstance(build_embed, Embed))
        fields = build_embed._fields
        for field in fields:
            self.assertIsNotNone(field['name'])
            self.assertIsNotNone(field['value'])

        self.assertEqual([], [
            field['name']
            for field in fields if "Secondary Defense" in field['name']
        ], "Build should not have secondary defense field in embed")
Exemplo n.º 6
0
async def on_ready():
    bot.add_cog(PoBCog(bot, config.active_channels, config.allow_pming))
    log.info(f'Logged in: uname={bot.user.name}, id={bot.user.id}')
    if config.presence_message:
        await bot.change_presence(activity=discord.Activity(name=config.presence_message))
Exemplo n.º 7
0
 def test_illegal_url(self):
     demo_profile_link = 'https://pastebin.com/404URLNOTFOUND'
     demo_author = None
     build_embed = PoBCog._parse_pob(demo_author, demo_profile_link)
     self.assertFalse(isinstance(build_embed, Embed))