def insert_records(): # (1 - imports) # (2 - generate database schema) # 3 - create a new session (from the session factory) session = Session() # 4 - create movies bourne_identity = Movie("The Bourne Identity", date(2002, 10, 11)) furious_7 = Movie("Furious 7", date(2015, 4, 2)) pain_and_gain = Movie("Pain & Gain", date(2013, 8, 23)) # 5 - creates actors matt_damon = Actor("Matt Damon", date(1970, 10, 8)) dwayne_johnson = Actor("Dwayne Johnson", date(1972, 5, 2)) mark_wahlberg = Actor("Mark Wahlberg", date(1971, 6, 5)) # 6 - add actors to movies bourne_identity.actors = [matt_damon] furious_7.actors = [dwayne_johnson] pain_and_gain.actors = [dwayne_johnson, mark_wahlberg] # 7 - add contact details to actors (the last parameter defines the actor that the ContactDetails instance is associated to) matt_contact = ContactDetails("415 555 2671", "Burbank, CA", matt_damon) dwayne_contact = ContactDetails("423 555 5623", "Glendale, CA", dwayne_johnson) dwayne_contact_2 = ContactDetails("421 444 2323", "West Hollywood, CA", dwayne_johnson) mark_contact = ContactDetails("421 333 9428", "Glendale, CA", mark_wahlberg) # 8 - create stuntmen matt_stuntman = Stuntman("John Doe", True, matt_damon) dwayne_stuntman = Stuntman("John Roe", True, dwayne_johnson) mark_stuntman = Stuntman("Richard Roe", True, mark_wahlberg) # 9 - persists data (save the movies, actors, contact details, and stuntment) # (note that actors don't need to be explicitly saved, because SQLAlchemy, by default, uses the 'save-update' cascade strategy) session.add(bourne_identity) session.add(furious_7) session.add(pain_and_gain) session.add(matt_contact) session.add(dwayne_contact) session.add(dwayne_contact_2) session.add(mark_contact) session.add(matt_stuntman) session.add(dwayne_stuntman) session.add(mark_stuntman) # 10 - commit and close session session.commit() session.close()
def test_create_movie(app): app.go_to_home_page() app.login(User.Admin()) app.create_movie(Movie.required_field('The Terminal', '2004')) expected_text = "The Terminal (2004)" assert app.is_movie_created() == expected_text, "Title is not equal" app.logout()
def __init__(self, data): self.users = dict() self.movies = dict() for user_id in data: self.users[user_id] = User(user_id) for movie_id in data[user_id].ratings: self.users[user_id].add_rating(movie_id, data[user_id].ratings[movie_id]) if movie_id not in self.movies: self.movies[movie_id] = Movie(movie_id) self.movies[movie_id].add_rating(user_id, data[user_id].ratings[movie_id]) self.align_data()
def print_models(): matt_damon = Actor("Matt Damon", date(1970, 10, 8)) print(matt_damon) matt_contact = ContactDetails("415 555 2671", "Burbank, CA", matt_damon) print(matt_contact) bourne_identity = Movie("The Bourne Identity", date(2002, 10, 11)) print(bourne_identity) matt_stuntman = Stuntman("John Doe", True, matt_damon) print(matt_stuntman)
def addMovie(): """ Adds a movie to the DB. params: movie: A JSON encoded movie """ try: movieJson = request.form.get("movie") if not movieJson: raise BadRequest("Must provide a movie") movieDict = None try: # Decode the JSON received into a dictionary movieDict = json.loads(movieJson) except: raise BadRequest("Movie isn't valid JSON") if not movieDict.get("title"): raise BadRequest("Movie doesn't have a title") # Load the contents of the dictionary into the movie movie = Movie() for key in movie.__dict__: print("{}={}".format(key, movieDict.get(key))) movie.__dict__[key] = movieDict.get(key) db.addMovie(movie) print("Added movie: {}".format(movie)) return Response("success", mimetype="text/plain") except Exception as e: if config.debug: raise InternalServerError("Error: " + str(e)) else: raise e
def movie(self, movie_id: int()): m = tmdb.Movies(movie_id) response = m.info() cast = list() for actor in m.credits()['cast']: cast.append( Cast(id = actor['id'], name = actor['name'], character = actor['character'], profile_path = actor['profile_path'])) crew = list() for c in m.credits()['crew']: crew.append( Crew(id = c['id'], name = c['name'], job = c['job'], department = c['department'], profile_path = c['profile_path'])) credits = Credits(cast = cast, crew = crew) btc = BelongsToCollection(id = m.belongs_to_collection['id'], name = m.belongs_to_collection['name'], poster_path = m.belongs_to_collection['poster_path'], backdrop_path = m.belongs_to_collection['backdrop_path']) movie = Movie(id = m.id, imdb_id = m.imdb_id, title = m.title, original_title = m.original_title, tagline = m.tagline, release_date = m.release_date, poster_path = m.poster_path, backdrop_path = m.backdrop_path, homepage = m.homepage, runtime = m.runtime, budget = m.budget, revenue = m.revenue, overview = m.overview, status = m.status, belongs_to_collection = btc, credits = credits) return movie
def get_added_movie(self): vmp = self.view_movie_page vmp.is_this_page return Movie(title=vmp.movietitle_field.text)
def test_add_movie(app): app.ensure_login_as(User.Admin()) app.ensure_bad_movie_not_added(Movie.Bad()) app.ensure_logout()
def test_add_movie(app): app.ensure_login_as(User.Admin()) app.ensure_movie_added(Movie.random()) app.ensure_logout()
def test_add_movie(app): new_movie = Movie.random() app.ensure_login_as(User.Admin()) app.add_movie(new_movie) assert app.is_added_movie(new_movie)
async def editmovie(item: movie.Movie): data = item.dict() updatemovie(data) return {"Result": "Success"}
async def addmovie(item: movie.Movie): data = item.dict() insertmovie(data) return {"Result": "Success"}
def test_delete_movie(app): new_movie = Movie.random() app.ensure_login_as(User.Admin()) app.add_movie(new_movie) assert app.is_added_movie(new_movie) app.delete_movie(new_movie)
from datetime import date from base import Session, engine, Base from model.actor import Actor from model.contact_details import ContactDetails from model.movie import Movie from model.stuntman import Stuntman Base.metadata.create_all(engine) session = Session() bourne_identity = Movie("The Bourne Identity", date(2002, 10, 11)) furious_7 = Movie("Furious 7", date(2015, 4, 2)) pain_and_gain = Movie("Pain & Gain", date(2013, 8, 23)) matt_damon = Actor("Matt Damon", date(1970, 10, 8)) dwayne_johnson = Actor("Dwayne Johnson", date(1972, 5, 2)) mark_wahlberg = Actor("Mark Wahlberg", date(1971, 6, 5)) bourne_identity.actors = [matt_damon] furious_7.actors = [dwayne_johnson] pain_and_gain.actors = [dwayne_johnson, mark_wahlberg] matt_contact = ContactDetails("415 555 2671", "Burbank, CA", matt_damon) dwayne_contact = ContactDetails("423 555 5623", "Glendale, CA", dwayne_johnson) dwayne_contact_2 = ContactDetails("421 444 2323", "West Hollywood, CA", dwayne_johnson) mark_contact = ContactDetails("421 333 9428", "Glendale, CA", mark_wahlberg) matt_stuntman = Stuntman("John Doe", True, matt_damon) dwayne_stuntman = Stuntman("John Roe", True, dwayne_johnson)
from datetime import date from base import Base, engine, Session from model.actor import Actor from model.contact_details import ContactDetails from model.movie import Movie from model.stuntman import Stuntman #Initialize DB #Base.metadata.create_all(engine) session = Session() movie1 = Movie("The Dark Knight Rises", date(2012, 7, 20)) actor1 = Actor("Christian Bale", date(1974, 1, 30)) movie1.actors = [actor1] contact1 = ContactDetails("433 555 4353", "East Hollywood, CA", actor1) stuntman1 = Stuntman("", False, actor1) session.add(movie1) session.add(contact1) session.add(stuntman1)