Esempio n. 1
0
def users(user_id):
    if request.method == 'POST':
        request_data = request.json
        user_name = request_data.get('user_name')
        if db_connector.user_create(user_id,user_name): # try to create new user
            return {'status': 'ok', 'user_added': user_name }, 200
        else: #  user exist
            return {'status': 'error', 'reason': user_id  + ' Already exist'}, 500

    if request.method == 'GET':
        user_name =  db_connector.get_user_name(user_id)
        if user_name != '':
            return {'status': 'ok', 'user_name': user_name}, 200
        else:
            return {'status': 'error', 'reason': 'no such id'}, 500

    if request.method == 'PUT':
        request_data = request.json
        user_name = request_data.get('user_name')
        if db_connector.user_update(user_id,user_name): # try to update a user
            return {'status': 'ok', 'user_Updated': user_name }, 200
        else: #  user exist
            return {'status': 'error', 'reason': user_id  + ' no such id'}, 500


    if request.method == 'DELETE':
        if db_connector.user_delete(user_id):
            return {'status': 'ok', 'user_deleted': user_id}, 200
        else:
            return {'status': 'error', 'reason': 'no such id'}, 500
Esempio n. 2
0
def usrPost():
    res = requests.post('http://localhost:5002/users/1',
                        json={"user_name": "John"})
    if res.ok:
        print(res.json())
    else:
        print(res.json())
    print(' Database AFTER POST query found user_name: ' +
          db_connector.get_user_name(1) + ' For user_id: 1')
Esempio n. 3
0
def usrDel():
    res = requests.delete('http://localhost:5002/users/1')
    if res.ok:
        print(res.json())
    else:
        print(res.status_code)
        print(res.json())
    print(' Database AFTER DELETE query found user_name: ' +
          db_connector.get_user_name(1) + ' For user_id: 1')
Esempio n. 4
0
def usrPut():
    res = requests.put('http://localhost:5004/users/1',
                       json={"user_name": "John-updated"})
    if res.ok:
        print(res.json())
    else:
        print(res.status_code)
        print(res.json())
    print(' Database AFTER PUT query found user_name: ' +
          db_connector.get_user_name(1) + ' For user_id: 1')
Esempio n. 5
0
import requests
import db_connector
import frontend_testing

input_user_id = 901
input_json = {"user_name":"user-" + str(input_user_id)}

res = requests.post('http://127.0.0.1:5000/users/' + str(input_user_id) , json=input_json)
userj = res.json()
if res.status_code == 200:
    userj = res.json()
    user_posted = userj['user_added']
else:
    raise Exception("test failed")

res = requests.get('http://127.0.0.1:5000/users/' + str(input_user_id))
userj = res.json()
if res.status_code == 200:
    userj = res.json()
    user_get = userj['user_name']
    if user_get != user_posted :
        raise Exception("test failed")
else:
    raise Exception("test failed")

print(' Database AFTER GET query found user_name: ' + db_connector.get_user_name(input_user_id) + ' For user_id: ' + str(input_user_id))

user_fe = frontend_testing.fe_test(input_user_id)

if user_fe != db_connector.get_user_name(input_user_id):
    raise Exception("test failed")
Esempio n. 6
0
def users(user_id):
    user_name = db_connector.get_user_name(user_id)
    if user_name != '':
        return "<H1 id='user'>" + user_name + "</H1>"
    else:
        return "<H1 id='error'>" 'no such user: ' + user_id + "</H1>"
Esempio n. 7
0
import requests
import db_connector

res = requests.post('http://127.0.0.1:5000/users/1', json={"user_name":"John"})
if res.ok:
    print(res.json())
else:
    print(res.json())

print(' Database AFTER POST query found user_name: ' + db_connector.get_user_name(1) + ' For user_id: 1')

res = requests.get('http://127.0.0.1:5000/users/1')
if res.ok:
    print(res.json())
else:
    print(res.status_code)
    print(res.json())

print(' Database AFTER GET query found user_name: ' + db_connector.get_user_name(1) + ' For user_id: 1')

res = requests.put('http://127.0.0.1:5000/users/1', json={"user_name":"John-updated"})
if res.ok:
    print(res.json())
else:
    print(res.status_code)
    print(res.json())

print(' Database AFTER PUT query found user_name: ' + db_connector.get_user_name(1) + ' For user_id: 1')

res = requests.delete('http://127.0.0.1:5000/users/1')
if res.ok: