2016-01-15 15:15:35 +00:00
|
|
|
from flask.testing import FlaskClient
|
|
|
|
|
from flask import url_for
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class TestClient(FlaskClient):
|
|
|
|
|
def login(self, user):
|
|
|
|
|
# Skipping authentication here and just log them in
|
|
|
|
|
with self.session_transaction() as session:
|
2016-01-27 12:22:32 +00:00
|
|
|
session['user_details'] = {
|
|
|
|
|
"email": user.email_address,
|
|
|
|
|
"id": user.id}
|
|
|
|
|
# Include mock_login fixture in test for this to work.
|
|
|
|
|
# TODO would be better for it to be mocked in this
|
|
|
|
|
# function
|
2016-01-15 15:15:35 +00:00
|
|
|
response = self.post(
|
|
|
|
|
url_for('main.two_factor'), data={'sms_code': '12345'})
|
2016-01-15 16:10:24 +00:00
|
|
|
assert response.status_code == 302
|
2016-01-15 15:15:35 +00:00
|
|
|
|
|
|
|
|
def logout(self, user):
|
|
|
|
|
self.get(url_for("main.logout"))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def service_json(id_, name, users, limit=1000, active=False, restricted=True):
|
|
|
|
|
return {
|
|
|
|
|
'id': id_,
|
|
|
|
|
'name': name,
|
|
|
|
|
'users': users,
|
|
|
|
|
'limit': limit,
|
|
|
|
|
'active': active,
|
|
|
|
|
'restricted': restricted
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 17:35:28 +00:00
|
|
|
|
2016-01-19 15:54:12 +00:00
|
|
|
def template_json(id_, name, type_, content, service_id):
|
|
|
|
|
return {
|
|
|
|
|
'id': id_,
|
|
|
|
|
'name': name,
|
|
|
|
|
'template_type': type_,
|
|
|
|
|
'content': content,
|
|
|
|
|
'service': service_id
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-01-21 12:28:05 +00:00
|
|
|
def api_key_json(id_, name, expiry_date=None):
|
|
|
|
|
return {'id': id_,
|
|
|
|
|
'name': name,
|
|
|
|
|
'expiry_date': expiry_date
|
|
|
|
|
}
|
|
|
|
|
|
2016-01-18 16:01:04 +00:00
|
|
|
TEST_USER_EMAIL = 'test@user.gov.uk'
|
2016-01-15 15:15:35 +00:00
|
|
|
|
2016-01-18 17:35:28 +00:00
|
|
|
|
2016-01-15 15:15:35 +00:00
|
|
|
def create_test_user(state):
|
2016-01-27 16:30:33 +00:00
|
|
|
from app.main.dao import users_dao
|
2016-01-27 12:22:32 +00:00
|
|
|
user = None
|
2016-01-15 15:15:35 +00:00
|
|
|
users_dao.insert_user(user)
|
|
|
|
|
return user
|
|
|
|
|
|
|
|
|
|
|
2016-01-19 22:47:42 +00:00
|
|
|
def create_test_api_user(state):
|
|
|
|
|
from app.notify_client.user_api_client import User
|
|
|
|
|
user_data = {'id': 1,
|
|
|
|
|
'name': 'Test User',
|
|
|
|
|
'password': 'somepassword',
|
|
|
|
|
'email_address': TEST_USER_EMAIL,
|
|
|
|
|
'mobile_number': '+441234123412',
|
|
|
|
|
'state': state
|
|
|
|
|
}
|
|
|
|
|
user = User(user_data)
|
|
|
|
|
return user
|
|
|
|
|
|
|
|
|
|
|
2016-01-15 15:15:35 +00:00
|
|
|
def create_another_test_user(state):
|
2016-01-27 16:30:33 +00:00
|
|
|
from app.main.dao import users_dao
|
2016-01-27 12:22:32 +00:00
|
|
|
user = None
|
2016-01-15 15:15:35 +00:00
|
|
|
users_dao.insert_user(user)
|
|
|
|
|
return user
|
2016-01-18 16:01:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_test_user():
|
2016-01-27 16:30:33 +00:00
|
|
|
from app.main.dao import users_dao
|
2016-01-18 16:01:04 +00:00
|
|
|
return users_dao.get_user_by_email(TEST_USER_EMAIL)
|