Commit Graph

68 Commits

Author SHA1 Message Date
David McDonald
91f5be835a Add DB table for service broadcast settings
This will allow us to store details of which channel a service should be
sending to.

See the comment about how all broadcast services can have a row in the
table but may not at the moment. This has been done for speed as it's
the quickest way to let us set up different services to send to
different channels for some needed testing with the mobile handset
providers in the coming week.
2021-02-01 14:10:37 +00:00
Leo Hemsted
36ae5fadf6 add broadcast_event table
It's clear that we need a way to track updates to a broadcast message.
It's also clear that we'll need some kind of audit log that captures
exactly what was sent out in a message.

This commit adds a new database table, `broadcast_event`, which maps 1:1
with CAP XML sent to the CBCs. We'll create one of these just before
sending out.

The main driver for this was that cancel and update messages need to
contain a list of references of all previous messages that they're
amending. This is of format `{sender},{identifier},{sent_timestamp}`,
and the identifier itself needs to be unique for each message.
2020-07-28 12:10:18 +01:00
Leo Hemsted
eb72a0279f remove monkeypatch
it's interacting strangely with our os.environ stuff and not restoring
nicely, probably due to fixture order which is hard to visualise and
control.
2020-01-06 17:53:56 +00:00
Leo Hemsted
d244146638 fix weird test isolation errors with os.environ and boto3
test_config manipulates os.environ. os.environ is an `environ` object,
which acts like a dict but isn't in some subtle unknowable ways. The
`reload_config` fixture would create a dict copy of the env, and then
just call `os.environ = old_env` afterwards.

Boto3 would then complain that it couldn't load credentials (despite us
using the mock_s3 fixture and also not having creds in the environment
in the first place). Not entirely sure why this happens, but it does.
For some reason, it being a `dict` instead of an `environ` object causes
the mocking of boto3 to fail.

The solution is to not overwrite os.environ entirely, rather, use the
standard dictionary setitem syntax to update the values to their
previous values. Use `clear` to empty the environment too.
2020-01-06 16:21:34 +00:00
Leo Hemsted
52a33f220b make tests use mmg 100% of the time by default
we randomly choose between sms providers now - this means that tests may
sometimes send firetext and sometimes mmg, so we'd need to patch out
different HTTP calls, expect different values in sent_by, etc etc.

To ensure tests are consistent, add a new fixture that is always used by
notify_db_session, which sets the priorities of the sms providers to
100% mmg 0% firetext. if you need to test other values, then you should
set the values manually in the test file
2019-11-28 13:29:02 +00:00
Pea Tyczynska
38bb2c1cf6 Simpify org types migration script and introduce foreign key
Don't transform org types on prod
2019-07-24 17:55:56 +01:00
Leo Hemsted
28bff28786 remove letter rates between tests
we only use them in ft_billing so no reason not to delete them. makes
the tests read better as it's obvious how they work too.
2019-04-03 15:34:02 +01:00
Leo Hemsted
06f9e445f7 remove dvla_organisation from database
downgrade re-populates all static data but leaves all services with 001
(HM Government) branding
2019-02-14 14:27:59 +00:00
Leo Hemsted
ac5c19c3d5 remove some pytest warnings 2018-10-26 17:54:53 +01:00
Leo Hemsted
5c4f3e246c make test dvla response file timestamps in a random order
since there'll be a bunch of threads running functional test tasks at
the same time, there's no point always trying to start from the same
second and then stepping back to the same one-second-back file each
time. Also, this leads us to an increased risk of race conditions.

This change takes the same thirty second range, but shuffles it. The
tests, since they're no longer deterministic, now use a new Matcher
object (w/ credit to alexey) to match any filename from within that
thirty second range
2018-07-20 12:09:00 +01:00
Pea Tyczynska
183aa160c6 Add callback_type column to service_callback_api table
Also add service_callback_type table with allowed types
2018-07-17 16:54:00 +01:00
Katie Smith
c57f33a02d Use real letter_rates in tests
Added the letter_rate table to the list of tables which does not get
deleted after each test run and changed the tests to use the real letter
rates.

