def test_missing_medals_stop_being_missing_when_we_create_them(
            self, mock_get_medal_names):
        medal_names = ['hd invi [ex]', 'axel b', 'illustrated halloween goofy']
        mock_get_medal_names.return_value = medal_names

        number_of_missing_medals = len(self.scrapper.missing_medals())
        invi_data_filename = 'test/fixtures/scrapper/medal_with_symbol_in_name_3.json'
        with open(invi_data_filename) as invi_data_file:
            invi_data = json.loads(invi_data_file.read())['medal']['0']
            MedalFactory.medal(invi_data)

        self.assertEqual(len(self.scrapper.missing_medals()),
                         number_of_missing_medals - 1)
예제 #2
0
    def test_medal_is_not_created_if_multiplier_is_None(self):
        combat_medal_json_faulty = self.combat_medal_json.copy()
        combat_medal_json_faulty['multiplier'] = None

        created_medal = MedalFactory.medal(combat_medal_json_faulty)

        self.assertIsNone(created_medal)
예제 #3
0
    def setUp(self):
        Medal.bind(test_db, bind_refs=False, bind_backrefs=False)

        test_db.connect()
        test_db.create_tables([Medal])

        with open('test/fixtures/models/combat_medal_data.json') as fixture:
            combat_medal_json = json.loads(fixture.read())
            self.combat_medal = MedalFactory.medal(combat_medal_json)

        with open(
                'test/fixtures/models/combat_medal_with_ranged_multiplier_data.json'
        ) as fixture:
            combat_medal_ranged_multiplier_json = json.loads(fixture.read())
            self.combat_medal_ranged_multiplier = MedalFactory.medal(
                combat_medal_ranged_multiplier_json)
예제 #4
0
    def test_parses_multiplier_correctly_if_doesnt_start_with_x(self):
        combat_medal_json_without_x = self.combat_medal_json.copy()
        combat_medal_json_without_x['multiplier'] = "3.29-7.12"

        created_medal = MedalFactory.medal(combat_medal_json_without_x)

        self.assertEqual(created_medal.multiplier_min, 3.29)
        self.assertEqual(created_medal.multiplier_max, 7.12)
예제 #5
0
    def setUp(self):
        super(TestMedalFactory, self).setUp()

        with open('test/fixtures/models/combat_medal_data.json') as fixture:
            self.combat_medal_json = json.loads(fixture.read())

        with open(
                'test/fixtures/models/combat_medal_with_ranged_multiplier_data.json'
        ) as fixture:
            self.combat_medal_ranged_multiplier_json = json.loads(
                fixture.read())

        with open(
                'test/fixtures/models/non_combat_medal_data.json') as fixture:
            self.non_combat_medal_json = json.loads(fixture.read())

        self.combat_medal = MedalFactory.medal(self.combat_medal_json)
        self.combat_medal_ranged_multiplier = MedalFactory.medal(
            self.combat_medal_ranged_multiplier_json)
예제 #6
0
    def test_medal_is_created_correctly_if_multiplier_has_curved_separator(
            self):

        combat_medal_json_curved = self.combat_medal_json.copy()
        combat_medal_json_curved['multiplier'] = "x3.29~7.12"

        created_medal = MedalFactory.medal(combat_medal_json_curved)

        self.assertEqual(created_medal.multiplier_min, 3.29)
        self.assertEqual(created_medal.multiplier_max, 7.12)
예제 #7
0
    def test_creates_medal_if_any_other_field_is_missing(self):
        combat_medal_json_faulty = self.combat_medal_json.copy()
        combat_medal_json_faulty.pop('defence')
        combat_medal_json_faulty.pop('image_link')
        combat_medal_json_faulty.pop('notes')
        combat_medal_json_faulty.pop('pullable')
        combat_medal_json_faulty.pop('region')
        combat_medal_json_faulty.pop('strength')
        combat_medal_json_faulty.pop('voice_link')

        created_medal = MedalFactory.medal(combat_medal_json_faulty)
        self.assertIsInstance(created_medal, Medal)
예제 #8
0
    def scrape_missing_medals(self):
        """Saves in the DB the medals that aren't there yet"""
        missing_medals_names = self.missing_medals()
        print(f'Missing medals:\n {missing_medals_names}')

        for medal_name in missing_medals_names:
            matching_medals = self.get_medals(medal_name)
            print(f"Current medal: {medal_name}")

            for medal in matching_medals:
                if not Medal.get_or_none(Medal.medal_id == medal['id']):
                    created_medal = MedalFactory.medal(medal)

                    if created_medal:
                        print(
                            f"{created_medal.name} - {created_medal.rarity}* was correctly created"
                        )
                    else:
                        print(
                            f"Couldn't create medal {medal['name']} - {medal['rarity']}*"
                        )
예제 #9
0
 def test_doesnt_create_medal_if_type_is_not_combat(self):
     self.assertIsNone(MedalFactory.medal(self.non_combat_medal_json))
예제 #10
0
    def test_doesnt_create_medal_if_type_is_missing(self):
        combat_medal_json_faulty = self.combat_medal_json.copy()
        combat_medal_json_faulty.pop('type')

        created_medal = MedalFactory.medal(combat_medal_json_faulty)
        self.assertIsNone(created_medal)
예제 #11
0
 def test_doesnt_create_medal_if_the_json_contains_an_error(self):
     json_with_error = {"error": "Error message to use in this test"}
     self.assertIsNone(MedalFactory.medal(json_with_error))