2016-01-08 12:18:12 +00:00
|
|
|
import pytest
|
2016-01-15 12:16:07 +00:00
|
|
|
from app.models import (User, Service, Template, Token, Job)
|
2016-01-14 11:30:45 +00:00
|
|
|
from app.dao.users_dao import (save_model_user)
|
2016-01-11 17:19:06 +00:00
|
|
|
from app.dao.services_dao import save_model_service
|
2016-01-13 11:04:13 +00:00
|
|
|
from app.dao.templates_dao import save_model_template
|
2016-01-14 11:30:45 +00:00
|
|
|
from app.dao.tokens_dao import save_model_token
|
2016-01-15 12:16:07 +00:00
|
|
|
from app.dao.jobs_dao import save_job
|
|
|
|
|
import uuid
|
2016-01-08 12:18:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
|
def sample_user(notify_db,
|
|
|
|
|
notify_db_session,
|
|
|
|
|
email="notify@digital.cabinet-office.gov.uk"):
|
2016-01-11 15:07:13 +00:00
|
|
|
user = User(**{'email_address': email})
|
2016-01-11 17:19:06 +00:00
|
|
|
save_model_user(user)
|
2016-01-11 15:07:13 +00:00
|
|
|
return user
|
2016-01-08 12:18:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
|
def sample_service(notify_db,
|
|
|
|
|
notify_db_session,
|
|
|
|
|
service_name="Sample service",
|
|
|
|
|
user=None):
|
|
|
|
|
if user is None:
|
|
|
|
|
user = sample_user(notify_db, notify_db_session)
|
2016-01-11 15:07:13 +00:00
|
|
|
data = {
|
|
|
|
|
'name': service_name,
|
|
|
|
|
'users': [user],
|
|
|
|
|
'limit': 1000,
|
|
|
|
|
'active': False,
|
|
|
|
|
'restricted': False}
|
|
|
|
|
service = Service(**data)
|
2016-01-11 17:19:06 +00:00
|
|
|
save_model_service(service)
|
2016-01-11 15:07:13 +00:00
|
|
|
return service
|
2016-01-13 11:04:13 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
|
def sample_template(notify_db,
|
|
|
|
|
notify_db_session,
|
|
|
|
|
template_name="Template Name",
|
|
|
|
|
template_type="sms",
|
|
|
|
|
content="This is a template",
|
|
|
|
|
service=None):
|
|
|
|
|
if service is None:
|
|
|
|
|
service = sample_service(notify_db, notify_db_session)
|
|
|
|
|
data = {
|
|
|
|
|
'name': template_name,
|
|
|
|
|
'template_type': template_type,
|
|
|
|
|
'content': content,
|
|
|
|
|
'service': service
|
|
|
|
|
}
|
|
|
|
|
template = Template(**data)
|
|
|
|
|
save_model_template(template)
|
|
|
|
|
return template
|
2016-01-14 11:30:45 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
|
def sample_token(notify_db,
|
|
|
|
|
notify_db_session,
|
|
|
|
|
service=None):
|
|
|
|
|
if service is None:
|
|
|
|
|
service = sample_service(notify_db, notify_db_session)
|
|
|
|
|
data = {'service_id': service.id}
|
|
|
|
|
token = Token(**data)
|
|
|
|
|
save_model_token(token)
|
|
|
|
|
return token
|
2016-01-15 12:16:07 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='function')
|
|
|
|
|
def sample_job(notify_db,
|
|
|
|
|
notify_db_session,
|
|
|
|
|
service=None,
|
|
|
|
|
template=None):
|
|
|
|
|
if service is None:
|
|
|
|
|
service = sample_service(notify_db, notify_db_session)
|
|
|
|
|
if template is None:
|
|
|
|
|
template = sample_template(notify_db, notify_db_session,
|
|
|
|
|
service=service)
|
|
|
|
|
data = {
|
|
|
|
|
'id': uuid.uuid4(),
|
|
|
|
|
'service_id': service.id,
|
|
|
|
|
'template_id': template.id,
|
|
|
|
|
'original_file_name': 'some.csv'
|
|
|
|
|
}
|
|
|
|
|
job = Job(**data)
|
|
|
|
|
save_job(job)
|
|
|
|
|
return job
|