def test_two_tags(): clear_v1() user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng") user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton") channel1 = channels_create_v2(user1['token'], 'Channel 1', True) channel_join_v2(user2['token'], channel1['channel_id']) msg1str = "@ericzheng @joshhatton" message_send_v2(user1['token'], channel1['channel_id'], msg1str) assert notifications_get_v1(user1['token']) == { 'notifications': [{ 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': f"ericzheng tagged you in Channel 1: {msg1str[0:20]}" }] } assert notifications_get_v1(user2['token']) == { 'notifications': [{ 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': f"ericzheng tagged you in Channel 1: {msg1str[0:20]}" }] }
def test_invalid_token(): """ Tests return of expected output when given a token that doesn't exist, or if the user is not in the channel/dm. """ clear_v1() # Token doesnt exist user_1 = auth_register_v2('*****@*****.**', 'happydays1', 'Eric', 'Zheng') with pytest.raises(AccessError): notifications_get_v1(user_1['token'] + 'bug') # User not in channel user_2 = auth_register_v2('*****@*****.**', 'happydays2', 'Josh', 'Hatton') channel_1 = channels_create_v2(user_1['token'], 'Channel 1', True) user_2_handle = user_profile_v2(user_1['token'], user_2['auth_user_id']) message_send_v2(user_1['token'], channel_1['channel_id'], f"Hi @{user_2_handle['user']['handle_str']}") assert notifications_get_v1(user_2['token']) == {'notifications': []} # User not in dm dm_1 = dm_create_v1(user_1['token'], [user_2['auth_user_id']]) user_3 = auth_register_v2('*****@*****.**', 'hihihi!!!', 'Bunny', 'Dong') user_3_handle = user_profile_v2(user_1['token'], user_3['auth_user_id']) message_senddm_v1(user_1['token'], dm_1['dm_id'], f"Hello @{user_3_handle['user']['handle_str']}") assert notifications_get_v1(user_3['token']) == {'notifications': []}
def test_add_channel(test_data): a_data, b_data, c_data, a_ch_id = test_data b_ch_id = channels_create_v2(b_data['token'], 'Channel 2', True)['channel_id'] # ADD TO CHANNEL channel_invite_v2(a_data["token"], a_ch_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 1 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } sleep(1) channel_invite_v2(b_data["token"], b_ch_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 2 assert notifs[0] == { "channel_id": b_ch_id, "dm_id": -1, "notification_message": "bobbobinson added you to Channel 2" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } sleep(1)
def test_assorted_notifications(): clear_v1() user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng") user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton") channel1 = channels_create_v2(user1['token'], 'Channel 1', True) channel_invite_v2(user1['token'], channel1['channel_id'], user2['auth_user_id']) msg1str = "Welcome to the channel @joshhatton" msg1 = message_send_v2(user1['token'], channel1['channel_id'], msg1str) message_react_v1(user2['token'], msg1['message_id'], 1) msg2str = "Thanks for having me @ericzheng" msg2 = message_send_v2(user2['token'], channel1['channel_id'], msg2str) message_react_v1(user1['token'], msg2['message_id'], 1) assert notifications_get_v1(user1['token']) == { 'notifications': [{ 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': f"joshhatton tagged you in Channel 1: {msg2str[0:20]}" }, { 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': "joshhatton reacted to your message in Channel 1" }] } assert notifications_get_v1(user2['token']) == { 'notifications': [ { 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': "ericzheng reacted to your message in Channel 1" }, { 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': f"ericzheng tagged you in Channel 1: {msg1str[0:20]}" }, { 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': "ericzheng added you to Channel 1" }, ] }
def test_tag_edit(): clear_v1() user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng") user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton") channel1 = channels_create_v2(user1['token'], 'Channel 1', True) channel_join_v2(user2['token'], channel1['channel_id']) msg1str = "Hi friend" msg1 = message_send_v2(user1['token'], channel1['channel_id'], msg1str) assert len(notifications_get_v1(user2['token'])['notifications']) == 0 message_edit_v2(user1['token'], msg1['message_id'], "@joshhatton") assert len(notifications_get_v1(user2['token'])['notifications']) == 1
def test_tag_sendlaterdm(): clear_v1() user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng") user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton") dm1 = dm_create_v1(user1['token'], [user2['auth_user_id']]) msg1str = "@joshhatton sup" current_time = int(time.time()) message_sendlaterdm_v1(user1['token'], dm1['dm_id'], msg1str, current_time + 2) assert len(notifications_get_v1(user2['token'])['notifications']) == 1 time.sleep(3) assert len(notifications_get_v1(user2['token'])['notifications']) == 2
def test_tag_sendlater(): clear_v1() user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng") user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton") channel1 = channels_create_v2(user1['token'], 'Channel 1', True) channel_join_v2(user2['token'], channel1['channel_id']) msg1str = "@joshhatton sup" current_time = int(time.time()) message_sendlater_v1(user1['token'], channel1['channel_id'], msg1str, current_time + 2) assert len(notifications_get_v1(user2['token'])['notifications']) == 0 time.sleep(3) assert len(notifications_get_v1(user2['token'])['notifications']) == 1
def test_single_dm_tag(reg_user, u_handle, crt_channel, tag_dm): clear_v2() user_1_token = reg_user(0)['token'] user_2 = reg_user(1) dm = dm_create_v1(user_1_token, [user_2['auth_user_id']]) dm_text = tag_dm(user_1_token, dm, 0, 1, 0) notifs = notifications_get_v1(user_2['token'])['notifications'] assert len(notifs) == 2 notif = notifs[0] assert notif['channel_id'] == -1 assert notif['dm_id'] == dm['dm_id'] assert notif['notification_message'] == dm_text
def test_single_channel_add(reg_user, u_handle, crt_channel, ch_add_str): clear_v2() user_1_token = reg_user(0)['token'] user_2 = reg_user(1) channel_id = crt_channel(user_1_token, 0)['channel_id'] channel_invite_v2(user_1_token, channel_id, user_2['auth_user_id']) notifs = notifications_get_v1(user_2['token'])['notifications'] assert len(notifs) == 1 notif = notifs[0] assert notif['channel_id'] == channel_id assert notif['dm_id'] == -1 assert notif['notification_message'] == ch_add_str(u_handle(0), 0)
def test_no_notifications(): """ Assume that notifications_get_v1 returns an empty dictionary of list when there are no notifiactions to display """ clear_v1() user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng") user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton") user_3 = auth_register_v2("*****@*****.**", "anotherpassword", "Bunny", "Dong") user_4 = auth_register_v2("*****@*****.**", "password3", "Jordan", "Milch") user_5 = auth_register_v2("*****@*****.**", "4thpassword", "Dean", "Zworestine") assert notifications_get_v1(user_1['token']) == {'notifications': []} assert notifications_get_v1(user_2['token']) == {'notifications': []} assert notifications_get_v1(user_3['token']) == {'notifications': []} assert notifications_get_v1(user_4['token']) == {'notifications': []} assert notifications_get_v1(user_5['token']) == {'notifications': []}
def test_single_channel_tag(reg_user, u_handle, crt_channel, tag_message): clear_v2() user_1_token = reg_user(0)['token'] user_2 = reg_user(1) channel_id = crt_channel(user_1_token, 0)['channel_id'] channel_invite_v2(user_1_token, channel_id, user_2['auth_user_id']) message_text = tag_message(user_1_token, channel_id, 0, 0, 1, 0) notifs = notifications_get_v1(user_2['token'])['notifications'] assert len(notifs) == 2 notif = notifs[0] assert notif['channel_id'] == channel_id assert notif['dm_id'] == -1 assert notif['notification_message'] == message_text
def test_add_dm(test_data): # ADD TO DM a_data, b_data, c_data, _ = test_data a_dm_id = dm_create_v1(a_data['token'], [b_data['auth_user_id']])['dm_id'] b_dm_id = dm_create_v1(b_data['token'], [a_data['auth_user_id']])['dm_id'] dm_invite_v1(b_data["token"], b_dm_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 1 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } sleep(1) dm_invite_v1(a_data["token"], a_dm_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 2 assert notifs[0] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson added you to andyanderson, bobbobinson" } assert notifs[1] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" }
def test_more_than_twenty_dm_tag(reg_user, u_handle, crt_channel, tag_dm): clear_v2() user_1_token = reg_user(0)['token'] user_2 = reg_user(1) dm = dm_create_v1(user_1_token, [user_2['auth_user_id']]) dm_count = 21 dms_texts = [] for i in range(dm_count): dms_texts.append(tag_dm(user_1_token, dm, 0, 1, i)) notifs = notifications_get_v1(user_2['token'])['notifications'] assert len(notifs) == dm_count - 1 for i in reversed(range(dm_count - 1)): assert notifs[i]['channel_id'] == -1 assert notifs[i]['dm_id'] == dm['dm_id'] assert notifs[i]['notification_message'] == dms_texts[i + 1]
def test_twenty_channel_tag(reg_user, u_handle, crt_channel, tag_message): clear_v2() user_1_token = reg_user(0)['token'] user_2 = reg_user(1) channel_id = crt_channel(user_1_token, 0)['channel_id'] channel_invite_v2(user_1_token, channel_id, user_2['auth_user_id']) message_count = 20 messages_texts = [] for i in range(message_count): messages_texts.append(tag_message(user_1_token, channel_id, 0, 0, 1, i)) notifs = notifications_get_v1(user_2['token'])['notifications'] assert len(notifs) == message_count for i in reversed(range(message_count)): assert notifs[i]['channel_id'] == channel_id assert notifs[i]['dm_id'] == -1 assert notifs[i]['notification_message'] == messages_texts[i]
def test_more_than_twenty_channel_adds(reg_user, u_handle, crt_channel, ch_add_str): clear_v2() user_1_token = reg_user(0)['token'] user_2 = reg_user(1) add_count = 21 channel_ids = [] for i in range(add_count): channel_id = crt_channel(user_1_token, i)['channel_id'] channel_invite_v2(user_1_token, channel_id, user_2['auth_user_id']) channel_ids.append(channel_id) channel_ids.reverse() notifs = notifications_get_v1(user_2['token'])['notifications'] assert len(notifs) == add_count - 1 for i in range(len(notifs)): assert notifs[i]['channel_id'] == channel_ids[i] assert notifs[i]['dm_id'] == -1 assert notifs[i]['notification_message'] == ch_add_str( u_handle(0), 20 - i)
def test_no_notifs(test_data): a_data, b_data, c_data, a_ch_id = test_data b_dm_id = dm_create_v1( b_data['token'], [a_data['auth_user_id'], c_data['auth_user_id']])['dm_id'] channel_join_v2(b_data["token"], a_ch_id) channel_join_v2(c_data["token"], a_ch_id) message_send_v2(a_data["token"], a_ch_id, "a normal message") notifs = notifications_get_v1(c_data["token"])["notifications"] assert notifs == [] message_send_v2(b_data["token"], a_ch_id, "@CHRISCON") notifs = notifications_get_v1(c_data["token"])["notifications"] assert notifs == [] message_send_v2(a_data["token"], a_ch_id, "@chrisco") notifs = notifications_get_v1(c_data["token"])["notifications"] assert notifs == [] message_send_v2(b_data["token"], a_ch_id, "@chris con") notifs = notifications_get_v1(c_data["token"])["notifications"] assert notifs == [] message_senddm_v1(a_data["token"], b_dm_id, "@chrisco@hriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert notifs == [] message_senddm_v1(b_data["token"], b_dm_id, "@ chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert notifs == [] message_senddm_v1(a_data["token"], b_dm_id, "def@achriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert notifs == [] message_senddm_v1(b_data["token"], b_dm_id, "abc@chr isconabc") notifs = notifications_get_v1(c_data["token"])["notifications"] assert notifs == []
def test_single_react_notification(): clear_v1() user1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng") user2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton") channel1 = channels_create_v2(user1['token'], 'Channel 1', True) channel_join_v2(user2['token'], channel1['channel_id']) msg1 = message_send_v2(user1['token'], channel1['channel_id'], "1 like = 1 prayer") message_react_v1(user2['token'], msg1['message_id'], 1) assert notifications_get_v1(user1['token']) == { 'notifications': [{ 'channel_id': channel1['channel_id'], 'dm_id': -1, 'notification_message': "joshhatton reacted to your message in Channel 1" }] }
def test_simple_tag(): clear_v1() user_1 = auth_register_v2("*****@*****.**", "finalpassword", "Eric", "Zheng") user_2 = auth_register_v2("*****@*****.**", "validpassword", "Josh", "Hatton") message_1 = "@ericzheng, how are you doing today?" channel_1 = channels_create_v2(user_1['token'], 'Channel 1', True) channel_join_v2(user_2['token'], channel_1['channel_id']) message_send_v2(user_2['token'], channel_1['channel_id'], message_1) assert notifications_get_v1(user_1['token']) == { 'notifications': [{ 'channel_id': channel_1['channel_id'], 'dm_id': -1, 'notification_message': f"joshhatton tagged you in Channel 1: {message_1[0:20]}" }] }
def test_invalid_token(reg_user): clear_v2() reg_user(0) with pytest.raises(AccessError): notifications_get_v1("Invalid token")
def notifications_get(): token = request.args.get('token') return dumps(notifications_get_v1(token))
def test_tagged_channel(test_data): a_data, b_data, c_data, a_ch_id = test_data channel_join_v2(b_data["token"], a_ch_id) channel_join_v2(c_data["token"], a_ch_id) # c will be getting all the notifications/tags # TAGS IN CHANNEL # most recent to least recent message_send_v2(a_data["token"], a_ch_id, "1CH tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 1 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1CH tag @chriscon" } sleep(1) message_send_v2(b_data["token"], a_ch_id, "2CH tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 2 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "bobbobinson tagged you in Channel 1: 2CH tag @chriscon" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1CH tag @chriscon" } sleep(1) message_send_v2(c_data["token"], a_ch_id, "3CH tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 3 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "chriscon tagged you in Channel 1: 3CH tag @chriscon" } assert notifs[2] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1CH tag @chriscon" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "bobbobinson tagged you in Channel 1: 2CH tag @chriscon" }
def test_edge_case_notifs(test_data): a_data, b_data, c_data, a_ch_id = test_data channel_join_v2(b_data["token"], a_ch_id) channel_join_v2(c_data["token"], a_ch_id) sleep(1) #more than 20, 21 and 21+ notifications message_send_v2(a_data["token"], a_ch_id, "1 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "2 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "3 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "4 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "5 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "6 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "7 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "8 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "9 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "10 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "11 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "12 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "13 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "14 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "15 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "16 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "17 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "18 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "19 @chriscon") sleep(1) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 19 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 19 @chriscon" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 18 @chriscon" } assert notifs[17] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 2 @chriscon" } assert notifs[18] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1 @chriscon" } message_send_v2(a_data["token"], a_ch_id, "20 @chriscon") sleep(1) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 20 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 20 @chriscon" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 19 @chriscon" } assert notifs[18] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 2 @chriscon" } assert notifs[19] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1 @chriscon" } message_send_v2(a_data["token"], a_ch_id, "21 @chriscon") sleep(1) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 20 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 21 @chriscon" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 20 @chriscon" } assert notifs[18] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 3 @chriscon" } assert notifs[19] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 2 @chriscon" } message_send_v2(a_data["token"], a_ch_id, "22 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "23 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "24 @chriscon") sleep(1) message_send_v2(a_data["token"], a_ch_id, "25 @chriscon") sleep(1) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 20 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 25 @chriscon" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 24 @chriscon" } assert notifs[18] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 7 @chriscon" } assert notifs[19] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 6 @chriscon" }
def test_react(test_data): a_data, b_data, c_data, a_ch_id = test_data channel_join_v2(b_data["token"], a_ch_id) channel_join_v2(c_data["token"], a_ch_id) a_msg_id = message_send_v2(a_data["token"], a_ch_id, "React to me!")["message_id"] message_react_v1(b_data["token"], a_msg_id, 1) notifs = notifications_get_v1(a_data["token"])["notifications"] assert len(notifs) == 1 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "bobbobinson reacted to your message in Channel 1" } sleep(1) message_react_v1(c_data["token"], a_msg_id, 1) notifs = notifications_get_v1(a_data["token"])["notifications"] assert len(notifs) == 2 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "chriscon reacted to your message in Channel 1" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "bobbobinson reacted to your message in Channel 1" } sleep(1) b_dm_id = dm_create_v1( b_data["token"], [a_data["auth_user_id"], c_data["auth_user_id"]])["dm_id"] a1_msg_id = message_senddm_v1(a_data["token"], b_dm_id, "React to me again!")["message_id"] message_react_v1(b_data["token"], a1_msg_id, 1) notifs = notifications_get_v1(a_data["token"])["notifications"] assert len(notifs) == 3 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson reacted to your message in andyanderson, bobbobinson, chriscon" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "chriscon reacted to your message in Channel 1" } assert notifs[2] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "bobbobinson reacted to your message in Channel 1" }
def test_multitag(test_data): # multiple tags in one message a_data, b_data, c_data, a_ch_id = test_data channel_join_v2(b_data["token"], a_ch_id) channel_join_v2(c_data["token"], a_ch_id) # The notifcation message is cut off because it only shows the first 20 characters of the message message_send_v2(a_data["token"], a_ch_id, "tag @chriscon @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 1 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: tag @chriscon @chris" } sleep(1) message_send_v2(b_data["token"], a_ch_id, "tag @chriscon @chriscon @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 2 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "bobbobinson tagged you in Channel 1: tag @chriscon @chris" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: tag @chriscon @chris" } sleep(1) message_send_v2(c_data["token"], a_ch_id, "@chriscon tag @chriscon @chriscon @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 3 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "chriscon tagged you in Channel 1: @chriscon tag @chris" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "bobbobinson tagged you in Channel 1: tag @chriscon @chris" } assert notifs[2] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: tag @chriscon @chris" }
def test_add_both(test_data): # ADD TO BOTH a_data, b_data, c_data, a_ch_id = test_data x_data = auth_register_v2('*****@*****.**', '123456', 'Xxxx', 'Anderson') y_data = auth_register_v2('*****@*****.**', '123456', 'Yyyy', 'Bobinson') b_ch_id = channels_create_v2(b_data['token'], 'Channel 2', True)['channel_id'] a_dm_id = dm_create_v1(a_data['token'], [b_data['auth_user_id']])['dm_id'] b_dm_id = dm_create_v1(b_data['token'], [a_data['auth_user_id']])['dm_id'] # add dm # dilute dm with another invite dm_invite_v1(b_data["token"], b_dm_id, x_data["auth_user_id"]) dm_invite_v1(b_data["token"], b_dm_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 1 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } sleep(1) # add ch channel_invite_v2(a_data["token"], a_ch_id, y_data["auth_user_id"]) channel_invite_v2(a_data["token"], a_ch_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 2 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } assert notifs[1] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } sleep(1) # add dm dm_invite_v1(a_data["token"], a_dm_id, y_data["auth_user_id"]) dm_invite_v1(a_data["token"], a_dm_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 3 assert notifs[0] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson added you to andyanderson, bobbobinson" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } assert notifs[2] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } sleep(1) # add ch channel_invite_v2(b_data["token"], b_ch_id, x_data["auth_user_id"]) channel_invite_v2(b_data["token"], b_ch_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 4 assert notifs[0] == { "channel_id": b_ch_id, "dm_id": -1, "notification_message": "bobbobinson added you to Channel 2" } assert notifs[1] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson added you to andyanderson, bobbobinson" } assert notifs[2] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } assert notifs[3] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" }
def test_tagged_dm(test_data): # TAGS IN DM a_data, b_data, c_data, _ = test_data b_dm_id = dm_create_v1( b_data['token'], [a_data['auth_user_id'], c_data['auth_user_id']])['dm_id'] message_senddm_v1(a_data["token"], b_dm_id, "1DM tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 1 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson, chriscon: 1DM tag @chriscon" } sleep(1) message_senddm_v1(b_data["token"], b_dm_id, "2DM tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 2 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson, chriscon: 2DM tag @chriscon" } assert notifs[1] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson, chriscon: 1DM tag @chriscon" } sleep(1) message_senddm_v1(c_data["token"], b_dm_id, "3DM tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 3 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "chriscon tagged you in andyanderson, bobbobinson, chriscon: 3DM tag @chriscon" } assert notifs[1] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson, chriscon: 2DM tag @chriscon" } assert notifs[2] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson, chriscon: 1DM tag @chriscon" }
def test_invalid_token(test_data): a_data, _, c_data, a_ch_id = test_data channel_join_v2(c_data["token"], a_ch_id) message_send_v2(a_data["token"], a_ch_id, "1CH tag @chriscon") with pytest.raises(AccessError): notifications_get_v1("") notifications_get_v1(0) notifications_get_v1(999328) notifications_get_v1(-42) notifications_get_v1("5912381") notifications_get_v1("invalid.token.10586") notifications_get_v1("bytasdoawqeawqdqafwa") notifications_get_v1("ADWNUASMfaaAWwm") notifications_get_v1("ASUIdb21d9ADsDi21") notifications_get_v1("!)(%&@!*%#!$") notifications_get_v1(" ")
def test_mixed_case(test_data): a_data, b_data, c_data, a_ch_id = test_data b_ch_id = channels_create_v2(b_data['token'], 'Channel 2', True)['channel_id'] a_dm_id = dm_create_v1(a_data['token'], [b_data['auth_user_id']])['dm_id'] b_dm_id = dm_create_v1(b_data['token'], [a_data['auth_user_id']])['dm_id'] # join a_ch channel_invite_v2(a_data["token"], a_ch_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 1 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } sleep(1) # join b_dm dm_invite_v1(b_data["token"], b_dm_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 2 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } sleep(1) # tag in a_ch message_send_v2(a_data["token"], a_ch_id, "1A CH tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 3 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1A CH tag @chriscon" } assert notifs[1] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } assert notifs[2] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } sleep(1) # join a_dm dm_invite_v1(a_data["token"], a_dm_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 4 assert notifs[0] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson added you to andyanderson, bobbobinson" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1A CH tag @chriscon" } assert notifs[2] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } assert notifs[3] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } sleep(1) # tag in b_dm message_senddm_v1(b_data["token"], b_dm_id, "1B DM tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 5 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson: 1B DM tag @chriscon" } assert notifs[1] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson added you to andyanderson, bobbobinson" } assert notifs[2] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1A CH tag @chriscon" } assert notifs[3] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } assert notifs[4] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } sleep(1) # tag in a_dm message_senddm_v1(a_data["token"], a_dm_id, "1A DM tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 6 assert notifs[0] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson: 1A DM tag @chriscon" } assert notifs[1] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson: 1B DM tag @chriscon" } assert notifs[2] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson added you to andyanderson, bobbobinson" } assert notifs[3] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1A CH tag @chriscon" } assert notifs[4] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } assert notifs[5] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } sleep(1) # join b_ch channel_invite_v2(b_data["token"], b_ch_id, c_data["auth_user_id"]) notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 7 assert notifs[0] == { "channel_id": b_ch_id, "dm_id": -1, "notification_message": "bobbobinson added you to Channel 2" } assert notifs[1] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson: 1A DM tag @chriscon" } assert notifs[2] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson: 1B DM tag @chriscon" } assert notifs[3] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson added you to andyanderson, bobbobinson" } assert notifs[4] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1A CH tag @chriscon" } assert notifs[5] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } assert notifs[6] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } sleep(1) # tag in b_dm message_senddm_v1(b_data["token"], b_dm_id, "2B DM tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 8 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson: 2B DM tag @chriscon" } assert notifs[1] == { "channel_id": b_ch_id, "dm_id": -1, "notification_message": "bobbobinson added you to Channel 2" } assert notifs[2] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson: 1A DM tag @chriscon" } assert notifs[3] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson: 1B DM tag @chriscon" } assert notifs[4] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson added you to andyanderson, bobbobinson" } assert notifs[5] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1A CH tag @chriscon" } assert notifs[6] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } assert notifs[7] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" } sleep(1) # tag in b_ch message_send_v2(b_data["token"], b_ch_id, "1B CH tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 9 assert notifs[0] == { "channel_id": b_ch_id, "dm_id": -1, "notification_message": "bobbobinson tagged you in Channel 2: 1B CH tag @chriscon" } assert notifs[1] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson: 2B DM tag @chriscon" } assert notifs[2] == { "channel_id": b_ch_id, "dm_id": -1, "notification_message": "bobbobinson added you to Channel 2" } assert notifs[3] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson: 1A DM tag @chriscon" } assert notifs[4] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson: 1B DM tag @chriscon" } assert notifs[5] == { "channel_id": -1, "dm_id": a_dm_id, "notification_message": "andyanderson added you to andyanderson, bobbobinson" } assert notifs[6] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1A CH tag @chriscon" } assert notifs[7] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson added you to andyanderson, bobbobinson" } assert notifs[8] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson added you to Channel 1" }
def notification(): parameters = request.args token = parameters['token'] output = notifications_get_v1(token) return dumps(output)
def test_tagged_both(test_data): # TAGS IN BOTH a_data, b_data, c_data, a_ch_id = test_data channel_join_v2(b_data["token"], a_ch_id) channel_join_v2(c_data["token"], a_ch_id) b_dm_id = dm_create_v1( b_data['token'], [a_data['auth_user_id'], c_data['auth_user_id']])['dm_id'] # send ch message_send_v2(a_data["token"], a_ch_id, "1CH tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 1 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1CH tag @chriscon" } sleep(1) # send dm message_senddm_v1(a_data["token"], b_dm_id, "1DM tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 2 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson, chriscon: 1DM tag @chriscon" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1CH tag @chriscon" } sleep(1) # send dm message_senddm_v1(b_data["token"], b_dm_id, "2DM tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 3 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson, chriscon: 2DM tag @chriscon" } assert notifs[1] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson, chriscon: 1DM tag @chriscon" } assert notifs[2] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1CH tag @chriscon" } sleep(1) # send ch message_send_v2(b_data["token"], a_ch_id, "2CH tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 4 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "bobbobinson tagged you in Channel 1: 2CH tag @chriscon" } assert notifs[1] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson, chriscon: 2DM tag @chriscon" } assert notifs[2] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson, chriscon: 1DM tag @chriscon" } assert notifs[3] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1CH tag @chriscon" } sleep(1) # send dm message_senddm_v1(c_data["token"], b_dm_id, "3DM tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 5 assert notifs[0] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "chriscon tagged you in andyanderson, bobbobinson, chriscon: 3DM tag @chriscon" } assert notifs[1] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "bobbobinson tagged you in Channel 1: 2CH tag @chriscon" } assert notifs[2] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson, chriscon: 2DM tag @chriscon" } assert notifs[3] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson, chriscon: 1DM tag @chriscon" } assert notifs[4] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1CH tag @chriscon" } sleep(1) # send ch message_send_v2(c_data["token"], a_ch_id, "3CH tag @chriscon") notifs = notifications_get_v1(c_data["token"])["notifications"] assert len(notifs) == 6 assert notifs[0] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "chriscon tagged you in Channel 1: 3CH tag @chriscon" } assert notifs[1] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "chriscon tagged you in andyanderson, bobbobinson, chriscon: 3DM tag @chriscon" } assert notifs[2] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "bobbobinson tagged you in Channel 1: 2CH tag @chriscon" } assert notifs[3] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "bobbobinson tagged you in andyanderson, bobbobinson, chriscon: 2DM tag @chriscon" } assert notifs[4] == { "channel_id": -1, "dm_id": b_dm_id, "notification_message": "andyanderson tagged you in andyanderson, bobbobinson, chriscon: 1DM tag @chriscon" } assert notifs[5] == { "channel_id": a_ch_id, "dm_id": -1, "notification_message": "andyanderson tagged you in Channel 1: 1CH tag @chriscon" }