def test_post_2(self): """ create a movie with actors""" payload = { 'title': 'pirates of the caribbean', 'genre': 'action', 'actors': ['Johnny Depp', 'Orlando Bloom'] } res = self.post_json('http://localhost:5555/movie/', payload) self.assertEqual(res.status_code, 200) self.assertEqual(res.json.get('genre'), 'action') self.assertEqual(res.json.get('title'), 'pirates of the caribbean') movie_uuid = res.json.get('uuid') # fetch from db: m = Movie.get(Movie.uuid == movie_uuid) self.assertEqual(m.title, 'pirates of the caribbean') self.assertEqual(m.genre, 'action') # implicitly the actors should be created: actors = Actor.select() self.assertEqual(len(actors), 2) johnny = Actor.get(name='Johnny Depp') orlando = Actor.get(name='Orlando Bloom') # there should also be two records for MovieActor: all_movie_actors = MovieActor.select() self.assertEqual(len(all_movie_actors), 2) MovieActor.get((MovieActor.movie == m) & (MovieActor.actor == johnny)) MovieActor.get((MovieActor.movie == m) & (MovieActor.actor == orlando))
def test_get_5(self): """test GET movies filtered by actor AND genre""" alice_in_wonderland = Movie.get_or_create(title='alice in wonderland', genre='mystery') # this one has the actor we want minions = Movie.get_or_create(title='minions', genre='comedy') mission_impossible = Movie.get_or_create(title='Mission Impossible', genre='action') bob = Actor.get_or_create(name='Bob') alice = Actor.get_or_create(name='Alice') MovieActor.get_or_create(movie_uuid=alice_in_wonderland.uuid, actor_uuid=alice.uuid) MovieActor.get_or_create(movie_uuid=minions.uuid, actor_uuid=bob.uuid) MovieActor.get_or_create(movie_uuid=mission_impossible.uuid, actor_uuid=bob.uuid) res = self.test_client.get( 'http://localhost:5555/movie/?actor=Bob&genre=action') self.assertEqual(res.status_code, 200) self.assertEqual(len(res.json), 1) self.assertEqual(res.json[0].get('title'), 'Mission Impossible') self.assertEqual(res.json[0].get('genre'), 'action')
def setUp(self): """ delete all records before running test """ MovieActor.delete().execute() Movie.delete().execute() Actor.delete().execute()
def setUpClass(cls): """ create all database tables if necessary and wipe them """ super(ModelTestCase, cls).setUpClass() if not Movie.table_exists(): Movie.create_table() if not Actor.table_exists(): Actor.create_table() if not MovieActor.table_exists(): MovieActor.create_table()
def test_create(self): """ new MovieActor will be created when no match already exists""" movie = Movie.get_or_create(title='lion king', genre='drama') actor = Actor.get_or_create(name='nicole kidman') ma = MovieActor.get_or_create(movie_uuid=movie.uuid, actor_uuid=actor.uuid) # implicitly assert that only one record is in the database ma_from_db = MovieActor.get() self.assertEqual(ma_from_db.uuid, str(ma.uuid)) # confirm that trying to get or create with the same movies # will not create a duplicate: ma = MovieActor.get_or_create(movie_uuid=movie.uuid, actor_uuid=actor.uuid) ma_from_db = MovieActor.get() self.assertEqual(ma_from_db.uuid, str(ma.uuid))
def add_actor(item): actor_db = Actor(actor_name=item['actor_name'], actor_username=item['actor_username'], channel_id=item['channel_id'], title=item['title'], subscribers=item['subscribers'], video_count=item['video_count'], view_count=item['view_count'], created_date=item['created_date'], keywords=item['keywords'], collected_date=item['collected_date'], thumbnail_url=item['thumbnail_url'], description=item['description'], banner_url=item['banner_url'], above_one_hundred_thousand=item['hundred_thousand']) db.session.add(actor_db) db.session.commit()
def test_bad_movie(self): """ cannot create MovieActor record when movie does not exist""" actor = Actor.get_or_create(name='nicole kidman') with self.assertRaises(ValueError): MovieActor.get_or_create(movie_uuid='bad uuid', actor_uuid=actor.uuid)
response) creation_date = youtube_user.get_channel_creation_date(response) channel_thumbnail = youtube_user.get_channel_thumbnail(response) description = youtube_user.get_channel_description(response) keywords = youtube_user.get_channel_keywords(response) banner_thumbnail = youtube_user.get_channel_banner(response) hundred_thousand = youtube_user.check_above_one_hundred_thousand( subscribers) actor_db = Actor(actor_name=channel_actor, actor_username=channel_username, channel_id=channel_id, title=title, subscribers=subscribers, video_count=video_count, view_count=view_count, created_date=creation_date.split("T")[0], collected_date=YoutubeAPI.start_time, thumbnail_url=channel_thumbnail, description=description, keywords=keywords, banner_url=banner_thumbnail, above_one_hundred_thousand=hundred_thousand) db.session.add(actor_db) db.session.commit() time.sleep(0.02) videos_views = video.get_all_video_views_user_id( response, parameters['video_limit'], parameters['related_video_limit']) if videos_views:
def setUp(self): app.app_context().push() db.create_all() collected_date_value = datetime.strptime('2018-06-14', '%Y-%m-%d').date() actor_db = Actor(actor_name='Marina Silva', actor_username='******', channel_id='channel_id_value', title='Marina Silva', subscribers=13515, video_count=876, view_count=4307555, created_date='2010-01-26', keywords='keywords_value', collected_date=collected_date_value, thumbnail_url='thumbnail_url_value', description='description_value', banner_url='banner_url_value', above_one_hundred_thousand=False) video_db = Videos(views='1', title='Video Marina Silva', likes='1', dislikes='1', comments='1', favorites='1', url='url Marina Silva', publishedAt='data publicação', description='descrição', tags='tags', embeddable='embeddable', duration='duration', thumbnail='thumbnail', category='category', collected_date=collected_date_value, channel_id='channel_id_value', video_id='1') related_video_db = Videos( title='Related title', likes='34', views='8234', dislikes='3', comments='2', favorites='10', url='https://www.youtube.com/watch?v=hFc_scYRasdY', publishedAt='2015-12-13T17:37:01.000Z', description='', tags='disabled', embeddable='True', duration='PT4H24M20S', thumbnail='https://i.ytimg.com/vi/hFc_sasdRpQY/hqdefault.jpg', category='Entretenimento', video_id='2', collected_date=collected_date_value, channel_id='channel_id_value') relationship_actor_db = Relationship_Actor_Videos( video_id='1', channel_id='channel_id_value', collected_date=collected_date_value) relationship_video_db = Relationship_Videos( video_id='2', original_video_id='1', collected_date=collected_date_value) db.session.add(actor_db) db.session.add(video_db) db.session.add(relationship_actor_db) db.session.add(relationship_video_db) db.session.commit() # Cria um cliente de teste self.app = app.test_client() # Propaga as exceções para o cliente de teste self.app.testing = True