def test_single_customer_good(setup_invoice_file): elisa_invoice_csv = 'Elisa_Miles_invoice.csv' create_invoice = single_customer('Elisa Miles', elisa_invoice_csv) create_invoice(INVOICE_FILE) line_count = sum(1 for line in open(elisa_invoice_csv)) assert line_count == 2 remove_file(elisa_invoice_csv)
def test_single_customer(self): """ Validates add furnature with an new file """ def mock_method(invoice_file, customer_name, item_code, item_description, item_monthly_price): """ Mock add_furnature Method """ pass contents = "Alteration:82.31%,Incursion:17.68%,Recursion:100.00%" mock_file = mock_open(read_data=contents) with patch("inventory.add_furnature") as add: add.return_value = mock_method with patch("functools.partial"): with patch("builtins.open", mock_file) as open_mock: test_customer = single_customer("Astra Matsume", "air.csv") test_customer("timeline.csv") open_mock.assert_called_once_with("timeline.csv", "r") add.assert_called_once_with(invoice_file="air.csv", customer_name="Astra Matsume", item_code="Alteration:82.31%", item_description="Incursion:17.68%", item_monthly_price="Recursion:100.00%")
def test_single_customer_bad(setup_invoice_file): non_customer_csv = 'non_customer.csv' create_invoice = single_customer("Non Customer", non_customer_csv) create_invoice(INVOICE_FILE) line_count = sum(1 for line in open(non_customer_csv)) assert line_count == 0 remove_file(non_customer_csv)
def test_single_customer(self): """Test single_customer()""" # Test creating new file and adding 1 item inventory.add_furniture('test_rented_items.csv', 'John Adams', 'LK25', 'Leather Chair', 25) # Test adding multiple items into existing file inventory.add_furniture('test_rented_items.csv', 'Ivan Ramen', 'ST68', 'Bar Stool', 15) inventory.add_furniture('test_rented_items.csv', 'Irene Jules', 'SF22', 'Sofa', 150) # Test adding multiple items with single_customer bulk_add = inventory.single_customer('Susan', 'test_rented_items.csv') bulk_add('all_rentals.csv') # Check for added items with open('test_rented_items.csv', 'r') as file: reader = csv.reader(file) data = [] for row in reader: data.append(row) test_list = [[ 'customer_name', 'item_code', 'item_description', 'item_monthly_price' ], ['John Adams', 'LK25', 'Leather Chair', '25'], ['Ivan Ramen', 'ST68', 'Bar Stool', '15'], ['Irene Jules', 'SF22', 'Sofa', '150'], ['Susan', 'HM25', 'Mattress', '150'], ['Susan', 'JK10', 'Grill', '20'], ['Susan', 'YG36', 'Rug', '300']] self.assertEqual(test_list, data)
def test_single_customer(test_single_customer_results): create_invoice = single_customer("Susan Wong", "SW_invoice.csv") create_invoice("test_items.csv") with open("test_items.csv", mode="r") as customer_file: customer_reader = csv.reader(customer_file) customer_list = [row for row in customer_reader] assert customer_list[0] == test_single_customer_results[0]
def main(): add_furniture("invoice01.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) add_furniture("invoice01.csv", "Edward Data", "KT78", "Kitchen Table", 10) add_furniture("invoice01.csv", "Alex Gonzales", "BR02", "Queen Mattress", 17) add_items = single_customer('Susan Wong', 'sw_invoice.csv') add_items('test_items.csv')
def test_single_customer(): result = inventory.single_customer("test_invoices.csv", "Fresh Prince") result("test_items.csv") with open('test_invoices.csv', 'r') as file: lines = file.readlines() assert len(lines) == 3 assert lines[0] == "Fresh Prince,LR04,Leather Sofa,25.00\n" assert lines[1] == "Fresh Prince,KT78,Kitchen Table,10.00\n" assert lines[2] == "Fresh Prince,BR02,Queen Mattress,17.00\n"
def test_single_customer(self): """Test single_customer function.""" open(self.test_invoice_file, 'w').close() create_invoice = inventory.single_customer("Susan Wong", self.test_invoice_file) create_invoice("test_items.csv") with open(self.test_invoice_file, 'r') as file: contents = csv.reader(file) check_row = next(contents) self.assertEqual(self.test_single_list, check_row)
def test_single_customer(): ''' Testing the single customer function ''' invoice_file = Path.cwd().with_name('data') / 'invoice_file.csv' rental_file = Path.cwd().with_name('data') / 'test_items.csv' customer = l.single_customer('Amy Sutton', invoice_file) customer(rental_file) with open(invoice_file, 'r') as f: items = f.readlines() assert items[0] == 'Amy Sutton,LR01,Small lamp,7.50\n'
def test_single_customer(tmpdir): ''' tests single_customer function from inventory.py ''' invoice_file = tmpdir.join("test_invoice_file2.csv") rentals_to_invoice = single_customer('Mrs. McSpendy', invoice_file.strpath) client_file = 'test_client_items.csv' rentals_to_invoice(client_file) with open(invoice_file.strpath, 'r') as f_file: results = f_file.read() assert results == 'Mrs. McSpendy, aTeST, Leather Sofa, 25.00\nMrs. McSpendy, bTeSt, Kitchen Table, 10.00\n'
def test_single_customer(self): """ Test single_customer function """ inv.LOGGER.info('--- Start Test single_customer() ---') create_invoice = inv.single_customer('Susan Wong', 'rented_items.csv') create_invoice('test_items.csv') with open('rented_items.csv', 'r') as infile: lines = infile.readlines() self.assertEqual(len(lines), 6) self.assertEqual(lines[3], 'Susan Wong,MO04,Microwave Oven,35.0\n') self.assertEqual(lines[4], 'Susan Wong,KT88,Kitchen Chair,5.0\n') self.assertEqual(lines[5], 'Susan Wong,KM52,King Matress,27.0\n') inv.LOGGER.info('--- End Test single_customer() ---')
def test_single_customer(self): """ Unit test for the single_customer function """ create_invoice = inventory.single_customer("Bruce Wayne", "data/rental_data.csv") create_invoice("data/test_items.csv") with open("data/rental_data.csv", 'r') as rental_file: reader = csv.reader(rental_file) self.assertIn( ["Bruce Wayne", "BM500", "Batmobile Remote Control", "1000"], list(reader))
def test_single_customer(self): """test adding in a single customer""" scrub_test_file("rented_items.csv") new_invoice = single_customer("rented_items.csv", "Susan Wong") new_invoice("data.csv") test_list = [] with open("rented_items.csv", newline="") as file: for row in file: test_list.append(row) self.assertEqual(test_list[0], ('Susan Wong,LR04,Leather Sofa,25.0\r\n')) self.assertEqual(test_list[1], ('Susan Wong,KT78,Kitchen Table,10.0\r\n')) self.assertEqual(test_list[2], ('Susan Wong,BR02,Queen Mattress,17.0\r\n'))
def test_single_customer(_show_all_single_customer_furniture): # Remove any old furniture listing in the spreadsheet’s data with open('data/test_items.csv', mode='w') as invoice: invoice.close() create_invoice = l.single_customer('Susan Wong', 'data/rented_items.csv') create_invoice('data/test_items.csv') with open('data/test_items.csv', mode='r') as invoice: reader = csv.reader(invoice, delimiter=',') for read_furniture, acutal_furniture in zip( reader, _show_all_single_customer_furniture): assert read_furniture == acutal_furniture
def test_single_customer(): create_invoice = l.single_customer("Susan Wong", "demo.csv") create_invoice("test_items.csv") data = [ ['Susan Wong','LR01','Small lamp','7.50'], ['Susan Wong','LR02','Television','28.00'], ['Susan Wong','BR07','LED lamp','5.50'], ['Susan Wong','KT08','Basic refrigerator','40.00'] ] opt_list = [] with open('demo.csv', 'r') as file: [opt_list.append(line.strip('\r\n').split(',')) for line in file.readlines()] for data_line in data: assert data_line in opt_list
def test_single_customer(self): ''' Method to test single_customer method ''' create_invoice = single_customer("Susan Wong", self.test_single_customer_write_file) create_invoice(self.test_single_customer_read_file) # Read csv file to confirm correct write with open(self.test_single_customer_write_file, 'r') as csv_file: csv_reader = csv.reader(csv_file) for i, row in enumerate(csv_reader): # Convert final column (price) to int row[-1] = int(float(row[-1])) # Ensure row is equal to input data self.assertEqual(self.single_customer_lines[i], row)
def test_single_customer(self): """ testing single_customer """ customer = single_customer('Eliza Miles', 'Miles.csv') customer('invoice_file.csv') with open('Miles.csv', 'r') as file: csv_contents = [] for row in file: csv_contents.append(row) expected = [ 'Eliza Miles,LR04,Leather Sofa,25.0\n', 'Eliza Miles,KT78,Kitchen Table,10.0\n', 'Eliza Miles,BR02,Queen Mattress,17.0\n' ] self.assertEqual(csv_contents, expected)
def test_single_customer(): my_path = Path('test.txt') test_result = [['Alex', 'LR01', 'Small lamp', '7.50'], ['Alex', 'LR02', 'Television', '28.00'], ['Alex', 'BR07', 'LED lamp', '5.50'], ['Alex', 'KT08', 'Basic refrigerator', '40.00']] logger.debug('If test.txt exists, delete it.') if my_path.is_file(): os.remove(my_path) test_func = l.single_customer('Alex', 'test.txt') test_func('../data/test_items.csv') test_data = [] with open(my_path) as f: reader = csv.reader(f) for line in reader: test_data.append(line) assert test_data == test_result
def test_single_customer(self): '''Tests single customer class''' inventory.add_furniture("rented_items.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) create_invoice = inventory.single_customer("Susan Wong", "rented_items.csv") create_invoice("test_items.csv") with open('rented_items.csv', 'r') as file: data_reader = csv.reader(file, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) new_list = [] for row in data_reader: new_list.append(row) final_list = [["Elisa Miles", "LR04", "Leather Sofa", '25'], ["Susan Wong", "LR04", "Leather Sofa", '25'], ["Susan Wong", "KT78", "Kitchen Table", '10'], ["Susan Wong", "BR02", "Queen Mattress", '17']] self.assertEqual(new_list, final_list)
def test_single_customer(self): """Unit test of the single_customer function""" test_file = 'single_customer_test.csv' test_items = [] with open('test_items.csv', newline='') as test_items_file: for line in reader(test_items_file): test_items.append(line) test_cust_add = single_customer('Bob Bobbo', test_file) test_cust_add(test_items) test_result = [] with open(test_file, 'r') as read_file: for line in reader(read_file): test_result.append(line) for item in test_items: item.insert(0, 'Bob Bobbo') self.assertListEqual(test_result[-len(test_items):], test_items)
def test_single_customer(self): """tests single_customer""" with open('Dorothy_Zbornak.csv', 'a', newline='') as invoice: invoice_write = csv.writer(invoice, delimiter=',') invoice_write.writerow(['T100', 'television', 50]) invoice_write.writerow(['CT100', 'coffee table', 10]) invoice_write.writerow(['QB100', 'queen bed', 40]) dorothy = single_customer('Dorothy Zbornak', 'test_invoice.csv') dorothy('Dorothy_Zbornak.csv') with open('test_invoice.csv', 'r') as test_invoice: test_csv_reader = csv.reader(test_invoice) test_row = next(test_csv_reader) self.assertEqual(test_row, ['Dorothy Zbornak', 'C100', 'couch', '25']) with open('test_invoice.csv', 'r') as test_invoice: test_csv_reader = csv.reader(test_invoice) test_row = (next(reversed(list(test_csv_reader)))) self.assertEqual(test_row, ['Dorothy Zbornak', 'QB100', 'queen bed', '40'])
def test_single_customer(self): """ Tests importing items from a CSV for a single user """ expected_content = [ 'Elisa Miles,LR04,Leather Sofa,25\n', 'Edward Data,KT78,Kitchen Table,10\n', 'Alex Gonzales,BR02,Queen Mattress,17\n', 'Susan Wong,LR04,Leather Sofa,25.00\n', 'Susan Wong,KT78,Kitchen Table,10.00\n', 'Susan Wong,BR02,Queen Mattress,17.00\n' ] create_invoice = single_customer("Susan Wong", "rented_items.csv") create_invoice("test_items.csv") with open("rented_items.csv", "r") as csv_file: content = csv_file.readlines() self.assertEqual(expected_content, content)
def test_single_customer(self): os.remove('space_items.csv') """tests single_customer function """ spider_man = single_customer('Peter Parker', 'space_items.csv') spider_man('test_items.csv') with open('space_items.csv', 'r') as space_items: csv_reader = csv.reader(space_items) spider_row = next(csv_reader) self.assertEqual(spider_row, ['Peter Parker', 'LR04', 'Leather Cape', '25']) with open('space_items.csv', 'r') as space_items: csv_reader = csv.reader(space_items) test_row = (next(reversed(list(csv_reader)))) self.assertEqual(test_row, ['Peter Parker', 'BR02', 'Queen Mattress', '17'])
def test_single_customer(self): """ Tests function to add multiple rental data for a single customer """ name = "Susan Wong" items = [['LR04', 'Leather Sofa', '25'], ['KT78', 'Kitchen Table', '15'], ['BR02', 'Queen Mattress', '17']] for item in items: item.insert(0, name) invoice_file = "rental_data.csv" create_invoice = single_customer(name, invoice_file) create_invoice("test_items.csv") with open(invoice_file, 'r') as csvfile: reader = csv.reader(csvfile) data_list = list(reader) del data_list[:3] self.assertEqual(data_list, items)
def test_single_customer(self): """Tests inventory.single_customer""" try: with open(TEST_CSV) as f: lines_pre = f.readlines() except FileNotFoundError: lines_pre = [] create_invoice = inventory.single_customer("Susan Wong", TEST_CSV) create_invoice(TEST_ITEMS) with open(TEST_CSV) as f: lines = f.readlines() new_lines = lines[len(lines_pre):] self.assertEqual(3, len(new_lines)) self.assertEqual("Susan Wong,LR04,Leather Sofa,25.00", new_lines[0].strip()) self.assertEqual("Susan Wong,KT78,Kitchen Table,10.00", new_lines[1].strip()) self.assertEqual("Susan Wong,BR02,Queen Mattress,17.00", new_lines[2].strip())
def test_single_customer(): """Tests single customer function returns function.""" test_func = single_customer("Susan Wong", "SW_invoice.csv") assert type(test_func) == "function"
def test_single_customer(_single_customer): create_invoice = l.single_customer("Susan Wong", "../data/rented_items.csv") response = create_invoice("../data/test_items.csv") assert response == _single_customer
"""UnitTest Module for inventory.py""" from inventory import add_furniture, single_customer add_furniture("rented_items.csv", "Elisa Miles", "LR04", "Leather Sofa", 25) add_furniture("rented_items.csv", "Edward Data", "KT78", "Kitchen Table", 10) add_furniture("rented_items.csv", "Alex Gonzales", "BR01", "Queen Mattress", 17) create_invoice = single_customer("Susan Wong", "rented_items.csv") create_invoice("test_items.csv")
from inventory import add_furniture, single_customer add_furniture('butt', 'y69', '123w', 420) add_furniture('ccat', 'y23', 'aasd32', 22) add_furniture('qqgg', 'sdf2', 'sdsv33', 33) testy = single_customer('dude') testy('rental_file.csv') # cd C:\Users\v-ollock\github\SP_Python220B_2019\students\ScotchWSplenda\lesson08\assignment\ # python -m pylint ./inventory.py
def test_closure(): godzilla = inventory.single_customer('Godzilla') assert godzilla('godzilla_invoice.csv') == 'Invoice godzilla_invoice.csv created for Godzilla.'