コード例 #1
0
def test_add_furniture():
    """ testing add furniture fucntion"""
    # clean the file
    l.clean_file("rented_items.csv")
    l.add_furniture("rented_items.csv", "Elisa Miles", "LR04", "Leather Sofa",
                    25)
    header = ("customer_name", "item_code", "item_description",
              "item_monthly_price")
    result = dict(zip(header, ("Elisa Miles", "LR04", "Leather Sofa", "25")))
    lines = l.read_csv("rented_items.csv")
    line = next(lines)
    assert line == result
コード例 #2
0
    def test_add_furniture_should_create_invoice(self):
        """ Create invoice, verify CSV created"""
        # Given
        expected_filename = "rented_items.csv"
        expected_directory = "./invoices"
        file_path = Path(expected_directory) / expected_filename

        # When
        add_furniture("rented_items.csv", "Elisa Miles", "LR04",
                      "Leather Sofa", 25)

        # Then
        self.assertTrue(os.path.isfile(file_path))
コード例 #3
0
def test_add_furniture():
    """
    Tests add_furniture function using a randomly generated list of customers,
    items, prices, and codes.

    Function should create file if it does not exist and append to it if it
    does.
    """
    # print(TEST_LIST)
    for item in TEST_LIST:
        inv.add_furniture(item[0], item[1], item[2], item[3], item[4])

    with open('data/super_test_uncopyable_filename.csv', 'r') as read_file:
        test_reader = list(csv.reader(read_file))
        for index, line in enumerate(test_reader):
            assert line == TEST_LIST[index][1:]

    os.remove('data/super_test_uncopyable_filename.csv')
コード例 #4
0
    def test_add_furniture(self):
        """This method will test the add_furniture function in inventory.py"""
        file_path = os.path.join(os.path.dirname(__file__), '..', 'src',
                                 'test_add_furniture.csv')
        try:
            os.remove(file_path)
        except FileNotFoundError:
            LOGGER.debug("No leftover files found")

        actual_items1 = []

        inventory.add_furniture("test_add_furniture.csv", "Elisa Miles",
                                "LR04", "Leather Sofa", 25)
        inventory.add_furniture("test_add_furniture.csv", "Edward Data",
                                "KT78", "Kitchen Table", 10)
        inventory.add_furniture("test_add_furniture.csv", "Alex Gonzales",
                                "QM15", "Queen Mattress", 17)

        with open(file_path) as test:
            test_reader = csv.reader(test, delimiter=',', quotechar='"')
            for row in test_reader:
                actual_items1.append(row)
        expected_items1 = [["Elisa Miles", "LR04", "Leather Sofa", '25'],
                           ["Edward Data", "KT78", "Kitchen Table", '10'],
                           ["Alex Gonzales", "QM15", "Queen Mattress", '17']]
        self.assertEqual(actual_items1, expected_items1)
        os.remove(file_path)
コード例 #5
0
    def test_create_invoice_for_single_customer_should_create_invoice(self):
        """ Test create_invoice to see if file is generated correctly """
        # Given
        expected_contents = [
            "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",
        ]

        # Whenadd_furniture("rented_items.csv", "Elisa Miles", "LR04", "Leather Sofa", 25)
        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", "BR02",
                      "Queen Mattress", 17)

        create_invoice = single_customer("Susan Wong", "rented_items.csv")
        self.assertTrue(callable(create_invoice))
        create_invoice("test_items.csv")

        # Then
        actual_lines = []
        with open("./invoices/rented_items.csv", "r") as f:
            for line in f:
                actual_lines.append(line)

        self.assertListEqual(expected_contents, actual_lines)
コード例 #6
0
    def test_add_furniture_should_add_line_to_blank_file(self):
        """ Create invoice, add line to it"""
        # Given
        filename = "rented_items.csv"
        directory = "./invoices"
        file_path = Path(directory) / filename
        name = "Elisa Miles"
        prod_id = "LR04"
        description = "Leather Sofa"
        price = 25

        expected_line = ",".join([name, prod_id, description, str(price)])
        expected_line += "\n"

        # When
        add_furniture(filename, name, prod_id, description, price)

        # Then
        with open(file_path, "r") as f:
            read_line = f.readline()

        self.assertEqual(expected_line, read_line)
コード例 #7
0
def test_add_furniture():
    inventory.add_furniture('invoice.csv', 'Elisa Miles', 'LR04',
                            'Leather Sofa', '25.00')
    inventory.add_furniture('invoice.csv', 'Edward Data', 'KT78',
                            'Kitchen Table', '10.00')
    inventory.add_furniture('invoice.csv', 'Alex Gonzales', 'BR02',
                            'Queen Mattress', '17.00')

    with open('invoice.csv', 'r') as file:
        reader = csv.reader(file)
        test_invoice = [line for line in reader]

    invoice = [['Elisa Miles', 'LR04', 'Leather Sofa', '25.00'],
               ['Edward Data', 'KT78', 'Kitchen Table', '10.00'],
               ['Alex Gonzales', 'BR02', 'Queen Mattress', '17.00']]

    assert test_invoice == invoice

    os.remove('invoice.csv')
コード例 #8
0
    def test_add_furniture_should_be_able_to_add_multiple_lines(self):
        """ Create invoice, add many entries """
        # Given
        expected_lines = [
            "Elisa Miles,LR04,Leather Sofa,25\n",
            "Edward Data,KT78,Kitchen Table,10\n",
            "Alex Gonzales,BR02,Queen Mattress,17\n",
        ]
        # When
        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", "BR02",
                      "Queen Mattress", 17)

        actual_lines = []
        with open("./invoices/rented_items.csv", "r") as f:
            for line in f:
                actual_lines.append(line)
        # Then
        self.assertListEqual(expected_lines, actual_lines)