예제 #1
0
class CritickerImportTestCase(ImportTestCase):

    path = os.path.dirname('')
    vote_history = os.path.abspath('import_ratings/test/test_criticker_rankings.xml')
    def setUp(self):
        Film.objects.filter(imdb_code__lt=1000).delete()

        f1 = Film(type=1, permalink='the-alien', imdb_code=111, status=1, version=1,
            release_year=1979, title='The Alien', popularity=1, popularity_month=1)
        f1.save()
        f2 = Film(type=1, permalink='the-shawshank-redemption', imdb_code=112, status=1, version=1,
        release_year=1994, title='The Shawshank Redemption', popularity=1, popularity_month=1)
        f2.save()
        f3 = Film(type=1, permalink='terminator-2-judgment-day', imdb_code=113, status=1, version=1,
        release_year=1991, title='Terminator 2: Judgment Day', popularity=1, popularity_month=1)
        f3.save()
        f4 = Film(type=1, permalink='american-history-x', imdb_code=114, status=1, version=1,
            release_year=1998, title='American History X', popularity=1, popularity_month=1)
        f4.save()
        f5 = Film(type=1, permalink='the-big-lebowski', imdb_code=115, status=1, version=1,
            release_year=1998, title='The Big Lebowski', popularity=1, popularity_month=1)
        f5.save()
        f6 = Film(type=1, permalink='the-goonies', imdb_code=116, status=1, version=1,
            release_year=1985, title='The Goonies', popularity=1, popularity_month=1)
        f6.save()
        f7 = Film(type=1, permalink='the-lord-of-the-rings-the-fellowship-of-the-ring', imdb_code=117, status=1, version=1,
            release_year=2001, title='The Lord of the Rings: Fellowship of the Ring', popularity=1, popularity_month=1)
        f7.save()

        self.u1=User(username="******", email="*****@*****.**")
        self.u1.save()

    def test_import(self):
        """
            Import a sample voting history from Criticker XML file
        """

        ratings_list = parse_criticker_votes(self.vote_history)
        self.assertEquals(len(ratings_list),10)

        save_ratings_db(self.u1, ratings_list, ImportRatings.CRITICKER, overwrite=True)

        all_ratings = ImportRatings.objects.all()
        self.assertEquals(len(all_ratings), 1)

        """
            Gets the import records stored in ImportRatings table and
            imports them into single Rating records
        """

        import_ratings()

        ratingsLogs = ImportRatingsLog.objects.all()
        self.assertEquals(len(ratingsLogs), 1)

        ratings = Rating.objects.all()
        self.assertEquals(len(ratings), 10)
예제 #2
0
class IMDBImportTestCase(ImportTestCase):
    def setUp(self):
        """
        setup user
        """
        self.u1 = User(username='******', email='*****@*****.**')
        self.u1.save()

        Film.objects.filter(imdb_code__lt=1000).delete()

        f1 = Film(type=1, permalink='we-live-in-public', imdb_code=111, status=1, version=1,
            release_year=2009, title='We live in public', popularity=1, popularity_month=1)
        f1.save()
        # wrong year, should NOT match, only matches when year exact or different by 1
        f2 = Film(type=1, permalink='krotki-film-o-zabijaniu', imdb_code=112, status=1, version=1,
        release_year=1980, title='Krotki film o zabijaniu', popularity=1, popularity_month=1)
        f2.save()
        f3 = Film(type=1, permalink='xiao-cai-feng', imdb_code=113, status=1, version=1,
        release_year=2002, title='Xiao cai feng', popularity=1, popularity_month=1)
        f3.save()
        films = Film.objects.all()
        print "films in database: " + str(len(films))

    def test_import(self):
        """
            Import a sample voting history from Filmweb
        """                

        #setup path to local file with ratings
        f = open('import_ratings/test/test_imdb_ratings.csv', 'rb')
        ratings_list = parse_imdb_votes(f)

        print "parsed ratings_list length=" + str(len(ratings_list))
        self.assertEquals(len(ratings_list), 5)

        save_ratings_db(self.u1, ratings_list, ImportRatings.IMDB, overwrite=True)

        all_ratings = ImportRatings.objects.all()
        self.assertEquals(len(all_ratings), 1)

        """
            Gets the import records stored in ImportRatings table and
            imports them into single Rating records
        """

        import_ratings()

        ratingsLogs = ImportRatingsLog.objects.all()
        self.assertEquals(len(ratingsLogs), 1)
        print ratingsLogs[0]

        films = Film.objects.all()
        print "films in database: " + str(len(films))

        ratings = Rating.objects.all()
        print "imported ratings = " + str(len(ratings))
        self.assertEquals(len(ratings), 5)
예제 #3
0
    def setUp(self):
        Film.objects.filter(imdb_code__lt=1000).delete()

        f1 = Film(type=1, permalink='the-alien', imdb_code=111, status=1, version=1,
            release_year=1979, title='The Alien', popularity=1, popularity_month=1)
        f1.save()
        f2 = Film(type=1, permalink='the-shawshank-redemption', imdb_code=112, status=1, version=1,
        release_year=1994, title='The Shawshank Redemption', popularity=1, popularity_month=1)
        f2.save()
        f3 = Film(type=1, permalink='terminator-2-judgment-day', imdb_code=113, status=1, version=1,
        release_year=1991, title='Terminator 2: Judgment Day', popularity=1, popularity_month=1)
        f3.save()
        f4 = Film(type=1, permalink='american-history-x', imdb_code=114, status=1, version=1,
            release_year=1998, title='American History X', popularity=1, popularity_month=1)
        f4.save()
        f5 = Film(type=1, permalink='the-big-lebowski', imdb_code=115, status=1, version=1,
            release_year=1998, title='The Big Lebowski', popularity=1, popularity_month=1)
        f5.save()
        f6 = Film(type=1, permalink='the-goonies', imdb_code=116, status=1, version=1,
            release_year=1985, title='The Goonies', popularity=1, popularity_month=1)
        f6.save()
        f7 = Film(type=1, permalink='the-lord-of-the-rings-the-fellowship-of-the-ring', imdb_code=117, status=1, version=1,
            release_year=2001, title='The Lord of the Rings: Fellowship of the Ring', popularity=1, popularity_month=1)
        f7.save()

        self.u1=User(username="******", email="*****@*****.**")
        self.u1.save()
예제 #4
0
    def setUp(self):
        """
        setup user
        """
        self.u1 = User(username='******', email='*****@*****.**')
        self.u1.save()

        Film.objects.filter(imdb_code__lt=1000).delete()

        f1 = Film(type=1, permalink='we-live-in-public', imdb_code=111, status=1, version=1,
            release_year=2009, title='We live in public', popularity=1, popularity_month=1)
        f1.save()
        # wrong year, should NOT match, only matches when year exact or different by 1
        f2 = Film(type=1, permalink='krotki-film-o-zabijaniu', imdb_code=112, status=1, version=1,
        release_year=1980, title='Krotki film o zabijaniu', popularity=1, popularity_month=1)
        f2.save()
        f3 = Film(type=1, permalink='xiao-cai-feng', imdb_code=113, status=1, version=1,
        release_year=2002, title='Xiao cai feng', popularity=1, popularity_month=1)
        f3.save()
        films = Film.objects.all()
        print "films in database: " + str(len(films))