Also removed the letter rate DAO since this was only being used in
tests, so was no longer needed.
2018-07-10 11:31:18 +01:00
Athanasios Voutsadakis
6f1e4c76d5 Make test context managers more reliable
Sometimes, when a test using one of the set_config[_values] context managers
failed or raised an exception it would cause the context to not be able
to revert its config changes, resulting in a 'spooky action at a
distance' where random tests would start to fail for non-obvious reasons.
2018-03-27 17:41:05 +01:00
Leo Hemsted
57a174aeb4 add tests for org invite rest, and update conftest 2018-02-23 10:45:18 +00:00
Leo Hemsted
450deae32a add user_to_organisation and invited_organisation_users tables
similar to user_to_service and invited_users, but without auth types
or permissions
2018-02-15 14:19:24 +00:00
Leo Hemsted
5466b7cd3c fix test create_app invocation 2017-11-23 17:04:58 +00:00
Leo Hemsted
7c8586f959 add auth_type to schemas to enable updating in endpoints 2017-10-30 12:29:01 +00:00
Leo Hemsted
6acea8323b fixup! add auth type table, currently contains sms_auth and email_auth 2017-10-30 11:59:32 +00:00
Leo Hemsted
c39ec90727 add auth type table, currently contains sms_auth and email_auth 2017-10-30 11:11:37 +00:00
Leo Hemsted
2fefe8a957 use sqlalchemy hooks rather than pyscopg2
seems to play nicer with docker?
2017-08-29 18:03:15 +01:00
Leo Hemsted
3d4dbaa632 run tests in multiple threads at once
previously we didn't do this because the tests all used the same DB
(test_notifications_api), however @minglis shared a snippet that simply
creates one test db per thread.
2017-08-29 17:46:11 +01:00
Leo Hemsted
c36e50bef1 update dependencies 2017-08-18 17:02:31 +01:00
Leo Hemsted
7f883f1355 don't store non-strings to os.environ
in tests, we were replacing os.environ with a basic dict so that
we didn't overwrite the contents of the real environment during tests.
However, os.environ doesn't accept non-str values, so this commit
changes the fixture so that it asserts all values set are strings.
We needed to change how we store ip whitelist stuff in the env because
of this.
2017-07-11 15:41:44 +01:00
Ken Tsang
114d4d84d4 Add service permissions DAO and refactor user service permission mock 2017-05-15 17:28:14 +01:00
Leo Hemsted
7e52fa4d13 add new notification_status column to models.py
We now have a new column in the database, but it isn't being
populated. The first step is to make sure we update this column,
while still keeping the old enum based column up to date as well.

A couple of changes have had to happen to support this - one irritating
thing is that if we're ever querying columns individually, including
`Notification.status`, then we'll need to give that column a label,
since under the hood it translates to `Notification._status_enum`.
Accessing status through the ORM (i.e., my_noti.status = 'sending' or
similar) will work fine.
2017-05-04 17:24:28 +01:00
Rebecca Law
6dc336ad6c Created new queries to return the rate with the sum of billable units for the year totals.
Once we have the new columns in notifications table, the query will need to include the rate multiplier and if the number is international.
The monthly billing query will be built next.
2017-04-28 10:10:48 +01:00
Rebecca Law
266c17dfd6 Do not delete rates 2017-04-24 16:32:23 +01:00
Imdad Ahad
c4fac1d937 Revert "Revert "add DVLA organisations to API"" 2017-04-21 16:05:07 +01:00
Leo Hemsted
c3e56d5d2d Revert "add DVLA organisations to API" 2017-04-20 18:21:56 +01:00
Leo Hemsted
d514d99a67 add DVLA organisations to API
when services are created, they'll have a dvla_org_id of 001, or
HM Government. That can be changed later using a regular update call
2017-04-19 16:31:18 +01:00
Imdad Ahad
73d5ce4f8b Add tests to verify correctness of the switching provider task 2017-02-24 12:23:39 +00:00
Andras Ferencz-Szabo
e10c5e28cd Merge pull request #763 from alphagov/cloudfoundry
Run on Paas
2017-01-17 11:28:38 +00:00
Rebecca Law
6c79ddbe41 This is the first deploy in series of deploys to give certain templates priority in processing.
If the template is marked as priority the notification will be sent using the `notify` queue.
The `notify` queue is a low volume queue, messages here will not be queue behind a large job and should be delivered with in a more consistent time frame.

- Added templates.process_type and templates_history.process_type column.
- Added a template_process_type table to handle the enum for templates.process_type, initial values are normal and priority

https://www.pivotaltracker.com/story/show/135429147
2017-01-13 12:14:34 +00:00
bandesz
fd66fbd719 Run API on Paas 2017-01-13 10:24:13 +00:00
Leo Hemsted
8bb0261c79 dont let user update prov details version, and refactor tests
the provider details tests were previously very stateful - they
would update a value, and then because provider_details is a "static"
table that is not wiped by the notify_db_session fixture, the tests
were forced to make a second update that reverted that change. if the
test fails for whatever reason, the provider_details table ends up
permanently modified, playing havoc on tests further down the line.

