How to use insert_test method in autotest

Best Python code snippet using autotest_python

insert.test.py

Source:insert.test.py Github

copy

Full Screen

...6from random import randint, randrange7from queries.insert_queries import *8from create_tables import create_tables9fake_zip = "V6R1Y5"10def insert_test(query_name, insert_query, insert_tuple):11 cursor.execute(insert_query, insert_tuple)12 print(f"{query_name} inserted successfully")13 db.commit()14def get_random_phone_number():15 # returns a random 10 digit phone number16 return randint(1000000000, 9999999999)17def get_random_user_type():18 return randint(0, 3)19def delete_all_rows_from(table_name):20 cursor.execute(f"DELETE FROM {table_name};")21if __name__ == "__main__":22 create_tables()23 """24 CREATE TABLE Card_BIN (25 card_number_6 char(6),26 bank_name char(50) NOT NULL,27 card_type char(20) NOT NULL,28 payment_system char(30) NOT NULL,29 PRIMARY KEY (card_number_6)30 );31 """32 insert_test("Card BIN", insert_card_bin_query,33 (123456, "CIBC", "CREDIT", "VISA"))34 """35 INSERT INTO RestaurantParent (36 restaurant_name,37 cuisine38 )39 """40 # not sure how to insert this41 # must convert input to lower case42 insert_test("Restaurant Parent",43 insert_restaurant_parent_query, ("McDonalds", "Fast Food"))44 """45 INSERT INTO City (46 city_name,47 province_name48 );49 """50 insert_test("City", insert_city_query,51 ("vancouver", "british columbia"))52 """53 INSERT INTO Zip (54 zip,55 city_name,56 );57 """58 # must convert city to lower case since duplicate cities with the same name could arise59 # and because city_name is a primary key60 insert_test("Zip", insert_zip_query, (fake_zip, "vancouver"))61 """62 CREATE TABLE User (63 user_id int auto increment,64 name char(20) NOT NULL,65 email char(30) NOT NULL,66 phone char(20) NOT NULL,67 type int NOT NULL,68 PRIMARY KEY (user_id),69 CHECK (type <= 2 AND type >= 0)70 );71 """72 insert_test("User", insert_user_query,73 ("tomi", "liu", "tomi@gmail.com", "7786966999", 0))74 """75 INSERT INTO UserToUser_Reviews (76 user_id_ratable,77 user_id_consumer,78 rating_time,79 value,80 review,81 );82 """83 # insert does not work because of foreign key constraints84 # insert_test("User to User reviews", insert_user_to_user_reviews_query,85 # (0, 0, datetime.now(), 5, "very tasty food!!"))86 """87 INSERT INTO User_Address (88 user_id, 89 zip,90 building_number, 91 unit_number, 92 street_name,93 VALUES (%s, %s, %s, %s, %s, %s)94 );95 """96 # cannot insert due to foreign key constraint97 # insert_test("User Address", insert_user_address_query,98 # (0, fake_zip, 0, 0, "Cambie st"))99 """100 INSERT INTO Speeder (101 speeder_id,102 transit,103 current_long,104 current_lat,105 );106 """107 # speeder id?108 insert_test("Speeder", insert_speeder_query, (0, 0, 123, 49))109 """110 INSERT INTO Restaurant (111 restaurant_name,112 restaurant_id,113 );114 """115 # must convert input to lower case116 insert_test("Restaurant", insert_restaurant_query, ("McDonalds", 0))117 """118 INSERT INTO Card_All (119 card_number_6, 120 card_number_rest,121 expiration_date, 122 zip,123 )124 """125 # cannot update because of foreign key constraint126 # insert_test("Card All", insert_card_all_query, (123456, 1111111111,127 # datetime.now().month + datetime.now().year, fake_zip))128 """129 INSERT INTO Item (130 item_name,131 restaurant_id ,132 price,133 );134 """135 # cannot update because of foreign key constraint136 # insert_test("Item", insert_item_query, ("chicken nuggets", 0, 6.9))137 """138 INSERT INTO Order (139 tip,140 status,141 order_time,142 special_instructions,143 consumer_id,144 restaurant_id,145 speeder_id,146 );147 """148 # order id?149 # remember to consider status for future150 # cannot update because of foreign key constraint151 # insert_test("Order", insert_order_query,152 # (2, 0, datetime.now(), "Please include utensils", 0, 0, 0))153 """154 INSERT INTO OrderToItem (155 order_id,156 restaurant_id,157 item_name,158 );159 """160 # cannot update because of foreign key constraint161 # insert_test("Order to Item", insert_order_to_item_query,...

