コード例 #1
0
def courier_menu():
    app_utilities.app_title()
    option = app_menu_displays.courier_menu_display()
    if option == '1':
        app_utilities.app_title()
        app_databases.print_table_function('couriers', f'SELECT * FROM couriers')
        input('\nPress Enter to continue. ')
        courier_menu()
    elif option == '2':
        app_utilities.app_title()
        app_databases.add_to_database_function('couriers')
        courier_menu()
    elif option == '3':
        app_utilities.app_title()
        app_databases.update_database_function('couriers')
        courier_menu()
    elif option == '4':
        app_utilities.app_title()
        app_databases.remove_database_function('couriers')
        courier_menu()
    elif option == '5':
        main_menu()
    elif option == '6':
        app_functions.exit_app()
    else:
        app_functions.incorrect_input()
        time.sleep(1)
        product_menu()
コード例 #2
0
    def test_cancel_while_adding_courier_to_database_function(
            self, mock_execute, mock_input, mock_get_column):
        table = 'couriers'
        mock_get_column.return_value = [
            'courier_id', 'courier_name', 'phone_number'
        ]
        mock_input.side_effect = ['Ben', '0']

        add_to_database_function(table)

        self.assertEqual(mock_execute.call_count, 0)
コード例 #3
0
    def test_cancel_while_adding_product_to_database_function(
            self, mock_execute, mock_input, mock_existing_product,
            mock_get_column):
        table = 'products'
        mock_get_column.return_value = [
            'product_id', 'product_name', 'product_price'
        ]
        mock_existing_product.return_value = '0'

        add_to_database_function(table)

        self.assertEqual(mock_execute.call_count, 0)
コード例 #4
0
    def test_add_courier_to_database_function(self, mock_basket, mock_execute,
                                              mock_input, mock_get_column):
        table = 'couriers'
        mock_get_column.return_value = [
            'courier_id', 'courier_name', 'phone_number'
        ]
        mock_input.side_effect = ['Ben', '07123456789']
        expected = 'INSERT INTO couriers (courier_name, phone_number) VALUES ("Ben", "07123456789")'

        add_to_database_function(table)

        mock_execute.assert_called_with(expected)
        self.assertEqual(mock_basket.call_count, 0)
コード例 #5
0
    def test_cancel_while_adding_order_to_database_function(
            self, mock_basket, mock_execute, mock_existing_courier, mock_input,
            mock_get_column):
        table = 'orders'
        mock_get_column.return_value = [
            'order_id', 'customer_name', 'customer_number', 'customer_address',
            'status', 'courier_id'
        ]
        mock_existing_courier.return_value = '0'
        mock_input.side_effect = ['ABC', '123', '12Highst']

        add_to_database_function(table)

        self.assertEqual(mock_execute.call_count, 0)
コード例 #6
0
    def test_add_order_to_database_function(self, mock_basket, mock_execute,
                                            mock_existing_courier, mock_input,
                                            mock_get_column):
        table = 'orders'
        mock_get_column.return_value = [
            'order_id', 'customer_name', 'customer_number', 'customer_address',
            'status', 'courier_id'
        ]
        mock_existing_courier.return_value = '12'
        mock_input.side_effect = ['ABC', '123', '12Highst']
        expected = 'INSERT INTO orders (customer_name, customer_number, customer_address, status, courier_id) VALUES ("Abc", "123", "12Highst", "Preparing", "12")'
        mock_basket.return_value = ['1']
        add_to_database_function(table)

        mock_execute.assert_called_with(expected)
        self.assertEqual(mock_basket.call_count, 1)
コード例 #7
0
    def test_add_product_to_database_function(self, mock_basket, mock_execute,
                                              mock_input,
                                              mock_existing_product,
                                              mock_get_column):
        table = 'products'
        mock_get_column.return_value = [
            'product_id', 'product_name', 'product_price'
        ]
        mock_existing_product.return_value = 'Orange'
        mock_input.return_value = '4.3'
        expected = 'INSERT INTO products (product_name, product_price) VALUES ("Orange", "4.3")'

        add_to_database_function(table)

        mock_execute.assert_called_with(expected)
        self.assertEqual(mock_basket.call_count, 0)
コード例 #8
0
    def test_catches_error_thrown_with_large_value_add_product_to_database_function(
            self, mock_print, mock_execute, mock_input, mock_existing_product,
            mock_get_column):
        table = 'products'
        mock_get_column.return_value = [
            'product_id', 'product_name', 'product_price'
        ]
        mock_existing_product.return_value = 'Orange'
        mock_input.return_value = '999999.99'

        mock_execute.side_effect = pymysql.err.DataError()

        add_to_database_function(table)

        mock_print.assert_called_with(
            'The data entered was out of range of the column. Returning to previous screen.'
        )
コード例 #9
0
def order_menu():
    app_utilities.app_title()
    option = app_menu_displays.order_menu_display()
    if option == '1':
        app_utilities.app_title()
        app_databases.print_table_function('orders', f'SELECT * FROM orders')
        print('\nTo see the products ordered for a customer,\n')
        id = app_databases.choose_an_existing_id('orders')
        if id == '0':
            order_menu()
        print('')
        customer_order = app_databases.read_from_database(f'SELECT p.product_id, p.product_name, p.product_price FROM customer_orders c JOIN products p ON c.product_id = p.product_id WHERE c.order_id = {id}')
        app_databases.print_order_table(customer_order) 
        input('\nPress Enter to continue.')       
        order_menu()
    elif option == '2':
        app_utilities.app_title()
        app_databases.add_to_database_function('orders')
        order_menu()
    elif option == '3':
        app_utilities.app_title()
        app_databases.update_order_status()
        order_menu()
    elif option == '4':
        app_utilities.app_title()
        app_databases.update_database_function('orders')
        order_menu()
    elif option == '5':
        app_utilities.app_title()
        app_databases.update_basket()
        order_menu()
    elif option == '6':
        app_utilities.app_title()
        app_databases.remove_database_function('orders')
        order_menu()
    elif option == '7':
        main_menu()
    elif option == '8':
        app_functions.exit_app()
    else:
        app_functions.incorrect_input()
        time.sleep(1)
        order_menu()