From 8e548f5f6d5183abd86a693959a175757bd9ec25 Mon Sep 17 00:00:00 2001 From: DewanaGustavus <76590469+DewanaGustavus@users.noreply.github.com> Date: Mon, 23 Oct 2023 22:38:50 +0700 Subject: [PATCH] chore: fix some seeding invalid data --- seeding/carts_faker.py | 9 ++++++--- seeding/user_faker.py | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/seeding/carts_faker.py b/seeding/carts_faker.py index 8568b08..bef31a2 100644 --- a/seeding/carts_faker.py +++ b/seeding/carts_faker.py @@ -8,6 +8,7 @@ PRODUCTS_LIMIT = 200 # Get data from database select_users = '''SELECT id FROM users + WHERE category = \'user\' ORDER BY rand() LIMIT ''' + str(USERS_LIMIT) cursor.execute(select_users) @@ -31,9 +32,10 @@ for i in range(CARTS_COUNT): user_index = randint(0, USERS_LIMIT - 1) product_index = randint(0, PRODUCTS_LIMIT - 1) - while((users[user_index][0], products[product_index][0]) in existing_carts) : - user_id = randint(0, USERS_LIMIT - 1) - product_id = randint(0, PRODUCTS_LIMIT - 1) + while((users[user_index][0], products[product_index][0]) in existing_carts + or products[product_index][1] == 0) : + user_index = randint(0, USERS_LIMIT - 1) + product_index = randint(0, PRODUCTS_LIMIT - 1) user_id = users[user_index][0] product_id = products[product_index][0] @@ -42,6 +44,7 @@ for i in range(CARTS_COUNT): carts_val = (user_id, product_id, quantity) cursor.execute(carts_sql, carts_val) + existing_carts.append((user_id, product_id)) db.commit() print("Insertion success") \ No newline at end of file diff --git a/seeding/user_faker.py b/seeding/user_faker.py index ec69f4e..718fbae 100644 --- a/seeding/user_faker.py +++ b/seeding/user_faker.py @@ -8,7 +8,7 @@ for i in range(USER_COUNT): name = faker.name() username = name + "-" + str(i) - email = name + "@gmail.com" + email = username + "@gmail.com" password = name description = faker.text() category = "user" -- GitLab