def test_new_event(auth, get_user_id, get_one, execute_insert_events, execute_insert_apiutils, client): new_event_json = json.dumps(new_event_spec) response = client.post('/event/new', data=new_event_json, content_type='application/json') auth.assert_called_with(None, None) get_user_id.assert_called_with() insert_query = 'INSERT INTO events (id_network,id_host,event_date,' \ 'title,address_1,address_2,country,city,region,' \ 'description) values ' \ '(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s);' insert_args = (1, 2, '2018-12-24T22:17:30.900Z', 'Title!', 'Address1', 'Address2', 'Country', 'City', 'Region', 'The Event Description!') execute_insert_apiutils.assert_called_with(insert_query, insert_args) join_event_query = "INSERT INTO event_registration VALUES " \ "(%s,%s,CURRENT_TIMESTAMP, %s)" join_event_args = (2, 65, 'host') execute_insert_events.assert_called_with(join_event_query, join_event_args) get_event_id_query = "SELECT id FROM events WHERE id_host=%s AND id_" \ "network=%s ORDER BY id DESC LIMIT 1" get_event_id_args = (2, 1) get_one.assert_called_with(get_event_id_query, get_event_id_args) assert response.status_code == 200 assert response.data.decode() == 'OK'
def test_join_missing_network(execute_mod, net_exists, auth, get_id, client): response = client.post('/user/joinNetwork/2') auth.assert_called_with(None, None) get_id.assert_called_with() net_exists.assert_called_with('2') execute_mod.assert_not_called() assert response.status_code == 405 assert response.data.decode() == 'Invalid Network Id'
def test_join_event_missing_role(execute_insert, event_exists, auth, get_id, client): response = client.post('/user/joinEvent/23') auth.assert_called_with(None, None) event_exists.assert_called_with('23') get_id.assert_called_with() execute_insert.assert_not_called() assert response.status_code == 405 assert response.data.decode() == 'Invalid role parameter.'
def test_create_user_bad_description_fail(get_one, execute_insert, client): user_def_json = json.dumps({}) response = client.post("/user/users", data=user_def_json, content_type="application/json") get_one.assert_not_called() execute_insert.assert_not_called() assert response.status_code == 400 assert response.data.decode() == "Username already taken or invalid params"
def test_join_missing_event(execute_insert, event_exists, auth, get_id, client): response = client.post('/user/joinEvent/23', query_string={'role': 'guest'}) execute_insert.assert_not_called() event_exists.assert_called_with('23') get_id.assert_not_called() auth.assert_called_with(None, None) assert response.status_code == 405 assert response.data.decode() == "Invalid Event Id"
def test_create_user_username_taken_fail(get_one, execute_insert, client): user_def_json = json.dumps(user_def) response = client.post("/user/users", data=user_def_json, content_type="application/json") get_one.assert_called_with("SELECT * FROM users WHERE username=%s", (user_obj['username'], )) execute_insert.assert_not_called() assert response.status_code == 400 assert response.data.decode() == "Username already taken or invalid params"
def test_join_network(execute_mod, net_exists, auth, get_id, client): response = client.post('/user/joinNetwork/2') auth.assert_called_with(None, None) get_id.assert_called_with() net_exists.assert_called_with('2') query = "INSERT INTO network_registration VALUES " \ "(%s, %s, CURRENT_TIMESTAMP)" args = ('1', '2') execute_mod.assert_called_with(query, args) assert response.status_code == 200 assert response.data.decode() == 'OK'
def test_join_event(execute_insert, event_exists, auth, get_id, client): response = client.post('/user/joinEvent/23', query_string={'role': 'guest'}) query = "INSERT INTO event_registration VALUES " \ "(%s,%s,CURRENT_TIMESTAMP, %s)" args = (1, '23', 'guest') execute_insert.assert_called_with(query, args) event_exists.assert_called_with('23') get_id.assert_called_with() auth.assert_called_with(None, None) assert response.status_code == 200 assert response.data.decode() == 'OK'
def test_create_reply(auth, get_user_id, execute_insert, client): response = client.post('/post/2/reply', data=reply_json, content_type='application/json') auth.assert_called_with(None, None) get_user_id.assert_called_with() query = 'INSERT INTO post_replies ' \ '(id_parent,id_user,id_network,reply_text) ' \ 'values (%s, %s, %s, %s);' args = (2, 1, 3, 'Some post reply!') execute_insert.assert_called_with(query, args) assert response.status_code == 200 assert response.data.decode() == 'OK'
def test_create_post(auth, get_user_id, execute_insert, client): response = client.post('/post/new', data=new_post_json, content_type='application/json') auth.assert_called_with(None, None) get_user_id.assert_called_with() query = 'INSERT INTO posts ' \ '(id_user,id_network,post_text,vid_link,img_link) values ' \ '(%s, %s, %s, %s, %s);' args = (1, 2, 'New Post', 'videoLink', 'imageLink') execute_insert.assert_called_with(query, args) assert response.status_code == 200 assert response.data.decode() == 'OK'
def test_create_user(get_one, execute_insert, client): user_def_json = json.dumps(user_def) response = client.post("/user/users", data=user_def_json, content_type="application/json") by_email_query = "SELECT * FROM users WHERE email=%s" call_email = call(by_email_query, (user_obj['email'], )) by_username_query = "SELECT * FROM users WHERE username=%s" call_username = call(by_username_query, (user_obj['username'], )) get_one.assert_has_calls([call_email, call_username], any_order=False) form = 'INSERT INTO users (username,first_name,last_name,email,password)' \ ' values (%s, %s, %s, %s, %s);' args = ('MyUserName3!', 'Human2!', 'Being4!', '*****@*****.**', md5(str(user_def["password"]).encode('utf-8')).hexdigest()) execute_insert.assert_called_with(form, args) assert response.status_code == 200 assert response.data.decode() == "OK"