Esempio n. 1
0
    def test_anidb_get_animes(self):
        # Fake an artist entry with no AniDB creator ID that will be filled by retrieving Sangatsu
        artist = Artist(name="Shinbou Akiyuki").save()

        filenames = ['anidb/sangatsu_no_lion.xml', 'anidb/sangatsu_no_lion.xml', 'anidb/hibike_euphonium.xml']
        with responses.RequestsMock(assert_all_requests_are_fired=True) as rsps:
            for filename in filenames:
                rsps.add(
                    responses.GET,
                    AniDB.BASE_URL,
                    body=self.read_fixture(filename),
                    status=200,
                    content_type='application/xml'
                )

            sangatsu = self.anidb.get_or_update_work(11606)
            tags_sangatsu_from_anidb = self.anidb.get_tags(11606)
            tags_diff_sangatsu = diff_between_anidb_and_local_tags(sangatsu, tags_sangatsu_from_anidb)
            hibike = self.anidb.get_or_update_work(10889)

        # Retrieve tags
        tags_sangatsu = set(Work.objects.get(pk=sangatsu.pk).taggedwork_set.all().values_list('tag__title', flat=True))
        tags_hibike = set(Work.objects.get(pk=hibike.pk).taggedwork_set.all().values_list('tag__title', flat=True))
        shared_tags = tags_sangatsu.intersection(tags_hibike)

        # Checks on tags
        self.assertEqual(len(tags_sangatsu), 30)
        self.assertEqual(len(tags_hibike), 38)
        self.assertEqual(len(shared_tags), 18)

        # Check for Sangatsu's informations
        self.assertEqual(sangatsu.title, 'Sangatsu no Lion')
        self.assertEqual(sangatsu.nb_episodes, 22)
        self.assertEqual(sangatsu.studio.title, 'Shaft')
        self.assertEqual(sangatsu.date, datetime(2016, 10, 8, 0, 0))
        self.assertEqual(sangatsu.end_date, datetime(2017, 3, 18, 0, 0))

        # Check for Sangatsu's staff
        staff_sangatsu = Work.objects.get(pk=sangatsu.pk).staff_set.all().values_list('artist__name', flat=True)
        self.assertCountEqual(staff_sangatsu, ['Umino Chika', 'Hashimoto Yukari', 'Shinbou Akiyuki', 'Okada Kenjirou'])

        # Check retrieved tags from AniDB
        self.assertEqual(len(tags_diff_sangatsu["deleted_tags"]), 0)
        self.assertEqual(len(tags_diff_sangatsu["added_tags"]), 0)
        self.assertEqual(len(tags_diff_sangatsu["updated_tags"]), 0)
        self.assertEqual(len(tags_diff_sangatsu["kept_tags"]), len(tags_sangatsu))

        # Check for no artist duplication
        artist = Artist.objects.filter(name="Shinbou Akiyuki")
        self.assertEqual(artist.count(), 1)
        self.assertEqual(artist.first().anidb_creator_id, 59)
Esempio n. 2
0
    def test_insert_into_database(self):
        self.add_fake_auth()
        artist = Artist(name='Ishihara Tatsuya').save()

        # Test insert AniListEntry into database
        responses.add(
            responses.GET,
            urljoin(AniList.BASE_URL, 'browse/anime'),
            body=self.read_fixture('anilist/airing_summer_2017_trimmed.json'),
            status=200,
            content_type='application/json')

        seasonal = list(
            self.anilist.list_seasonal_animes(year=2017, season='summer'))
        self.assertEqual(
            len(insert_works_into_database_from_anilist(seasonal)), 7)

        # Test insert AniListRichEntry into database
        responses.add(responses.GET,
                      urljoin(AniList.BASE_URL, 'anime/20912/page'),
                      body=self.read_fixture('anilist/hibike_euphonium.json'),
                      status=200,
                      content_type='application/json')

        hibike_entry = self.anilist.get_work_by_id(AniListWorks.animes, 20912)
        hibike = insert_work_into_database_from_anilist(hibike_entry)

        titles_hibike = WorkTitle.objects.filter(work=hibike)
        genres_hibike = hibike.genre.values_list('title', flat=True)
        related_hibike = RelatedWork.objects.filter(parent_work=hibike)
        staff_hibike = Work.objects.get(
            pk=hibike.pk).staff_set.all().values_list('artist__name',
                                                      flat=True)

        self.assertEqual(hibike.studio.title, 'Kyoto Animation')
        self.assertEqual(len(titles_hibike), 3)
        self.assertEqual(len(related_hibike), 4)
        self.assertCountEqual(genres_hibike,
                              ['Slice of Life', 'Music', 'Drama'])
        self.assertCountEqual(
            staff_hibike,
            ['Ishihara Tatsuya', 'Matsuda Akito', 'Takeda Ayano'])

        # Check for no artist duplication
        artist = Artist.objects.filter(name='Ishihara Tatsuya')
        self.assertEqual(artist.count(), 1)
        self.assertEqual(artist.first().anilist_creator_id, 100055)

        # Try adding this work to the DB again
        hibike_again = insert_work_into_database_from_anilist(hibike_entry)
        self.assertEqual(hibike, hibike_again)
Esempio n. 3
0
    def test_insert_into_database(self):
        artist = Artist(name='Ishihara Tatsuya').save()

        # Test insert AniListEntry into database
        responses.add(responses.POST,
                      self.anilist.BASE_URL,
                      body=self.read_fixture('anilist/hibike_euphonium.json'),
                      status=200,
                      content_type='application/json')

        hibike_entry = self.anilist.get_work(search_id=20912)
        hibike = insert_work_into_database_from_anilist(hibike_entry,
                                                        build_related=False)

        titles_hibike = WorkTitle.objects.filter(work=hibike).values_list(
            'title', flat=True)
        genres_hibike = hibike.genre.values_list('title', flat=True)
        related_hibike = RelatedWork.objects.filter(parent_work=hibike)
        staff_hibike = Work.objects.get(
            pk=hibike.pk).staff_set.all().values_list('artist__name',
                                                      flat=True)

        self.assertEqual(hibike.studio.title, 'Kyoto Animation')
        self.assertCountEqual(
            titles_hibike,
            ['Hibike! Euphonium', 'Sound! Euphonium', '響け!ユーフォニアム'])
        self.assertCountEqual(genres_hibike,
                              ['Slice of Life', 'Music', 'Drama'])
        self.assertCountEqual(
            staff_hibike,
            ['Ishihara Tatsuya', 'Matsuda Akito', 'Takeda Ayano'])

        # Check for no artist duplication
        artist = Artist.objects.filter(name='Ishihara Tatsuya')
        self.assertEqual(artist.count(), 1)
        self.assertEqual(artist.first().anilist_creator_id, 100055)

        # Try adding this work to the DB again
        hibike_again = insert_work_into_database_from_anilist(
            hibike_entry, build_related=False)
        self.assertEqual(hibike, hibike_again)