def test_notifications(register_users): channels_create_v2(make_token(1), "PublicChannel1", True) channel_invite_v2(make_token(1), 0, 0) assert notifications_get_v1(make_token(0)) == { "notifications": [{ "channel_id": 0, "dm_id": -1, "notification_message": "petertran invited you to PublicChannel1" }] } dm_create_v1(make_token(0), [1]) # dm_id 0 assert notifications_get_v1(make_token(1)) == { "notifications": [{ "channel_id": -1, "dm_id": 0, "notification_message": "gungeetsingh added you to dm gungeetsingh, petertran" }] } clear_v1()
def register_users(): clear_v1() # register 4 users with email, password, first name and last name # first user is the dream owner auth_register_v2("*****@*****.**", "password", "Gungeet", "Singh") auth_register_v2("*****@*****.**", "password", "Peter", "Tran") auth_register_v2("*****@*****.**", "password", "Christopher", "Luong") auth_register_v2("*****@*****.**", "password", "Tal", "Avrahami")
def test_auth_register_v2(): clear_v1() resp = requests.post(config.url + 'auth/register/v2', json={ "email": "*****@*****.**", "password": "******", "name_first": "Eyal", "name_last": "Dorfan", }) payload = resp.json() assert payload == {'token': make_token(0), 'auth_user_id': 0}
def user_setup(): ''' Clear history of all current users then register and login new users ''' clear_v1() # register 3 users with email, password, first name and last name auth_register_v2("*****@*****.**", "password", "Gungeet", "Singh") auth_register_v2("*****@*****.**", "password", "Peter", "Tran") auth_register_v2("*****@*****.**", "password", "Christopher", "Luong") auth_register_v2("*****@*****.**", "password", "Tal", "Avrahami") # login the 3 users who have been registered auth_login_v2("*****@*****.**", "password") auth_login_v2("*****@*****.**", "password") auth_login_v2("*****@*****.**", "password") auth_login_v2("*****@*****.**", "password")
def test_auth_invalid_email(): clear_v1() resp = requests.post(config.url + 'auth/register/v2', json={ "email": "eyaldgmail.com", "password": "******", "name_first": "Eyal", "name_last": "Dorfan", }) assert resp.status_code == 400 resp = requests.post(config.url + 'auth/login/v2', json={ "email": "eyaldgmail.com", "password": "******", }) assert resp.status_code == 400
def test_auth_register_name_errors(): clear_v1() resp = requests.post(config.url + 'auth/register/v2', json={ "email": "*****@*****.**", "password": "******", "name_first": "", "name_last": "Dorfan", }) assert resp.status_code == 400 resp = requests.post(config.url + 'auth/register/v2', json={ "email": "*****@*****.**", "password": "******", "name_first": "Eyal", "name_last": "", }) assert resp.status_code == 400 resp = requests.post(config.url + 'auth/register/v2', json={ "email": "*****@*****.**", "password": "******", "name_first": "A" * 100, "name_last": "Dorfan", }) assert resp.status_code == 400 resp = requests.post(config.url + 'auth/register/v2', json={ "email": "*****@*****.**", "password": "******", "name_first": "Eyal", "name_last": "D" * 100, }) assert resp.status_code == 400
def user_setup(): ''' Clear history of all current users then register and login new users ''' clear_v1() # register 3 users with email, password, first name and last name requests.post(config.url + 'auth/register/v2', json = { "email": "*****@*****.**", "password": "******", "name_first": "Gungeet", "name_last": "Singh", }) requests.post(config.url + 'auth/register/v2', json = { "email": "*****@*****.**", "password": "******", "name_first": "Peter", "name_last": "Tran", }) requests.post(config.url + 'auth/register/v2', json = { "email": "*****@*****.**", "password": "******", "name_first": "Christopher", "name_last": "Luong" })
def test_search_success(register_users): channels_create_v2(make_token(0), "PublicChannel1", True) dm_create_v1(make_token(0), [1, 2]) # dm_id 0 message_send_v2(make_token(0), 0, "Hello") message_senddm_v1(make_token(0), 0, "Goodbye") assert search_v2(make_token(0), "Hello") == { "messages": [{ "message_id": 0, "u_id": 0, "message": "Hello", "time_created": str(create_timestamp()), "channel_id": 0, "dm_id": -1, "reacts": [{ "react_id": 1, "u_ids": [], "is_this_user_reacted": False }], "is_pinned": False }] } assert search_v2(make_token(0), "Good") == { "messages": [{ "message_id": 1, "u_id": 0, "message": "Goodbye", "time_created": str(create_timestamp()), "channel_id": -1, "dm_id": 0, "reacts": [{ "react_id": 1, "u_ids": [], "is_this_user_reacted": False }], "is_pinned": False }] } assert search_v2(make_token(0), "o") == { "messages": [{ "message_id": 0, "u_id": 0, "message": "Hello", "time_created": str(create_timestamp()), "channel_id": 0, "dm_id": -1, "reacts": [{ "react_id": 1, "u_ids": [], "is_this_user_reacted": False }], "is_pinned": False }, { "message_id": 1, "u_id": 0, "message": "Goodbye", "time_created": str(create_timestamp()), "channel_id": -1, "dm_id": 0, "reacts": [{ "react_id": 1, "u_ids": [], "is_this_user_reacted": False }], "is_pinned": False }] } clear_v1()
def clear(): reset = clear_v1() return dumps(reset)