Exemple #1
0
def test_menu(mocked_print, mocked_input):
    '''
    Integration test script for menu.py
    '''
    # Setup menu for testing
    mocked_input.side_effect = selections
    menu.user_collection = menu.main.init_user_collection()
    menu.status_collection = menu.main.init_status_collection()
    # Test Users related functions
    menu.load_users()
    menu.add_user()
    mocked_print.assert_called_with(responces[0])  # add_user()
    menu.add_user()
    mocked_print.assert_called_with(responces[1])  # add_user() error
    menu.update_user()
    mocked_print.assert_called_with(responces[2])  # update_user()
    menu.update_user()
    mocked_print.assert_called_with(responces[3])  # update_user() error
    menu.search_user()
    mocked_print.assert_called_with(responces[4])  # search_user()
    menu.search_user()
    mocked_print.assert_called_with(responces[5])  # search_user() error
    menu.delete_user()
    mocked_print.assert_called_with(responces[6])  # delete_user()
    menu.delete_user()
    mocked_print.assert_called_with(responces[7])  # delete_user() error
    # Test UserStatus related functions
    menu.add_user()
    mocked_print.assert_called_with(responces[8])  # add_user() for status
    menu.load_status_updates()
    menu.add_status()
    mocked_print.assert_called_with(responces[9])  # add_status()
    menu.add_status()
    mocked_print.assert_called_with(responces[10])  # add_status() error
    menu.update_status()
    mocked_print.assert_called_with(responces[11])  # update_status()
    menu.update_status()
    mocked_print.assert_called_with(responces[12])  # update_status() error
    menu.search_status()
    mocked_print.assert_called_with(responces[13])  # search_status()
    menu.search_status()
    mocked_print.assert_called_with(responces[14])  # search_status() error
    menu.delete_status()
    mocked_print.assert_called_with(responces[15])  # delete_status()
    menu.delete_status()
    mocked_print.assert_called_with(responces[16])  # delete_status() error
    # Test cascading deletes
    menu.add_status()
    mocked_print.assert_called_with(responces[17])  # add_status()
    menu.delete_user()
    mocked_print.assert_called_with(responces[18])  # delete_user()
    menu.search_status()
    mocked_print.assert_called_with(responces[19])  # search_status() error
    # Test table restrictions
    menu.add_user()
    mocked_print.assert_called_with(responces[20])  # add_user() error
    menu.add_user()
    mocked_print.assert_called_with(responces[21])  # add_user() error
    menu.add_user()
    mocked_print.assert_called_with(responces[22])  # add_user() error
Exemple #2
0
def test_menu(mocked_reader, mocked_writer, mocked_print, mocked_input):
    '''
    Integration test script for menu.py
'''
    # Setup menu for testing
    mocked_input.side_effect = selections
    mocked_writer.return_value = Mock()
    menu.user_collection = menu.main.init_user_collection()
    menu.status_collection = menu.main.init_status_collection()
    # Test Users related functions
    menu.load_users()
    mocked_reader.assert_called_once()
    menu.add_user()
    mocked_print.assert_called_with(responces[0])
    assert menu.user_collection.database['dave03'].email == selections[2]
    menu.add_user()
    mocked_print.assert_called_with(responces[1])
    menu.update_user()
    mocked_print.assert_called_with(responces[2])
    assert menu.user_collection.database['dave03'].email == selections[10]
    menu.update_user()
    mocked_print.assert_called_with(responces[3])
    menu.search_user()
    mocked_print.assert_called_with(responces[4])
    menu.search_user()
    mocked_print.assert_called_with(responces[5])
    menu.delete_user()
    mocked_print.assert_called_with(responces[6])
    assert menu.user_collection.database == dict()
    menu.delete_user()
    mocked_print.assert_called_with(responces[7])
    menu.save_users()
    mocked_writer.assert_called_once()
    mocked_writer.return_value.writerow.assert_called_once()
    # Reset mocks for UserStatus tests
    mocked_reader.reset_mock()
    mocked_writer.reset_mock()
    # Test UserStatus related functions
    menu.load_status_updates()
    mocked_reader.assert_called_once()
    menu.add_status()
    mocked_print.assert_called_with(responces[8])
    menu.add_status()
    mocked_print.assert_called_with(responces[9])
    menu.update_status()
    mocked_print.assert_called_with(responces[10])
    menu.update_status()
    mocked_print.assert_called_with(responces[11])
    menu.search_status()
    mocked_print.assert_called_with(responces[12])
    menu.search_status()
    mocked_print.assert_called_with(responces[13])
    menu.delete_status()
    mocked_print.assert_called_with(responces[14])
    menu.delete_status()
    mocked_print.assert_called_with(responces[15])
    menu.save_status()
    mocked_writer.assert_called_once()
    mocked_writer.return_value.writerow.assert_called_once()
Exemple #3
0
def test_menu_delete_status_false(collection):
    expected = "call('An error occurred while trying to delete status')"
    menu.user_collection = collection

    with patch('builtins.print') as mock_print:
        with patch('menu.input') as mock_input:
            mock_input.side_effect = ['Cool_kid187']
            menu.delete_status()

    print(str(mock_print.call_args))
    with pytest.raises(KeyError):
        print(menu.user_collection.database['Cool_kid187'])
    assert str(mock_print.call_args) == expected
Exemple #4
0
def test_menu_delete_status_true(impeach, status_collection):
    menu.status_collection = status_collection
    menu.status_collection.database['XKPiC6*iW!H3#6'] = impeach
    expected = "call('Status was successfully deleted')"

    with patch('builtins.print') as mock_print:
        with patch('menu.input') as mock_input:
            mock_input.side_effect = ['XKPiC6*iW!H3#6', 'ted', 'ted', 'ted']
            menu.delete_status()

    with pytest.raises(KeyError):
        print(menu.status_collection.database['XKPiC6*iW!H3#6'])
    print(str(mock_print.call_args))
    assert str(mock_print.call_args) == expected