def test_filter_by_email_that_contains(self): my_file = "test_data.csv" expected = [[ 'Diana Harris', 'lime', 'Martin-Barnes', '*****@*****.**', '1-860-251-9980x6941', '5354' ]] self.assertEqual(filter(my_file, email__contains="@gmail"), expected)
def test_filter_with_empty_file_whether_raise_exception(self): my_file = "empty_file.csv" with self.assertRaises(Exception) as e: self.assertTrue( filter(my_file, full_name="Diana Harris", favourite_color="lime"), e.exception)
def test_filter_by_first_name_that_startswith(self): my_file = "test_data.csv" expected = [[ 'Diana Harris', 'lime', 'Martin-Barnes', '*****@*****.**', '1-860-251-9980x6941', '5354' ]] self.assertEqual(filter(my_file, full_name__startswith="Diana Harris"), expected)
def test_filter_by_first_name_and_favourite_color(self): my_file = "test_data.csv" expected = [[ 'Diana Harris', 'lime', 'Martin-Barnes', '*****@*****.**', '1-860-251-9980x6941', '5354' ]] self.assertEqual( filter(my_file, full_name="Diana Harris", favourite_color="lime"), expected)
def test_when_one_key_word_argument_is_passed_then_return_array_of_data_filtered_by_that_key_word( self): expr = "Diana Harris" file = 'example_data.csv' expected_result = [[ 'lime', '5354', '1-860-251-9980x6941', '*****@*****.**', 'Martin-Barnes', 'Diana Harris' ]] self.assertEqual((queries.filter(file, full_name=expr)).sort(), expected_result.sort())
def test_when_more_then_one_key_word_arguments_are_passed_then_return_array_of_arrays_filtered_by_all_of_arguments( self): expr_1 = "Diana Harris" expr_2 = 'lime' file = 'example_data.csv' expected_result = [[ 'lime', '5354', '1-860-251-9980x6941', '*****@*****.**', 'Martin-Barnes', 'Diana Harris' ]] self.assertEqual((queries.filter(file, full_name=expr_1, favoutite_color='lime')).sort(), expected_result.sort())
def test_when_filter_by_first_name_then_return_array_of_data_filtered_by_first_name( self): expr = "Diana" file = 'example_data.csv' expected_result = [[ '1-860-251-9980x6941', 'Martin-Barnes', '5354', 'Diana Harris', 'lime', '*****@*****.**' ], [ '659-155-8389x092', 'Hart, Ray and Wagner', '8587', 'Diana May', 'olive', '*****@*****.**' ]] self.assertEqual((queries.filter(file, full_name_startswith=expr)).sort(), expected_result.sort())
def test_filter_by_salary_gt_1000_and_lt_3000(self): my_file = "test_data.csv" expected = [[ 'Michael Olson', 'olive', 'Scott, Young and King', '*****@*****.**', '114-116-1124x315', '2151' ], [ 'Patricia King', 'white', 'Gonzalez-Fuentes', '*****@*****.**', '1-512-204-5161', '1039' ], [ 'Julie Byrd', 'lime', 'Johnson-Reynolds', '*****@*****.**', '(664)760-9409', '1995' ]] self.assertListEqual(filter(my_file, salary__gt=1000, salary__lt=3000), expected)
def test_filter_by_salary_grater_then_given_one_and_less_then_another_one_and_return_array_of_arrays_with_records_that_are_having_salary_in_given_interval( self): expr_1 = 3000 expr_2 = 6000 file = 'example_data.csv' expected_result = [[ 'lime', '*****@*****.**', 'Martin-Barnes', '5354', '1-860-251-9980x6941', 'Diana Harris' ], [ 'black', '*****@*****.**', 'Wilson, Smith and Vance', '5985', '(448)095-7360x318', 'Karen Lucas' ]] self.assertEqual((queries.filter(file, salary_gt=expr_1, salary_lt=expr_2)).sort(), expected_result.sort())
def test_filter_when_is_passed_order_element_then_return_result_ordered_by_given_value( self): expr_1 = 3000 expr_2 = 6000 expr_3 = 'salary' file = 'example_data.csv' expected_result = [[ 'Martin-Barnes', '5354', '1-860-251-9980x6941', '*****@*****.**', 'Diana Harris', 'lime' ], [ 'Wilson, Smith and Vance', '5985', '(448)095-7360x318', '*****@*****.**', 'Karen Lucas', 'black' ]] self.assertEqual((queries.filter(file, salary_gt=expr_1, salary_lt=expr_2, order_by=expr_3)).sort(), expected_result.sort())
def test_filter_by_type_of_email_and_return_array_of_arrays_with_records_that_are_using_this_type( self): expr = "@yahoo" file = 'example_data.csv' expected_result = [[ 'Michael Olson', '*****@*****.**', 'olive', '114-116-1124x315', '2151', 'Scott, Young and King' ], [ 'Marilyn Maldonado', '*****@*****.**', 'black', '+49(1)7897611670', '7158', 'Walker PLC' ], [ 'Courtney Lowery DVM', '*****@*****.**', 'lime', '(826)821-7107x2319', '169', 'Rogers PLC' ]] self.assertEqual((queries.filter(file, full_name_startswith=expr)).sort(), expected_result.sort())
def test_filter_with_empty_file(self): my_file = "empty_file.csv" expected = [] self.assertEqual( filter(my_file, full_name="Diana Harris", favourite_color="lime"), expected)
def test_get_csv_data_raises_OSError_if_fails_to_open_file(self): with self.assertRaises(OSError): invalidFileName = "qodwqopdkq.csv" filter(invalidFileName)