def person_wrong_name( self ): self.initialize() person = Person() person.name = "Ela" person.surname = "Gabor" person.permalink = "ela-gabor" person.imdb_code = "3140529" person.verified_imdb_code = True person.type = Person.TYPE_PERSON person.save() fti1 = FilmToImport( user = self.user, title = '180/100', imdb_url = 'http://www.imdb.com/title/tt2089598/', imdb_id = '2089598', status = FilmToImport.ACCEPTED ) fti1.save() run( False, False, False, False, False, True, "http" ) self.assertEqual( Person.objects.filter( imdb_code__isnull=True ).count(), 0 ) person = Person.objects.get( imdb_code="3140529" ) self.assertEqual( person.name, "Ela" ) self.assertEqual( person.surname, "Gabor" ) self.assertEqual( person.permalink, "ela-gabor" ) self.assertEqual( person.import_comment, "imdb name: Éva Gábor" )
def person_short_imdb_code( self ): self.initialize() person = Person() person.name = "Harrison" person.surname = "Ford" person.permalink = "harrison-ford" person.imdb_code = "148" person.type = Person.TYPE_PERSON person.save() person = Person() person.name = "Harrison" person.surname = "Ford (II)" person.permalink = "harrison-ford-ii" person.imdb_code = "0001230" person.type = Person.TYPE_PERSON person.save() self.assertEqual( Person.objects.filter( imdb_code='148' ).count(), 1 ) fti1 = FilmToImport( user = self.user, title = 'Love in High Gear', imdb_url = 'http://www.imdb.com/title/tt0022093/', imdb_id = '0022093', status = FilmToImport.ACCEPTED ) fti1.save() fti2 = FilmToImport( user = self.user, title = 'Journey to shiloh', imdb_url = 'http://www.imdb.com/title/tt0063161/', imdb_id = '0063161', status = FilmToImport.ACCEPTED ) fti2.save() fti3 = FilmToImport( user = self.user, title = 'Guys choice Awards 2011', imdb_url = 'http://www.imdb.com/title/tt2023505/', imdb_id = '2023505', status = FilmToImport.ACCEPTED ) fti3.save() run( False, False, False, False, False, True, "http" ) self.assertEqual( Person.objects.filter( name='Harrison', surname__contains='Ford' ).count(), 2 ) self.assertEqual( Person.objects.filter( imdb_code='148' ).count(), 0 ) self.assertEqual( Person.objects.get( imdb_code='0000148' ).permalink, 'harrison-ford' )
def duplicate_imdb_code(self): """ ImdbFetcher is trying to save person with imdb_code, already existing in db """ self.initialize() self.client.login(username=self.user.username, password='******') per = Person() per.name = "Jan" per.surname = "Kowalski" # Schwarzeneger's imdb code per.imdb_code = "0000216" per.type = Person.TYPE_PERSON per.save() per = Person.objects.get(imdb_code="0000216") self.assertEqual(per.name, "Jan") self.assertEqual(per.imdb_code, "0000216") film_to_import = FilmToImport(user = self.user, title = 'Terminator', imdb_url = 'http://www.imdb.com/title/tt0088247/', imdb_id='0088247', status=FilmToImport.ACCEPTED) film_to_import.save() run(False, False, False, False, False, True, "http") person = Person.objects.get(imdb_code="0000216") # duplicate imdb_code - should be set to Schwarzenegger self.assertEqual(person.name, "Arnold") self.assertEqual(person.surname, "Schwarzenegger") self.assertEqual(person.verified_imdb_code, True) self.assertEqual(person.imdb_code, "0000216") # old imdb_code should be set to None per = Person.objects.get(name="Jan", surname="Kowalski") self.assertEqual(per.imdb_code, None)
def unique_imdb_code(self): """ There is a person in db but, he has different imdb_code """ self.initialize() self.client.login(username=self.user.username, password='******') per = Person() per.name = "Jan" per.surname = "Kowalski" # Schwarzeneger's imdb code per.imdb_code = "0101010101010101" per.type = Person.TYPE_PERSON per.save() per = Person.objects.get(imdb_code="0101010101010101") self.assertEqual(per.name, "Jan") self.assertEqual(per.imdb_code, "0101010101010101") film_to_import = FilmToImport(user = self.user, title = 'Terminator', imdb_url = 'http://www.imdb.com/title/tt0088247/', imdb_id='0088247', status=FilmToImport.ACCEPTED) film_to_import.save() run(False, False, False, False, False, True, "http") person = Person.objects.get(imdb_code="0000216") self.assertEqual(person.name, "Arnold") self.assertEqual(person.surname, "Schwarzenegger") self.assertEqual(person.verified_imdb_code, True) self.assertEqual(person.imdb_code, "0000216") # old imdb_code should be set to None per = Person.objects.get(name="Jan", surname="Kowalski") self.assertEqual(per.imdb_code, "0101010101010101")
def initialize(self): self.clean_data() # set up users self.u1 = User.objects.create_user('michuk', '*****@*****.**', 'secret') self.u1.save() self.u2 = User(username='******', email='*****@*****.**') self.u2.save() self.u3 = User(username='******', email='*****@*****.**') self.u3.save() self.u4 = User(username='******', email='*****@*****.**') self.u4.save() self.contest = Contest() self.contest.name = "Plebiscyt" self.contest.start_date = datetime.now() self.contest.end_date = datetime.now() self.contest.event_status = Contest.STATUS_OPEN self.contest.type = Object.TYPE_CONTEST self.contest.permalink = "plebiscyt" self.contest.save() film1 = Film() film1.title = "Battlefield Earth II" film1.type = Object.TYPE_FILM film1.permalink = "/battlefirld-earth-ii/" film1.release_year = 2010 film1.save() person1 = Person() person1.name = "John" person1.surname = "Travolta" person1.type = Object.TYPE_PERSON person1.permalink = "/john-travolta/" person1.save() person2 = Person() person2.name = "Tom" person2.surname = "Cruise" person2.type = Object.TYPE_PERSON person2.permalink = "/tom-cruise/" person2.save() person3 = Person() person3.name = "Forrest" person3.surname = "Whitaker" person3.type = Object.TYPE_PERSON person3.permalink = "/forrest-whitaker/" person3.save() character1 = Character() character1.character = "Scientologist 1" character1.person = person1 character1.film = film1 character1.save() self.character1 = character1 character2 = Character() character2.character = "Scientologist 2" character2.person = person2 character2.film = film1 character2.save() self.character2 = character2 character3 = Character() character3.character = "A non-scientologist" character3.person = person3 character3.film = film1 character3.save() self.character3 = character3 today = datetime.today() tomorrow = today + timedelta(1) self.game1 = Game() self.game1.contest = self.contest self.game1.type = Object.TYPE_GAME self.game1.permalink = "scientologist-1-vs-scientologist-2" self.game1.level = Game.LEVEL_32 self.game1.character1 = character1 self.game1.character2 = character2 self.game1.start_date = today self.game1.end_date = today self.game1.save() self.game2 = Game() self.game2.contest = self.contest self.game2.type = Object.TYPE_GAME self.game1.permalink = "scientologist-1-vs-scientologist-2" self.game2.level = Game.LEVEL_32 self.game2.character1 = character1 self.game2.character2 = character2 self.game2.start_date = tomorrow self.game2.end_date = tomorrow self.game2.save()
def initialize(self): self.clean_data() # set up users self.u1= User.objects.create_user('michuk', '*****@*****.**', 'secret') self.u1.save() self.u2 = User(username='******', email='*****@*****.**') self.u2.save() self.u3 = User(username='******', email='*****@*****.**') self.u3.save() self.u4 = User(username='******', email='*****@*****.**') self.u4.save() self.contest = Contest() self.contest.name = "Plebiscyt" self.contest.start_date = datetime.now() self.contest.end_date = datetime.now() self.contest.event_status = Contest.STATUS_OPEN self.contest.type = Object.TYPE_CONTEST self.contest.permalink = "plebiscyt" self.contest.save() film1 = Film() film1.title = "Battlefield Earth II" film1.type = Object.TYPE_FILM film1.permalink = "/battlefirld-earth-ii/" film1.release_year = 2010 film1.save() person1 = Person() person1.name = "John" person1.surname = "Travolta" person1.type = Object.TYPE_PERSON person1.permalink = "/john-travolta/" person1.save() person2 = Person() person2.name = "Tom" person2.surname = "Cruise" person2.type = Object.TYPE_PERSON person2.permalink = "/tom-cruise/" person2.save() person3 = Person() person3.name = "Forrest" person3.surname = "Whitaker" person3.type = Object.TYPE_PERSON person3.permalink = "/forrest-whitaker/" person3.save() character1 = Character() character1.character = "Scientologist 1" character1.person = person1 character1.film = film1 character1.save() self.character1 = character1 character2 = Character() character2.character = "Scientologist 2" character2.person = person2 character2.film = film1 character2.save() self.character2 = character2 character3 = Character() character3.character = "A non-scientologist" character3.person = person3 character3.film = film1 character3.save() self.character3 = character3 today = datetime.today() tomorrow = today + timedelta(1) self.game1 = Game() self.game1.contest = self.contest self.game1.type = Object.TYPE_GAME self.game1.permalink = "scientologist-1-vs-scientologist-2" self.game1.level = Game.LEVEL_32 self.game1.character1 = character1 self.game1.character2 = character2 self.game1.start_date = today self.game1.end_date = today self.game1.save() self.game2 = Game() self.game2.contest = self.contest self.game2.type = Object.TYPE_GAME self.game1.permalink = "scientologist-1-vs-scientologist-2" self.game2.level = Game.LEVEL_32 self.game2.character1 = character1 self.game2.character2 = character2 self.game2.start_date = tomorrow self.game2.end_date = tomorrow self.game2.save()
def test_persons( self ): fti1 = FilmToImport( user=self.user, title='Nybyggarna', imdb_url='http://www.imdb.com/title/tt0069035/', imdb_id='0069035', status=FilmToImport.ACCEPTED ) fti1.save() fti2 = FilmToImport( user=self.user, title='Utvandrarna', imdb_url='http://www.imdb.com/title/tt0067919/', imdb_id='0067919', status=FilmToImport.ACCEPTED ) fti2.save() fti3 = FilmToImport( user=self.user, title='Sandade Sandadi', imdb_url='http://www.imdb.com/title/tt0338408/', imdb_id='0338408', status=FilmToImport.ACCEPTED ) fti3.save() fti4 = FilmToImport( user = self.user, title = 'Journey to shiloh', imdb_url = 'http://www.imdb.com/title/tt0063161/', imdb_id = '0063161', status = FilmToImport.ACCEPTED ) fti4.save() fti5 = FilmToImport( user = self.user, title = 'Guys choice Awards 2011', imdb_url = 'http://www.imdb.com/title/tt2023505/', imdb_id = '2023505', status = FilmToImport.ACCEPTED ) fti5.save() self.assertTrue( compare( "Penélope Cruz", "Penélope Cruz", 2 ) ) fti6 = FilmToImport( user=self.user, title='Volver', imdb_url='http://www.imdb.com/title/tt0441909/', imdb_id='0441909', status=FilmToImport.ACCEPTED ) fti6.save() fti7 = FilmToImport( user=self.user, title='Gothika', imdb_url='http://www.imdb.com/title/tt0348836/', imdb_id='0348836', status=FilmToImport.ACCEPTED ) fti7.save() run( False, False, False, False, False, True, "http" ) self.assertEqual( Film.objects.count(), 7 ) self.assertEqual( Person.objects.filter( name='Harrison', surname='Ford', imdb_code='0000148', verified_imdb_code=True ).count(), 1 ) self.assertEqual( Person.objects.filter( name='Yvonne', surname='Oppstedt', imdb_code='0649235', verified_imdb_code=True ).count(), 1 ) self.assertEqual( Person.objects.filter( name='Sonali', surname='Joshi', imdb_code='1359890', verified_imdb_code=True ).count(), 1 ) self.assertEqual( Film.objects.filter( character__person__imdb_code='0649235' ).distinct().count(), 2 ) self.assertEqual( Film.objects.filter( character__person__imdb_code='1359890' ).distinct().count(), 1 ) # 1. two persons merged f1 = Film.objects.get( imdb_code='0338408' ) yvonne = Person.objects.get( imdb_code='0649235' ) sonali = Person.objects.get( imdb_code='1359890' ) for ch in Character.objects.filter( person=sonali, film=f1 ): ch.person = yvonne ch.save() self.assertEqual( Film.objects.filter( character__person=yvonne ).distinct().count(), 3 ) self.assertEqual( Film.objects.filter( character__person=sonali ).distinct().count(), 0 ) sonali.delete() yvonne.imdb_code = '1359890' yvonne.verified_imdb_code = False yvonne.import_comment = 'imdb name: Sonali Joshi' yvonne.save() # 2. one person with two movies f2 = Film.objects.get( imdb_code='2023505' ) harrison = Person.objects.get( imdb_code='0000148' ) bad_harrison = Person() bad_harrison.name = "Harrison" bad_harrison.surname = "Ford" bad_harrison.permalink = "harrison-ford-1" bad_harrison.type = Person.TYPE_PERSON bad_harrison.save() for ch in Character.objects.filter( person=harrison, film=f2 ): ch.person = bad_harrison ch.save() harrison.verified_imdb_code = False harrison.imdb_code = '111111' harrison.save() bad_harrison.verified_imdb_code = True bad_harrison.imdb_code = '0000148' bad_harrison.save() self.assertEqual( Film.objects.filter( character__person=harrison ).distinct().count(), 1 ) self.assertEqual( Film.objects.filter( character__person=bad_harrison ).distinct().count(), 1 ) self.assertEqual( Person.objects.filter( verified_imdb_code=False ).count(), 2 ) # 3. short imdb code duplicated self.assertEqual( Person.objects.filter( imdb_code='0880521', name='Liv', surname='Ullmann' ).count(), 1 ) liv = Person.objects.get( imdb_code='0880521' ) liv.permalink = 'liv-ullmann-1' liv.save() short_liv = Person() short_liv.imdb_code = '880521' short_liv.name = 'Liv' short_liv.surname = 'Ullmann' short_liv.permalink = 'liv-ullmann' short_liv.type = Person.TYPE_PERSON short_liv.save() # 4. not verified imdb_code self.assertEqual( Person.objects.filter( imdb_code='0005493', name='Justin', surname='Timberlake', verified_imdb_code=True ).count(), 1 ) justin = Person.objects.get( imdb_code='0005493' ) justin.verified_imdb_code = False justin.imdb_code = None justin.save() self.assertEqual( Person.objects.filter( imdb_code='0873296', name='Jan', surname='Troell', verified_imdb_code=True ).count(), 1 ) jan = Person.objects.get( imdb_code='0873296' ) jan.verified_imdb_code = False jan.save() # 5. html entities in name self.assertEqual( Person.objects.filter( name='Penélope', surname='Cruz', imdb_code='0004851', verified_imdb_code=True ).count(), 1 ) penelope = Person.objects.get( imdb_code='0004851' ) gothika = Film.objects.get( imdb_code='0348836' ) penelope.verified_imdb_code = False penelope.imdb_code = '4851' penelope.save() bad_penelope = Person() bad_penelope.name = "Penélope" bad_penelope.surname = "Cruz" bad_penelope.imdb_code = '0004851' bad_penelope.permalink = "penxe9lope-cruz" bad_penelope.type = Person.TYPE_PERSON bad_penelope.save() for ch in Character.objects.filter( person=penelope, film=gothika ): ch.person = bad_penelope ch.save() call_command( 'fix_imported_persons' ) #for p in Person.objects.all(): # print p.verified_imdb_code, p, p.imdb_code, p.import_comment self.assertEqual( Person.objects.filter( verified_imdb_code=False ).count(), 1 ) self.assertEqual( Film.objects.filter( character__person=harrison ).distinct().count(), 2 ) self.assertEqual( Person.objects.get( pk=yvonne.pk ).import_comment, 'imdb name: Sonali Joshi, not matched movies: 0338408' ) self.assertEqual( Person.objects.filter( imdb_code='880521' ).count(), 0 ) self.assertEqual( Person.objects.filter( imdb_code='0880521', name='Liv', surname='Ullmann' ).count(), 1 ) justin = Person.objects.get( pk=justin.pk ) self.assertEqual( justin.imdb_code, '0005493' ) self.assertTrue( justin.verified_imdb_code ) jan = Person.objects.get( pk=jan.pk ) self.assertEqual( jan.imdb_code, '0873296' ) self.assertTrue( jan.verified_imdb_code ) self.assertEqual( Person.objects.filter( name='Penélope', surname='Cruz', imdb_code='0004851', verified_imdb_code=True ).count(), 1 ) acted = Film.objects.filter( character__person=penelope ).distinct() self.assertTrue( len( acted ), 2 )