Full Screen

Full Screen

insert_single_rows.py

Source:insert_single_rows.py Github

copy

Full Screen

...7fake_zip = "V6R1Y5"8# user_id, address_id, order_id are autoincremented, doing sample data for one user/address/order only9# auto-increment starts with 110user_id, address_id, order_id = 1, 1, 111def insert_test(query_name, insert_query, insert_tuple):12 cursor.execute(insert_query, insert_tuple)13 print(f"{query_name} inserted successfully with values {insert_tuple}")14 db.commit()15def insert_sample_rows():16 delete_all_rows_from_database(list_of_tables)17 insert_test("Card BIN", insert_card_bin_query,18 (123456, "CIBC", 0, "Visa"))19 # must convert input to lower case20 insert_test("Restaurant Parent", insert_restaurant_parent_query,21 ("McDonalds", "Fast Food"))22 insert_test("City", insert_city_query,23 ("Vancouver", "British Columbia"))24 # must convert city to lower case since duplicate cities with the same name could arise25 # and because city_name is a primary key26 insert_test("Zip", insert_zip_query, (fake_zip, "vancouver"))27 insert_test("User", insert_user_query,28 ("tomi","Liu", "tomi@gmail.com", "7786966999", 0))29 insert_test("User to User reviews", insert_user_to_user_reviews_query,30 (user_id, user_id, 5, "very tasty food!!"))31 insert_test("User Address", insert_user_address_query,32 (user_id, fake_zip, 33, 12, "Cambie st"))33 insert_test("Speeder", insert_speeder_query, (user_id, 2, 123, 49))34 # must convert input to lower case35 insert_test("Restaurant", insert_restaurant_query, (user_id, "McDonalds"))36 insert_test("Card All", insert_card_all_query, (123456, 1111111111,37 datetime.now().month + datetime.now().year, fake_zip, user_id))38 insert_test("Item", insert_item_query, ("chicken nuggets", user_id, 6.9))39 # order id?40 # remember to consider status for future41 insert_test("Order", insert_order_query,42 (1.3, 2, datetime.now(), "Please include utensils", user_id, user_id, user_id))43 insert_test("Order to Item", insert_order_to_item_query,44 (order_id, user_id, "chicken nuggets"))45if __name__ == "__main__":...

Full Screen

Full Screen

all_test.py

Source:all_test.py Github

copy

Full Screen

1import unittest2import sys3import os4sys.path.insert(0, os.path.abspath('..'))5from part1.insertion import Insertion6from part1.rapport import Rapport7class MyTestCase(unittest.TestCase):8 def check_if_word_in_file(self, filename, word):9 file = open(filename, 'r')10 if word in file.read():11 file.close()12 return True13 file.close()14 return False15 def test_should_end_the_input(self):16 insert_test = Insertion("text.txt")17 string = "--fin"18 self.assertTrue(insert_test.is_end(string))19 def test_should_not_end_the_input(self):20 insert_test = Insertion("text.txt")21 string = "fin"22 self.assertFalse(insert_test.is_end(string))23 def test_word_should_be_in_file(self):24 insert_test = Insertion("text.txt")25 insert_test.write_in_file("phrase")26 self.assertTrue(self.check_if_word_in_file("text.txt", "phrase"))27 os.remove("text.txt")28 def test_word_should_not_be_in_file(self):29 insert_test = Insertion("text.txt")30 insert_test.write_in_file("phrase")31 self.assertFalse(self.check_if_word_in_file("text.txt", "3"))32 os.remove("text.txt")33 def test_get_a_dict_of_three_words(self):34 file = open("test.txt", "a")35 file.write("1" + '\n')36 file.write("2" + '\n')37 file.write("3" + '\n')38 file.close()39 rapport = Rapport("test.txt")40 dict_of_words = rapport.get_a_dict_with_file_data()41 self.assertEqual(len(dict_of_words), 3)42 os.remove("test.txt")43 def test_sort_a_dict_in_reverse_order(self):44 rapport = Rapport("test.txt")45 dict_of_words = {1: 1, 2: 2, 3: 3}46 sorted_dict = dict(reversed(sorted(dict_of_words.items(), key=lambda item: item[1])))47 first_value = list(sorted_dict.keys())[0]48 self.assertEqual(first_value, 3)49if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful