2016-01-11 15:07:13 +00:00
|
|
|
import json
|
2016-01-15 16:22:03 +00:00
|
|
|
from flask import url_for
|
2016-01-11 18:09:10 +00:00
|
|
|
from app.models import (User, Service)
|
2016-01-15 16:22:03 +00:00
|
|
|
from tests import create_authorization_header
|
2016-01-11 18:09:10 +00:00
|
|
|
from tests.app.conftest import sample_service as create_sample_service
|
2016-01-11 15:07:13 +00:00
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_get_user_list(notify_api, notify_db, notify_db_session, sample_user, sample_admin_service_id):
|
2016-01-11 15:07:13 +00:00
|
|
|
"""
|
|
|
|
|
Tests GET endpoint '/' to retrieve entire user list.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
2016-01-15 16:22:03 +00:00
|
|
|
header = create_authorization_header(service_id=sample_admin_service_id,
|
|
|
|
|
path=url_for('user.get_user'),
|
|
|
|
|
method='GET')
|
|
|
|
|
response = client.get(url_for('user.get_user'),
|
|
|
|
|
headers=[header])
|
2016-01-11 15:07:13 +00:00
|
|
|
assert response.status_code == 200
|
|
|
|
|
json_resp = json.loads(response.get_data(as_text=True))
|
2016-01-15 16:22:03 +00:00
|
|
|
assert len(json_resp['data']) == 2
|
2016-01-19 11:38:29 +00:00
|
|
|
expected = {
|
|
|
|
|
"name": "Test User",
|
|
|
|
|
"email_address": sample_user.email_address,
|
|
|
|
|
"id": sample_user.id,
|
2016-01-22 14:43:30 +00:00
|
|
|
"mobile_number": "+447700900986",
|
2016-01-19 11:38:29 +00:00
|
|
|
"password_changed_at": None,
|
|
|
|
|
"logged_in_at": None,
|
|
|
|
|
"state": "active",
|
|
|
|
|
"failed_login_count": 0
|
|
|
|
|
}
|
|
|
|
|
assert expected in json_resp['data']
|
2016-01-11 15:07:13 +00:00
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_get_user(notify_api, notify_db, notify_db_session, sample_user, sample_admin_service_id):
|
2016-01-11 15:07:13 +00:00
|
|
|
"""
|
|
|
|
|
Tests GET endpoint '/<user_id>' to retrieve a single service.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
2016-01-15 16:22:03 +00:00
|
|
|
header = create_authorization_header(service_id=sample_admin_service_id,
|
|
|
|
|
path=url_for('user.get_user', user_id=sample_user.id),
|
|
|
|
|
method='GET')
|
2016-01-11 15:07:13 +00:00
|
|
|
resp = client.get(url_for('user.get_user',
|
2016-01-15 16:22:03 +00:00
|
|
|
user_id=sample_user.id),
|
|
|
|
|
headers=[header])
|
2016-01-11 15:07:13 +00:00
|
|
|
assert resp.status_code == 200
|
|
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
2016-01-19 11:38:29 +00:00
|
|
|
expected = {
|
|
|
|
|
"name": "Test User",
|
|
|
|
|
"email_address": sample_user.email_address,
|
|
|
|
|
"id": sample_user.id,
|
2016-01-22 14:43:30 +00:00
|
|
|
"mobile_number": "+447700900986",
|
2016-01-19 11:38:29 +00:00
|
|
|
"password_changed_at": None,
|
|
|
|
|
"logged_in_at": None,
|
|
|
|
|
"state": "active",
|
|
|
|
|
"failed_login_count": 0
|
|
|
|
|
}
|
|
|
|
|
assert json_resp['data'] == expected
|
2016-01-11 15:07:13 +00:00
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_post_user(notify_api, notify_db, notify_db_session, sample_admin_service_id):
|
2016-01-11 15:07:13 +00:00
|
|
|
"""
|
|
|
|
|
Tests POST endpoint '/' to create a user.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 1
|
2016-01-19 11:38:29 +00:00
|
|
|
data = {
|
|
|
|
|
"name": "Test User",
|
|
|
|
|
"email_address": "user@digital.cabinet-office.gov.uk",
|
|
|
|
|
"password": "password",
|
2016-01-22 14:43:30 +00:00
|
|
|
"mobile_number": "+447700900986",
|
2016-01-19 11:38:29 +00:00
|
|
|
"password_changed_at": None,
|
|
|
|
|
"logged_in_at": None,
|
|
|
|
|
"state": "active",
|
|
|
|
|
"failed_login_count": 0
|
|
|
|
|
}
|
2016-01-15 16:22:03 +00:00
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
|
|
|
|
path=url_for('user.create_user'),
|
|
|
|
|
method='POST',
|
|
|
|
|
request_body=json.dumps(data))
|
|
|
|
|
headers = [('Content-Type', 'application/json'), auth_header]
|
2016-01-11 15:07:13 +00:00
|
|
|
resp = client.post(
|
|
|
|
|
url_for('user.create_user'),
|
|
|
|
|
data=json.dumps(data),
|
|
|
|
|
headers=headers)
|
|
|
|
|
assert resp.status_code == 201
|
2016-01-15 16:22:03 +00:00
|
|
|
user = User.query.filter_by(email_address='user@digital.cabinet-office.gov.uk').first()
|
2016-01-11 15:07:13 +00:00
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
2016-01-15 16:22:03 +00:00
|
|
|
json_resp['data'] == {"email_address": user.email_address, "id": user.id}
|
2016-01-11 15:07:13 +00:00
|
|
|
assert json_resp['data']['email_address'] == user.email_address
|
|
|
|
|
assert json_resp['data']['id'] == user.id
|
|
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_post_user_missing_attribute_email(notify_api, notify_db, notify_db_session, sample_admin_service_id):
|
2016-01-11 18:09:10 +00:00
|
|
|
"""
|
|
|
|
|
Tests POST endpoint '/' missing attribute email.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 1
|
2016-01-11 18:09:10 +00:00
|
|
|
data = {
|
2016-01-19 11:38:29 +00:00
|
|
|
"name": "Test User",
|
|
|
|
|
"password": "password",
|
2016-01-22 14:43:30 +00:00
|
|
|
"mobile_number": "+447700900986",
|
2016-01-19 11:38:29 +00:00
|
|
|
"password_changed_at": None,
|
|
|
|
|
"logged_in_at": None,
|
|
|
|
|
"state": "active",
|
|
|
|
|
"failed_login_count": 0
|
|
|
|
|
}
|
2016-01-15 16:22:03 +00:00
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
|
|
|
|
path=url_for('user.create_user'),
|
|
|
|
|
method='POST',
|
|
|
|
|
request_body=json.dumps(data))
|
|
|
|
|
headers = [('Content-Type', 'application/json'), auth_header]
|
2016-01-11 18:09:10 +00:00
|
|
|
resp = client.post(
|
|
|
|
|
url_for('user.create_user'),
|
|
|
|
|
data=json.dumps(data),
|
|
|
|
|
headers=headers)
|
|
|
|
|
assert resp.status_code == 400
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 1
|
2016-01-11 18:09:10 +00:00
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
|
|
|
|
assert {'email_address': ['Missing data for required field.']} == json_resp['message']
|
|
|
|
|
|
|
|
|
|
|
2016-01-19 11:38:29 +00:00
|
|
|
def test_post_user_missing_attribute_password(notify_api, notify_db, notify_db_session, sample_admin_service_id):
|
|
|
|
|
"""
|
|
|
|
|
Tests POST endpoint '/' missing attribute password.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
|
|
|
|
assert User.query.count() == 1
|
|
|
|
|
data = {
|
|
|
|
|
"name": "Test User",
|
|
|
|
|
"email_address": "user@digital.cabinet-office.gov.uk",
|
2016-01-22 14:43:30 +00:00
|
|
|
"mobile_number": "+447700900986",
|
2016-01-19 11:38:29 +00:00
|
|
|
"password_changed_at": None,
|
|
|
|
|
"logged_in_at": None,
|
|
|
|
|
"state": "active",
|
|
|
|
|
"failed_login_count": 0
|
|
|
|
|
}
|
|
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
|
|
|
|
path=url_for('user.create_user'),
|
|
|
|
|
method='POST',
|
|
|
|
|
request_body=json.dumps(data))
|
|
|
|
|
headers = [('Content-Type', 'application/json'), auth_header]
|
|
|
|
|
resp = client.post(
|
|
|
|
|
url_for('user.create_user'),
|
|
|
|
|
data=json.dumps(data),
|
|
|
|
|
headers=headers)
|
|
|
|
|
assert resp.status_code == 400
|
|
|
|
|
assert User.query.count() == 1
|
|
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
2016-01-19 12:07:14 +00:00
|
|
|
assert {'password': ['Missing data for required field.']} == json_resp['message']
|
2016-01-19 11:38:29 +00:00
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_put_user(notify_api, notify_db, notify_db_session, sample_user, sample_admin_service_id):
|
2016-01-11 18:09:10 +00:00
|
|
|
"""
|
|
|
|
|
Tests PUT endpoint '/' to update a user.
|
|
|
|
|
"""
|
2016-01-11 17:19:06 +00:00
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 2
|
2016-01-11 17:19:06 +00:00
|
|
|
new_email = 'new@digital.cabinet-office.gov.uk'
|
|
|
|
|
data = {
|
2016-01-19 11:38:29 +00:00
|
|
|
'email_address': new_email
|
|
|
|
|
}
|
2016-01-15 16:22:03 +00:00
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
|
|
|
|
path=url_for('user.update_user', user_id=sample_user.id),
|
|
|
|
|
method='PUT',
|
|
|
|
|
request_body=json.dumps(data))
|
|
|
|
|
headers = [('Content-Type', 'application/json'), auth_header]
|
2016-01-11 17:19:06 +00:00
|
|
|
resp = client.put(
|
|
|
|
|
url_for('user.update_user', user_id=sample_user.id),
|
|
|
|
|
data=json.dumps(data),
|
|
|
|
|
headers=headers)
|
|
|
|
|
assert resp.status_code == 200
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 2
|
|
|
|
|
user = User.query.filter_by(email_address=new_email).first()
|
2016-01-11 17:19:06 +00:00
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
2016-01-19 11:38:29 +00:00
|
|
|
expected = {
|
|
|
|
|
"name": "Test User",
|
|
|
|
|
"email_address": new_email,
|
2016-01-22 14:43:30 +00:00
|
|
|
"mobile_number": "+447700900986",
|
2016-01-19 11:38:29 +00:00
|
|
|
"password_changed_at": None,
|
|
|
|
|
"id": user.id,
|
|
|
|
|
"logged_in_at": None,
|
|
|
|
|
"state": "active",
|
|
|
|
|
"failed_login_count": 0
|
|
|
|
|
}
|
|
|
|
|
assert json_resp['data'] == expected
|
2016-01-11 17:19:06 +00:00
|
|
|
assert json_resp['data']['email_address'] == new_email
|
2016-01-11 18:09:10 +00:00
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_put_user_not_exists(notify_api, notify_db, notify_db_session, sample_user, sample_admin_service_id):
|
2016-01-12 10:59:27 +00:00
|
|
|
"""
|
|
|
|
|
Tests PUT endpoint '/' to update a user doesn't exist.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 2
|
2016-01-12 10:59:27 +00:00
|
|
|
new_email = 'new@digital.cabinet-office.gov.uk'
|
2016-01-15 16:22:03 +00:00
|
|
|
data = {'email_address': new_email}
|
|
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
2016-01-22 14:58:03 +00:00
|
|
|
path=url_for('user.update_user', user_id="9999"),
|
2016-01-15 16:22:03 +00:00
|
|
|
method='PUT',
|
|
|
|
|
request_body=json.dumps(data))
|
|
|
|
|
headers = [('Content-Type', 'application/json'), auth_header]
|
2016-01-12 10:59:27 +00:00
|
|
|
resp = client.put(
|
2016-01-22 14:58:03 +00:00
|
|
|
url_for('user.update_user', user_id="9999"),
|
2016-01-12 10:59:27 +00:00
|
|
|
data=json.dumps(data),
|
|
|
|
|
headers=headers)
|
|
|
|
|
assert resp.status_code == 404
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 2
|
|
|
|
|
user = User.query.filter_by(id=sample_user.id).first()
|
2016-01-12 10:59:27 +00:00
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
2016-01-15 16:22:03 +00:00
|
|
|
assert json_resp == {'result': 'error', 'message': 'User not found'}
|
|
|
|
|
assert user == sample_user
|
2016-01-12 10:59:27 +00:00
|
|
|
assert user.email_address != new_email
|
|
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_get_user_services(notify_api, notify_db, notify_db_session, sample_service, sample_admin_service_id):
|
2016-01-11 18:09:10 +00:00
|
|
|
"""
|
|
|
|
|
Tests GET endpoint "/<user_id>/service/<service_id>" to retrieve services for a user.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
2016-01-15 16:22:03 +00:00
|
|
|
user = User.query.get(sample_service.users[0].id)
|
2016-01-11 18:09:10 +00:00
|
|
|
another_name = "another name"
|
2016-01-15 16:22:03 +00:00
|
|
|
create_sample_service(
|
2016-01-11 18:09:10 +00:00
|
|
|
notify_db,
|
|
|
|
|
notify_db_session,
|
|
|
|
|
service_name=another_name,
|
|
|
|
|
user=user)
|
2016-01-15 16:22:03 +00:00
|
|
|
assert Service.query.count() == 3
|
|
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
|
|
|
|
path=url_for('user.get_service_by_user_id', user_id=user.id),
|
|
|
|
|
method='GET')
|
2016-01-11 18:09:10 +00:00
|
|
|
resp = client.get(
|
|
|
|
|
url_for('user.get_service_by_user_id', user_id=user.id),
|
2016-01-15 16:22:03 +00:00
|
|
|
headers=[('Content-Type', 'application/json'), auth_header])
|
2016-01-11 18:09:10 +00:00
|
|
|
assert resp.status_code == 200
|
|
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
|
|
|
|
assert len(json_resp['data']) == 2
|
|
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_get_user_service(notify_api, notify_db, notify_db_session, sample_service, sample_admin_service_id):
|
2016-01-11 18:09:10 +00:00
|
|
|
"""
|
|
|
|
|
Tests GET endpoint "/<user_id>/service/<service_id>" to retrieve a service for a user.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
|
|
|
|
user = User.query.first()
|
|
|
|
|
another_name = "another name"
|
|
|
|
|
another_service = create_sample_service(
|
|
|
|
|
notify_db,
|
|
|
|
|
notify_db_session,
|
|
|
|
|
service_name=another_name,
|
|
|
|
|
user=user)
|
2016-01-15 16:22:03 +00:00
|
|
|
assert Service.query.count() == 3
|
|
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
|
|
|
|
path=url_for('user.get_service_by_user_id', user_id=user.id,
|
|
|
|
|
service_id=another_service.id),
|
|
|
|
|
method='GET')
|
2016-01-11 18:09:10 +00:00
|
|
|
resp = client.get(
|
|
|
|
|
url_for('user.get_service_by_user_id', user_id=user.id, service_id=another_service.id),
|
2016-01-15 16:22:03 +00:00
|
|
|
headers=[('Content-Type', 'application/json'), auth_header])
|
2016-01-11 18:09:10 +00:00
|
|
|
assert resp.status_code == 200
|
|
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
|
|
|
|
assert json_resp['data']['name'] == another_name
|
|
|
|
|
assert json_resp['data']['id'] == another_service.id
|
|
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_get_user_service_user_not_exists(notify_api, notify_db, notify_db_session, sample_service,
|
|
|
|
|
sample_admin_service_id):
|
2016-01-11 18:09:10 +00:00
|
|
|
"""
|
|
|
|
|
Tests GET endpoint "/<user_id>/service/<service_id>" 404 is returned for invalid user.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
2016-01-15 16:22:03 +00:00
|
|
|
assert Service.query.count() == 2
|
|
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
2016-01-21 12:13:17 +00:00
|
|
|
path=url_for('user.get_service_by_user_id', user_id="123423",
|
2016-01-15 16:22:03 +00:00
|
|
|
service_id=sample_service.id),
|
|
|
|
|
method='GET')
|
2016-01-21 12:13:17 +00:00
|
|
|
print('** service users{}'.format(sample_service.users[0].id))
|
2016-01-11 18:09:10 +00:00
|
|
|
resp = client.get(
|
2016-01-21 12:13:17 +00:00
|
|
|
url_for('user.get_service_by_user_id', user_id="123423", service_id=sample_service.id),
|
2016-01-15 16:22:03 +00:00
|
|
|
headers=[('Content-Type', 'application/json'), auth_header])
|
2016-01-11 18:09:10 +00:00
|
|
|
assert resp.status_code == 404
|
|
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
|
|
|
|
assert "User not found" in json_resp['message']
|
|
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_get_user_service_service_not_exists(notify_api, notify_db, notify_db_session, sample_service,
|
|
|
|
|
sample_admin_service_id):
|
2016-01-11 18:09:10 +00:00
|
|
|
"""
|
|
|
|
|
Tests GET endpoint "/<user_id>/service/<service_id>" 404 is returned for invalid service.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
|
|
|
|
user = User.query.first()
|
2016-01-15 16:22:03 +00:00
|
|
|
assert Service.query.count() == 2
|
|
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
|
|
|
|
path=url_for('user.get_service_by_user_id', user_id=user.id,
|
2016-01-21 12:13:17 +00:00
|
|
|
service_id="12323423"),
|
2016-01-15 16:22:03 +00:00
|
|
|
method='GET')
|
2016-01-11 18:09:10 +00:00
|
|
|
resp = client.get(
|
2016-01-21 12:13:17 +00:00
|
|
|
url_for('user.get_service_by_user_id', user_id=user.id, service_id="12323423"),
|
2016-01-15 16:22:03 +00:00
|
|
|
headers=[('Content-Type', 'application/json'), auth_header])
|
2016-01-11 18:09:10 +00:00
|
|
|
assert resp.status_code == 404
|
|
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
|
|
|
|
assert "Service not found" in json_resp['message']
|
2016-01-12 10:39:49 +00:00
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_delete_user(notify_api, notify_db, notify_db_session, sample_user, sample_admin_service_id):
|
2016-01-12 10:59:27 +00:00
|
|
|
"""
|
|
|
|
|
Tests DELETE endpoint '/<user_id>' delete user.
|
|
|
|
|
"""
|
2016-01-12 10:39:49 +00:00
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 2
|
|
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
|
|
|
|
path=url_for('user.update_user', user_id=sample_user.id),
|
|
|
|
|
method='DELETE')
|
2016-01-12 10:39:49 +00:00
|
|
|
resp = client.delete(
|
2016-01-15 16:22:03 +00:00
|
|
|
url_for('user.update_user', user_id=sample_user.id),
|
|
|
|
|
headers=[('Content-Type', 'application/json'), auth_header])
|
2016-01-12 10:39:49 +00:00
|
|
|
assert resp.status_code == 202
|
|
|
|
|
json_resp = json.loads(resp.get_data(as_text=True))
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 1
|
2016-01-19 11:38:29 +00:00
|
|
|
expected = {
|
|
|
|
|
"name": "Test User",
|
|
|
|
|
"email_address": sample_user.email_address,
|
2016-01-22 14:43:30 +00:00
|
|
|
"mobile_number": "+447700900986",
|
2016-01-19 11:38:29 +00:00
|
|
|
"password_changed_at": None,
|
|
|
|
|
"id": sample_user.id,
|
|
|
|
|
"logged_in_at": None,
|
|
|
|
|
"state": "active",
|
|
|
|
|
"failed_login_count": 0
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
assert json_resp['data'] == expected
|
2016-01-12 10:59:27 +00:00
|
|
|
|
|
|
|
|
|
2016-01-15 16:22:03 +00:00
|
|
|
def test_delete_user_not_exists(notify_api, notify_db, notify_db_session, sample_user, sample_admin_service_id):
|
2016-01-12 10:59:27 +00:00
|
|
|
"""
|
|
|
|
|
Tests DELETE endpoint '/<user_id>' delete user.
|
|
|
|
|
"""
|
|
|
|
|
with notify_api.test_request_context():
|
|
|
|
|
with notify_api.test_client() as client:
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 2
|
|
|
|
|
auth_header = create_authorization_header(service_id=sample_admin_service_id,
|
2016-01-19 13:59:45 +00:00
|
|
|
path=url_for('user.update_user', user_id='99999'),
|
2016-01-15 16:22:03 +00:00
|
|
|
method='DELETE')
|
2016-01-12 10:59:27 +00:00
|
|
|
resp = client.delete(
|
2016-01-19 13:59:45 +00:00
|
|
|
url_for('user.update_user', user_id="99999"),
|
2016-01-15 16:22:03 +00:00
|
|
|
headers=[('Content-Type', 'application/json'), auth_header])
|
2016-01-12 10:59:27 +00:00
|
|
|
assert resp.status_code == 404
|
2016-01-15 16:22:03 +00:00
|
|
|
assert User.query.count() == 2
|