Sample input for the whole test
This commit is contained in:
parent
c3434ec1f7
commit
94ad5b28e5
17
database.py
17
database.py
|
@ -38,14 +38,25 @@ def adapt_movie_data(data_in: dict):
|
|||
|
||||
|
||||
def fill_db(
|
||||
db=SessionLocal(), movie_input_file: str = "input_data/movies_metadata.csv"
|
||||
db=SessionLocal(),
|
||||
movie_input_file: str = "input_data/movies_metadata.csv",
|
||||
sample_rate=100,
|
||||
):
|
||||
import crud
|
||||
import csv
|
||||
import random
|
||||
|
||||
page_size = 1_00
|
||||
|
||||
def compute_rate(*dummy):
|
||||
if 0 < sample_rate < 100:
|
||||
return random.random() < (sample_rate / 100)
|
||||
return True
|
||||
|
||||
with open(movie_input_file) as csvfile:
|
||||
for count, movie_data in enumerate(csv.DictReader(csvfile), start=1):
|
||||
for count, movie_data in enumerate(
|
||||
filter(compute_rate, csv.DictReader(csvfile)), start=1
|
||||
):
|
||||
if count % page_size == 0:
|
||||
db.commit()
|
||||
|
||||
|
@ -62,4 +73,4 @@ def fill_db(
|
|||
|
||||
if __name__ == "__main__":
|
||||
create_db()
|
||||
fill_db()
|
||||
fill_db(sample_rate=1)
|
||||
|
|
|
@ -161,7 +161,7 @@ def test_title_is_taken_form_original_title_is_missing():
|
|||
|
||||
assert movie_title not in movies_by_title, "The movie should not be pre existing"
|
||||
with db_context() as db:
|
||||
fill_db(db, file_path)
|
||||
fill_db(db, file_path, sample_rate=1)
|
||||
|
||||
movies = client.get("movies")
|
||||
movies_by_title = {m["title"]: m for m in movies.json()}
|
||||
|
|
Loading…
Reference in New Issue