def test_should_get_jobs_seven_days_old_filters_type(notify_db, notify_db_session): eight_days_ago = datetime.utcnow() - timedelta(days=8) letter_template = create_template(notify_db, notify_db_session, template_type=LETTER_TYPE) sms_template = create_template(notify_db, notify_db_session, template_type=SMS_TYPE) email_template = create_template(notify_db, notify_db_session, template_type=EMAIL_TYPE) job = partial(create_job, notify_db, notify_db_session, created_at=eight_days_ago) job_to_remain = job(template=letter_template) job(template=sms_template) job(template=email_template) jobs = dao_get_jobs_older_than_limited_by(job_types=[EMAIL_TYPE, SMS_TYPE]) assert len(jobs) == 2 assert job_to_remain.id not in [job.id for job in jobs]
def deactivated_service(client, notify_db, notify_db_session, sample_service): create_template(notify_db, notify_db_session, template_name='a') create_template(notify_db, notify_db_session, template_name='b') create_api_key(notify_db, notify_db_session) create_api_key(notify_db, notify_db_session) auth_header = create_authorization_header() response = client.post('/service/{}/deactivate'.format(sample_service.id), headers=[auth_header]) assert response.status_code == 204 assert response.data == b'' return sample_service
def archived_service(client, notify_db, notify_db_session, sample_service): create_template(notify_db, notify_db_session, template_name='a') create_template(notify_db, notify_db_session, template_name='b') create_api_key(notify_db, notify_db_session) create_api_key(notify_db, notify_db_session) auth_header = create_authorization_header() response = client.post('/service/{}/archive'.format(sample_service.id), headers=[auth_header]) assert response.status_code == 204 assert response.data == b'' return sample_service
def test_get_jobs_for_service(notify_db, notify_db_session, sample_template): from tests.app.conftest import sample_job as create_job from tests.app.conftest import sample_service as create_service from tests.app.conftest import sample_template as create_template from tests.app.conftest import sample_user as create_user one_job = create_job(notify_db, notify_db_session, sample_template.service, sample_template) other_user = create_user(notify_db, notify_db_session, email="*****@*****.**") other_service = create_service(notify_db, notify_db_session, user=other_user, service_name="other service") other_template = create_template(notify_db, notify_db_session, service=other_service) other_job = create_job(notify_db, notify_db_session, service=other_service, template=other_template) one_job_from_db = get_jobs_by_service(one_job.service_id) other_job_from_db = get_jobs_by_service(other_job.service_id) assert len(one_job_from_db) == 1 assert one_job == one_job_from_db[0] assert len(other_job_from_db) == 1 assert other_job == other_job_from_db[0] assert one_job_from_db != other_job_from_db
def test_get_jobs_for_service(notify_db, notify_db_session, sample_template): one_job = create_job(notify_db, notify_db_session, sample_template.service, sample_template) other_user = create_user(email="*****@*****.**") other_service = create_service(notify_db, notify_db_session, user=other_user, service_name="other service", email_from='other.service') other_template = create_template(notify_db, notify_db_session, service=other_service) other_job = create_job(notify_db, notify_db_session, service=other_service, template=other_template) one_job_from_db = dao_get_jobs_by_service_id(one_job.service_id).items other_job_from_db = dao_get_jobs_by_service_id(other_job.service_id).items assert len(one_job_from_db) == 1 assert one_job == one_job_from_db[0] assert len(other_job_from_db) == 1 assert other_job == other_job_from_db[0] assert one_job_from_db != other_job_from_db
def deactivated_service_with_deleted_stuff(client, notify_db, notify_db_session, sample_service): with freeze_time('2001-01-01'): template = create_template(notify_db, notify_db_session, template_name='a') api_key = create_api_key(notify_db, notify_db_session) expire_api_key(sample_service.id, api_key.id) template.archived = True dao_update_template(template) with freeze_time('2002-02-02'): auth_header = create_authorization_header() response = client.post('/service/{}/deactivate'.format(sample_service.id), headers=[auth_header]) assert response.status_code == 204 assert response.data == b'' return sample_service
def archived_service_with_deleted_stuff(client, notify_db, notify_db_session, sample_service): with freeze_time('2001-01-01'): template = create_template(notify_db, notify_db_session, template_name='a') api_key = create_api_key(notify_db, notify_db_session) expire_api_key(sample_service.id, api_key.id) template.archived = True dao_update_template(template) with freeze_time('2002-02-02'): auth_header = create_authorization_header() response = client.post('/service/{}/archive'.format(sample_service.id), headers=[auth_header]) assert response.status_code == 204 assert response.data == b'' return sample_service
def test_get_jobs_for_service(notify_db, notify_db_session, sample_template): one_job = create_job(notify_db, notify_db_session, sample_template.service, sample_template) other_user = create_user(notify_db, notify_db_session, email="*****@*****.**") other_service = create_service(notify_db, notify_db_session, user=other_user, service_name="other service", email_from='other.service') other_template = create_template(notify_db, notify_db_session, service=other_service) other_job = create_job(notify_db, notify_db_session, service=other_service, template=other_template) one_job_from_db = dao_get_jobs_by_service_id(one_job.service_id).items other_job_from_db = dao_get_jobs_by_service_id(other_job.service_id).items assert len(one_job_from_db) == 1 assert one_job == one_job_from_db[0] assert len(other_job_from_db) == 1 assert other_job == other_job_from_db[0] assert one_job_from_db != other_job_from_db
def test_get_jobs(notify_db, notify_db_session, sample_template): one_job = create_job(notify_db, notify_db_session, sample_template.service, sample_template) other_user = create_user(email="*****@*****.**") other_service = create_service(notify_db, notify_db_session, user=other_user, service_name="other service", email_from='other.service') other_template = create_template(notify_db, notify_db_session, service=other_service) other_job = create_job(notify_db, notify_db_session, service=other_service, template=other_template) jobs = dao_get_jobs().all() assert len(jobs) == 2 assert jobs[0] == other_job assert jobs[1] == one_job