コード例 #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_cancelling_out_of_update_database_function(
            self, mock_execute, mock_input, mock_id, mock_get_column):
        table = 'couriers'
        mock_get_column.return_value = [
            'courier_id', 'courier_name', 'phone_number'
        ]
        mock_id.return_value = '0'

        update_database_function(table)

        self.assertEqual(mock_execute.call_count, 0)
コード例 #3
0
    def test_update_database_function_with_orders_first_loop_expected(
            self, mock_execute, mock_input, mock_id, mock_get_column):
        table = 'orders'
        mock_get_column.return_value = [
            'order_id', 'customer_name', 'customer_number', 'customer_address',
            'status', 'courier_id'
        ]
        mock_id.return_value = '1'
        mock_input.side_effect = ['Richard', '', '', '']
        expected = 'UPDATE orders SET customer_name = "Richard" WHERE order_id = 1'

        update_database_function(table)

        mock_execute.assert_called_with(expected)
        self.assertEqual(mock_execute.call_count, 1)
コード例 #4
0
    def test_update_database_function_with_orders_without_passes(
            self, mock_execute, mock_input, mock_id, mock_get_column):
        table = 'orders'
        mock_get_column.return_value = [
            'order_id', 'customer_name', 'customer_number', 'customer_address',
            'status', 'courier_id'
        ]
        mock_id.return_value = '1'
        mock_input.side_effect = ['Richard', '07123456789', '123 Main St', '2']
        expected = 'UPDATE orders SET courier_id = "2" WHERE order_id = 1'

        update_database_function(table)

        mock_execute.assert_called_with(expected)
        self.assertEqual(mock_execute.call_count, 4)
コード例 #5
0
    def test_update_database_function_with_couriers(self, mock_execute,
                                                    mock_input, mock_id,
                                                    mock_get_column):
        table = 'couriers'
        mock_get_column.return_value = [
            'courier_id', 'courier_name', 'phone_number'
        ]
        mock_id.return_value = '1'
        mock_input.side_effect = ['', '07123456789']
        expected = 'UPDATE couriers SET phone_number = "07123456789" WHERE courier_id = 1'

        update_database_function(table)

        mock_execute.assert_called_with(expected)
        self.assertEqual(mock_execute.call_count, 1)
コード例 #6
0
    def test_update_database_function_with_products(self, mock_execute,
                                                    mock_input, mock_id,
                                                    mock_get_column):
        table = 'products'
        mock_get_column.return_value = [
            'product_id', 'product_name', 'product_price'
        ]
        mock_id.return_value = '1'
        mock_input.side_effect = ['', '2.50']
        expected = 'UPDATE products SET product_price = "2.50" WHERE product_id = 1'

        update_database_function(table)

        mock_execute.assert_called_with(expected)
        self.assertEqual(mock_execute.call_count, 1)
コード例 #7
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()