this commit adds the fixture `restore_provider_details` to conftest.
this fixture stores a copy of the contents of ProviderDetails and
ProviderDetailsHistory tables outside of the session, runs the test,
and then clears the table and puts those old values in

this means that the tests have been cleaned up so that they do not
do operations twice in reverse. they've also been cleaned up
generally, including fixture optimisations and such
2016-12-19 17:13:10 +00:00
Leo Hemsted
17cf582502 Merge branch 'master' into active-service 2016-11-10 13:54:02 +00:00
Leo Hemsted
f6de17d6b7 dont let people accidentally delete their local database by forcing it to run against a different DB (ie test_notifications_api) 2016-11-08 17:10:28 +00:00
Leo Hemsted
ed187f7fad remove 500/unplanned exception handlers in test
this means if your code throws an exception, in the test you'll see the full stack trace to help debugging
2016-11-04 16:37:55 +00:00
Leo Hemsted
00b905bef0 use a contextmanager to set config values
so that when later tests run, the config has been restored to its
defaults and we don't end up failing later tests in confusing ways
2016-09-21 17:13:26 +01:00
Leo Hemsted
6ceb80d32f Merge pull request #651 from alphagov/contract-tests
Contract tests
2016-09-05 11:31:29 +01:00
Leo Hemsted
7240df0641 replace mock with unittest.mock 2016-08-31 12:39:11 +01:00
Leo Hemsted
59346d7546 add new client fixture
replaces previous notify_api fixture with the age old:
```
    with notify_api.test_request_context():
        with notify_api.test_client() as client:
```

just runs those two context managers in a yield fixture (new pytest 3.0 feature)
2016-08-30 15:55:27 +01:00
Leo Hemsted
fa3d4413e7 update test requirements
requirements should be kept up to date to ensure we get bug fixes and new features as they come - particularly py.test, which we were running an 18 month old version for, and missing out on some useful xfail and fixture enhancements, among other things
2016-08-30 15:55:23 +01:00
Martyn Inglis
cf3c14dbbd Added job_status to marshmallow
- ensured statues not deleted on test runs
- returns in API call

Merge branch 'add-new-column-to-jobs-for-delayed-sending' into scheduled-delivery-of-jobs

Conflicts:
	app/models.py
2016-08-24 14:35:22 +01:00
Leo Hemsted
a6cd490942 add organisation and branding models
a service now has branding and organisation_id columns, and two new
tables have been aded to reflect these:
* branding is a static types table referring to how a service wants
  their emails to be branded:
    * 'govuk' for GOV UK branding (default)
    * 'org' for organisational branding only
    * 'both' for co-branded output with both
* organisation is a table defining an organisation's branding. this
  contains three entries, all of which are nullable
    * colour - a hex code for a coloured bar on the logo's left
    * logo - relative path for that org's logo image
    * name - the name to display on the right of the logo
2016-08-09 15:59:16 +01:00
Leo Hemsted
2d1babf2bb 'detailed' flag on GET /service/<uuid>
if passed in, returns the service object with additional statistics
dictionary, which will be used in the admin app to populate dashboard
components. A new schema has been created for this to avoid clashing/
causing confusion with the existing schema, which is already used
for PUT/POST as well, and this schema can be easily tailored to
reduce ambiguity and lazy-loading
2016-07-21 14:04:25 +01:00
Leo Hemsted
a355f3e544 add idparametrize pytest decorator
so you can specify test IDs in a reasonable dictionary syntax,
which is useful when the parameters may not be immediately
self-explanatory
2016-07-21 14:04:25 +01:00
Adam Shimali
c29dd23702 Add sms sender to service to be used in sms templates
in place of default numeric short code.

If not present default short code is used.
2016-07-01 15:27:54 +01:00
Leo Hemsted
e9482c7fe1 add new key_type table
* single-column static data table that currently contains two types: 'normal' and 'team'
* key_type foreign-keyed from api_keys
  - must be not null
  - existing rows set to 'normal'
* key_type foreign-keyed from notifications
  - nullable
  - existing rows set to null
* api_key foreign-keyed from notifications
  - nullable
  - existing rows set to null
2016-06-24 15:56:54 +01:00
Leo Hemsted
bffeaa773a Remove db.drop_all from notify_db session fixture to speed up tests
We were dropping all tables at the end of the test run, however the alembic_version table is not part of the metadata so was being persisted. Alembic then doesn't upgrade the database next test run, since the version appears up to date, so we were, in the notify_db_session fixture, recreating from MetaData (sqlalchemy models). This involves quite a costly comparison of the postgres system tables and the tables in models.py, which was adding half a second to each test that uses the notify_db_session fixture (virtually all of them).
2016-06-22 15:22:16 +01:00