def test_upload_data(self, data): engine = self.temp_db.test_db_engine open_session(engine, upload_data_to_db, data) with HandleSession(engine) as handle: assert handle.session.query(models.MovieMetadata).all() assert handle.session.query(models.Character).all() assert handle.session.query(models.Crew).all() assert handle.session.query(models.Keywords).all()
def test_upload_movies_keywords(self, data): engine = self.temp_db.test_db_engine movie_metadata = data[0][0] open_session(engine, upload_movies_metadata, movie_metadata) keywords_data = data[2][0] open_session(engine, upload_movies_keywords, keywords_data) with HandleSession(engine) as handle: assert handle.session.query(models.Keywords).all()
def test_upload_movies_metadata(self, data): engine = self.temp_db.test_db_engine row = data[0][0] open_session(engine, upload_movies_metadata, row) with HandleSession(engine) as handle: assert handle.session.query(models.Genre).all() assert handle.session.query(models.ProductionCompany).all() assert handle.session.query(models.Country).all() assert handle.session.query(models.Language).all() assert handle.session.query(models.MovieMetadata).all()
def test_upload_movies_credits(self, data): engine = self.temp_db.test_db_engine movie_metadata = data[0][0] open_session(engine, upload_movies_metadata, movie_metadata) credits_data = data[1][0] open_session(engine, upload_movies_credits, credits_data) with HandleSession(engine) as handle: assert handle.session.query(models.Actor).all() assert handle.session.query(models.CrewMember).all() assert handle.session.query(models.Character).all() assert handle.session.query(models.Crew).all()
def upload_movies_keywords(session: Session, row: np.ndarray) -> Iterator: """ Creates and yields instances of Keywords from data from the row. """ yield models.Keywords.get_or_create(session, movie_id=row[0], keywords=row[1]) def upload_data_to_db( session: Session, data: Tuple[np.ndarray, np.ndarray, np.ndarray]) -> Iterator: """ Uploads data to the database. """ for row in data[0]: yield from upload_movies_metadata(session, row) for row in data[1]: yield from upload_movies_credits(session, row) for row in data[2]: yield from upload_movies_keywords(session, row) if __name__ == "__main__": from settings import DATABASES db_man = DBManager(db_config=DATABASES["default"]) db_man.create_tables() engine = db_man.default_db_engine data = upload_csv("archive") open_session(engine, upload_data_to_db, data)