def test_standup_active_invalid_channel(): """Tests passing an invalid channel name into standup_active""" clear() new_user = auth_register("*****@*****.**", "validPassword", "Validate", "Me") with pytest.raises(InputError): standup_active(new_user["token"], 123421)
def test_standup_send_handle(): """ Tests if standup_start and standup_send works. """ clear() user1 = auth.auth_register("*****@*****.**", "password", "Bilbo", "Baggins") channel_dict = channels.channels_create(user1['token'], "test_channel", True) user.user_profile_sethandle(user1['token'], 'handle') standup.standup_start(user1['token'], channel_dict['channel_id'], 3) standup.standup_send(user1['token'], channel_dict['channel_id'], "message1") time.sleep(5) standup.standup_active(user1['token'], channel_dict['channel_id']) message_dict = channel.channel_messages(user1['token'], channel_dict['channel_id'], 0) assert message_dict['messages'][0]['message'] == ("handle: message1") user.user_profile_sethandle(user1['token'], 'eren') standup.standup_start(user1['token'], channel_dict['channel_id'], 3) standup.standup_send(user1['token'], channel_dict['channel_id'], "message1") time.sleep(5) standup.standup_active(user1['token'], channel_dict['channel_id']) message_dict = channel.channel_messages(user1['token'], channel_dict['channel_id'], 0) assert message_dict['messages'][0]['message'] == ("eren: message1")
def test_standup_active_valid(): ''' Test validly checking if a standup is active ''' clear() f_owner = auth_register('*****@*****.**', 'password', 'Flockr', 'Owner') f_channel = channels_create(f_owner['token'], 'Test Channel', True) # Check standup_active returns correct values with no active standup standup_details = standup_active(f_owner['token'], f_channel['channel_id']) assert standup_details['is_active'] is False assert standup_details['time_finish'] is None # Start standup for 5 seconds t_finish1 = standup_start(f_owner['token'], f_channel['channel_id'], 5)['time_finish'] # Check standup_active returns correct values during a standup standup_details = standup_active(f_owner['token'], f_channel['channel_id']) assert standup_details['is_active'] is True # Check that time_finish of both standup_start and standup_active are the same t_finish2 = standup_details['time_finish'] assert t_finish1 == t_finish2 # Check standup_active returns correct values after standup ends time.sleep(6) standup_details = standup_active(f_owner['token'], f_channel['channel_id']) assert standup_details['is_active'] is False assert standup_details['time_finish'] is None
def test_standup_start1(): """ Tests if standup_start and standup_send works. """ clear() user1 = auth.auth_register("*****@*****.**", "password", "Bilbo", "Baggins") user2 = auth.auth_register("*****@*****.**", "password", "Frodo", "Baggins") user3 = auth.auth_register("*****@*****.**", "password", "Master", "Sauron") channel_dict = channels.channels_create(user1['token'], "test_channel", True) channel.channel_join(user2['token'], channel_dict['channel_id']) channel.channel_join(user3['token'], channel_dict['channel_id']) standup.standup_start(user1['token'], channel_dict['channel_id'], 3) standup.standup_send(user1['token'], channel_dict['channel_id'], "message1") standup.standup_send(user2['token'], channel_dict['channel_id'], "message2") standup.standup_send(user3['token'], channel_dict['channel_id'], "message3") time.sleep(5) standup.standup_active(user1['token'], channel_dict['channel_id']) message_dict = channel.channel_messages(user1['token'], channel_dict['channel_id'], 0) assert len(message_dict['messages']) == 1 assert message_dict['messages'][0]['message'] == ("bilbobaggins: message1\n" + "frodobaggins: message2\n" + "mastersauron: message3")
def test_standup_active_usernotinchannel(): clear() channels = getChannelData() #Registering a user register = auth_register('*****@*****.**', '123abc!@#', 'Hayden', 'Everest', None) #Storing token generated from registration process in a variable for easy access creator_token = register['token'] #Using the registered user to create a channel new_channel = channels_create(creator_token, "Testing Channel", True) #Storing channel_id generated from channel creation in a variable for easy access channel_id = new_channel['channel_id'] for channel in channels: if channel['channel_id'] == channel_id: assert channel['is_standup'] == False standup_start(creator_token, channel_id, 3) for channel in channels: if channel['channel_id'] == channel_id: assert channel['is_standup'] == True #Registering a user register1 = auth_register('*****@*****.**', '!!!123abc!@#', 'Howard', 'Fog', None) #Storing token generated from registration process in a variable for easy access another_token = register1['token'] with pytest.raises(AccessError): standup_active(another_token, channel_id)
def test_standup_whole(): time.sleep(5) _, wenyao_dict, _, channel_team1, _ = initialise_data() # start standup standup_start(wenyao_dict['token'], channel_team1['channel_id'], 5) # check if standup is active is_active = standup_active(wenyao_dict['token'], channel_team1['channel_id'])['is_active'] assert is_active == True standup_send(wenyao_dict['token'], channel_team1['channel_id'], "Hi") time.sleep(1) standup_send(wenyao_dict['token'], channel_team1['channel_id'], "Hello") # sleep for 5s time.sleep(5) # check if standup is active is_active = standup_active(wenyao_dict['token'], channel_team1['channel_id'])['is_active'] assert is_active == False # get handle wenyao_profile = user_profile(wenyao_dict['token'], wenyao_dict['u_id']) handle = wenyao_profile['user']['handle_str'] # check the return value for channel_message message_dict = channel_messages(wenyao_dict['token'], channel_team1['channel_id'], 0) msg = handle + ': ' + "Hi" + '\n' + handle + ': ' + "Hello" assert message_dict['messages'][0]['message'] == msg
def test_active_error_invalid_channel(initial_data): ''' error test when given channel_id is invalid channel_id does not exist ''' # non-existing channel with id 0 with pytest.raises(InputError): standup_active(users[0]['token'], 0)
def test_standup_active_invalid_channel(create_owner_with_channel_and_user): ''' Exception test for when an invalid channel is passed through ''' owner = create_owner_with_channel_and_user['owner'] with pytest.raises(InputError): standup.standup_active(owner['token'], 9999)
def test_active_output3(): clear() user = auth.auth_register("*****@*****.**", "password", "First", "Last") channel = channels.channels_create(user['token'], "name", True) standup.standup_start(user['token'], channel["channel_id"], 3) assert standup.standup_active(user['token'], channel['channel_id']).get('is_active') == True time.sleep(4) assert standup.standup_active(user['token'], channel['channel_id']).get('is_active') == False
def test_standup_active_invalid_token(): """Tests passing an invalid token to standup_active""" clear() valid_user = auth_register("*****@*****.**", "validPassword", "Validate", "Me") new_channel = channels_create(valid_user["token"], "invalid_channel", False) with pytest.raises(AccessError): standup_active(90000, new_channel["channel_id"])
def test_active_inavalid_channel_id(): """ Tests if standup_active returns an input error if a invalid channel_id is given """ test_user1 = auth.auth_register("*****@*****.**", "password", "Optimus", "Prime") with pytest.raises(InputError): standup.standup_active(test_user1["token"], 1) other.clear()
def test_standup_active_not_member(): Benjamin, _, _, James, channel_id0, _ = initialisation() # Standup should last for 2 seconds standup_start(Benjamin['token'], channel_id0['channel_id'], 2) time.sleep(1) with pytest.raises(error.AccessError): standup_active(James['token'], channel_id0['channel_id']) time.sleep(1.5) with pytest.raises(error.AccessError): standup_active(James['token'], channel_id0['channel_id'])
def test_standup_send_morethan1000(): time.sleep(5) _, wenyao_dict, _, channel_team1, _ = initialise_data() standup_start(wenyao_dict['token'], channel_team1['channel_id'], 5) standup_active(wenyao_dict['token'], channel_team1['channel_id']) letters = string.ascii_lowercase # random a string with length 1001 message_str = ''.join(random.choice(letters) for i in range(1001)) with pytest.raises(InputError): assert standup_send(wenyao_dict['token'], channel_team1['channel_id'], message_str)
def test_standup_active_invalid_channel_id(): clear() user1 = register_n_users(1) channel = channels_create(user1["token"], "channel1", is_public=True) standup_start(user1["token"], channel["channel_id"], 1) invalid_channel_id = -1 with pytest.raises(InputError): standup_active(user1["token"], invalid_channel_id)
def test_active_standupactive_channel(): ''' If standup is active ''' clear() user = auth.auth_register("*****@*****.**", "password", "First", "Last") channel = channels.channels_create(user['token'], "name", True) standup.standup_start(user['token'], channel["channel_id"], 4) with pytest.raises(error.InputError): standup.standup_active(user['token'], "channel_id")
def test_standup_active_nvid(): """ Tests if standup_active raises an InputError if the channel_id given is invalid. """ user = auth.auth_register("*****@*****.**", "password", "Just", "Monika") channel_dict = channels.channels_create(user['token'], "test_channel", False) standup.standup_start(user['token'], channel_dict['channel_id'], 1) with pytest.raises(error.InputError): standup.standup_active(user['token'], 100) time.sleep(1)
def test_standup_active_nvt(): """ Tests if standup_active raises an AccessError if the token given is invalid. """ user = auth.auth_register("*****@*****.**", "password", "Bat", "Man") channel_dict = channels.channels_create(user['token'], "test_channel", False) standup.standup_start(user['token'], channel_dict['channel_id'], 1) with pytest.raises(error.AccessError): standup.standup_active("InvalidToken", channel_dict['channel_id']) time.sleep(1)
def standup_active_invalidChannelID(register): auth_logout(register[0]['token']) auth_logout(register[1]['token']) login_return = auth_login("*****@*****.**", "myunsw") login_return2 = auth_login("*****@*****.**", "mygmail") channel = channels_create(login_return['token'], "Test Channel 0", True) u_id = login_return['u_id'] token = login_return['token'] standup_start(token, channel['channel_id'], 20) with pytest.raises(ValueError): standup_active(token, 20), "Channel (based on ID) does not exist"
def test_active_error_invalid_token(initial_data): ''' error test when given token is invalid 1. non-existing 2. logout token ''' # 1. non-existing token with pytest.raises(AccessError): standup_active('invalid-token', channels[0]['channel_id']) # 2. user1 logout token with pytest.raises(AccessError): standup_active(token_generate(0, 'logout'), channels[0]['channel_id'])
def test_active_standupactive_token(): ''' If standup token is invalid ''' clear() user = auth.auth_register("*****@*****.**", "password", "First", "Last") channel = channels.channels_create(user['token'], "name", True) standup.standup_start(user['token'], channel["channel_id"], 2) with pytest.raises(error.AccessError): standup.standup_active('token', channel["channel_id"]) time.sleep(3)
def test_standup_active_invalid_inputs(): ''' Test basic error raising from invalid inputs ''' clear() user = auth_register("*****@*****.**", "password", "Firstname", "Lastname") channel = channels_create(user['token'], "Channel", True) # invalid token raises AccessError with pytest.raises(AccessError): standup_active("notToken", channel['channel_id']) # invalid channel_id raises InputError with pytest.raises(InputError): standup_active(user['token'], -1)
def test_active_not_in_channel(): """ Tests if standup_active returns an access error when called by a user not in the channel """ channel_creater = auth.auth_register("*****@*****.**", "password", "Quick", "Shadow") test_user1 = auth.auth_register("*****@*****.**", "password", "Optimus", "Prime") test_channel_id1 = channels.channels_create(channel_creater["token"], "test1", True) standup.standup_start(channel_creater["token"], test_channel_id1["channel_id"], 1) with pytest.raises(AccessError): standup.standup_active(test_user1["token"], test_channel_id1["channel_id"]) other.clear()
def test_active_standard(initial_data): ''' user1 calls start in channel_1 user1 calls active in channel_1 user3 calls active in channel_2 ''' standup_start(users[0]['token'], channels[0]['channel_id'], 2) curr_time = int(time.time()) # chanenl 1 active_info = standup_active(users[0]['token'], channels[0]['channel_id']) assert active_info['is_active'] is True assert active_info['time_finish'] == curr_time + 2 # channel 2 active_info = standup_active(users[2]['token'], channels[1]['channel_id']) assert active_info['is_active'] is False assert active_info['time_finish'] is None
def active(): """ Checks whether standup is active using http """ token = request.args.get("token") channel_id = convert_to_int(request.args.get("channel_id")) return standup.standup_active(token, channel_id)
def test_standup_active_basecase(): clear() channels = getChannelData() #Registering a user register = auth_register('*****@*****.**', '123abc!@#', 'Hayden', 'Everest', None) #Storing token generated from registration process in a variable for easy access creator_token = register['token'] #Using the registered user to create a channel new_channel = channels_create(creator_token, "Testing Channel", True) #Storing channel_id generated from channel creation in a variable for easy access channel_id = new_channel['channel_id'] for channel in channels: if channel['channel_id'] == channel_id: assert channel['is_standup'] == False standup_start(creator_token, channel_id, 3) for channel in channels: if channel['channel_id'] == channel_id: assert channel['is_standup'] == True res = standup_active(creator_token, channel_id) assert len(res) == 2
def test_standup_active_none_active(): """Tests the return value (should be None) when there is no standup active""" clear() valid_user = auth_register("*****@*****.**", "validPassword", "Validate", "Me") new_channel = channels_create(valid_user["token"], "new_channel", False) result = standup_active(valid_user["token"], new_channel["channel_id"]) assert result == {'is_active': False, 'time_finish': None}
def test_standup_active_active_in_another_channel(): ''' Test that standup active returns false in one channel, if a standup is active in another (Channels should be independent) ''' clear() user = auth_register("*****@*****.**", "password", "Firstname", "Lastname") channel1 = channels_create(user['token'], "Channel1", True) channel2 = channels_create(user['token'], "Channel2", True) standup_start(user['token'], channel1['channel_id'], 1) result1 = standup_active(user['token'], channel1['channel_id']) result2 = standup_active(user['token'], channel2['channel_id']) assert result1['is_active'] == True assert result2['is_active'] == False time.sleep(2)
def test_standup_active_inactive(): reset_data() member = auth_register('*****@*****.**', 'helloworld', 'firstname', 'lastname') channel_id = channels_create(member['token'], 'New Channel', True)['channel_id'] assert standup_active(member['token'], channel_id) == { 'is_active': False, 'time_finish': None }
def test_standup_active_standup_not_active(): ''' Test that when a standup is not active standup active returns False, and None ''' clear() user = auth_register("*****@*****.**", "password", "Firstname", "Lastname") channel = channels_create(user['token'], "Channel", True) check = standup_active(user['token'], channel['channel_id']) assert check['is_active'] == False assert check['time_finish'] == None standup_start(user['token'], channel['channel_id'], 1) time.sleep(2) check = standup_active(user['token'], channel['channel_id']) assert check['is_active'] == False assert check['time_finish'] == None
def test_standup_active_invalidchannelid(): clear() channels = getChannelData() #Registering a user register = auth_register('*****@*****.**', '123abc!@#', 'Hayden', 'Everest', None) #Storing token generated from registration process in a variable for easy access creator_token = register['token'] #Using the registered user to create a channel new_channel = channels_create(creator_token, "Testing Channel", True) #Storing channel_id generated from channel creation in a variable for easy access channel_id = new_channel['channel_id'] for channel in channels: if channel['channel_id'] == channel_id: assert channel['is_standup'] == False with pytest.raises(InputError): standup_active(creator_token, channel_id*100)