Beispiel #1
0
def test_menu_add_user_true(collection):
    menu.user_collection = collection
    with patch('menu.input') as mock_input:
        mock_input.side_effect = ['ted', 'ted', 'ted', 'ted']
        menu.add_user()

        assert menu.user_collection.database['ted'].email == 'ted'
Beispiel #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()
Beispiel #3
0
def test_menu_add_user_false(collection):
    menu.user_collection = collection
    menu.user_collection.database['ted'] = 'exists'
    with patch('menu.input') as mock_input:
        mock_input.side_effect = ['ted', 'ted', 'ted', 'ted']
        menu.add_user()

        assert menu.user_collection.database['ted'] == 'exists'
Beispiel #4
0
def test_menu(mocked_print, mocked_input):
    '''
    Integration test script for menu.py
    '''
    # Setup menu for testing
    mocked_input.side_effect = selections
    # 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
Beispiel #5
0
def test_menu(mocked_print, mocked_input):
    '''
    Integration test script for menu.py
    '''
    # Drop tables for clean testing
    db_conn = sql.DBConnection()
    with db_conn as conn:
        conn.social.UserTable.drop()
        conn.social.StatusTable.drop()
    # 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