Merge pull request #623 from alphagov/test-fixes

Test fixes
This commit is contained in:
Leo Hemsted
2016-08-30 10:38:53 +01:00
committed by GitHub
11 changed files with 42 additions and 24 deletions

View File

@@ -75,7 +75,7 @@ upload-codedeploy-artifact: check-env-vars
aws s3 cp --region eu-west-1 target/notifications-api.zip s3://${DNS_NAME}-codedeploy/notifications-api-${DEPLOY_BUILD_NUMBER}.zip
.PHONY: test
test: venv ## Run tests
test: venv generate-version-file ## Run tests
./scripts/run_tests.sh
.PHONY: deploy-api

View File

@@ -72,6 +72,22 @@ scripts/run_celery_beat.sh
```
## To test the application
First, ensure that `scripts/boostrap.sh` has been run, as it creates the test database.
Then simply run
```
make test
```
That will run pep8 for code analysis and our unit test suite. If you wish to run our functional tests, instructions can be found in the
[notifications-functional-test](https://github.com/alphagov/notifications-functional-test) repository.
## To remove functional test data
NOTE: There is assumption that both the server name prefix and user name prefix are followed by a uuid.

View File

@@ -105,7 +105,7 @@ def send_sms_to_provider(self, service_id, notification_id):
def provider_to_use(notification_type, notification_id):
active_providers_in_order = [
provider for provider in get_provider_details_by_notification_type(notification_type) if provider.active
]
]
if not active_providers_in_order:
current_app.logger.error(

View File

@@ -75,7 +75,7 @@ def process_job(job_id):
'personalisation': {
key: personalisation.get(key)
for key in template.placeholders
}
}
})
if template.template_type == SMS_TYPE:

View File

@@ -73,7 +73,7 @@ class MMGClient(SmsClient):
"reqType": "BULK",
"MSISDN": to,
"msg": content,
"sender": self.from_number if sender is None else sender,
"sender": self.from_number if sender is None else sender,
"cid": reference,
"multi": multi
}

View File

@@ -9,7 +9,7 @@ from app.models import (
EMAIL_TYPE,
NOTIFICATION_STATUS_TYPES_BILLABLE,
KEY_TYPE_TEST
)
)
def get_provider_statistics(service, **kwargs):

View File

@@ -201,10 +201,10 @@ def create_history(obj, history_cls=None):
# not yet have a value before insert
elif isinstance(prop, RelationshipProperty):
if hasattr(history, prop.key+'_id'):
if hasattr(history, prop.key + '_id'):
foreign_obj = getattr(obj, prop.key)
# if it's a nullable relationship, foreign_obj will be None, and we actually want to record that
data[prop.key+'_id'] = getattr(foreign_obj, 'id', None)
data[prop.key + '_id'] = getattr(foreign_obj, 'id', None)
if not obj.version:
obj.version = 1

View File

@@ -431,7 +431,7 @@ class NotificationsFilterSchema(ma.Schema):
class TemplateStatisticsSchema(BaseSchema):
template = fields.Nested(TemplateSchema, only=["id", "name", "template_type"], dump_only=True)
template = fields.Nested(TemplateSchema, only=["id", "name", "template_type"], dump_only=True)
class Meta:
model = models.TemplateStatistics

View File

@@ -24,7 +24,7 @@ function display_result {
fi
}
if [ -d venv ]; then
if [[ -z "$VIRTUAL_ENV" ]] && [[ -d venv ]]; then
source ./venv/bin/activate
fi
pep8 .

View File

@@ -1,4 +1,4 @@
[pep8]
max-line-length = 120
ignore = E402
exclude = ./migrations,./venv,./venv3

View File

@@ -236,13 +236,14 @@ def test_send_user_sms_code(notify_api,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
assert mocked.call_count == 1
encrypted = encryption.encrypt({'template': current_app.config['SMS_CODE_TEMPLATE_ID'],
'template_version': 1,
'to': sample_user.mobile_number,
'personalisation': {
'verify_code': '11111'
}
})
encrypted = encryption.encrypt({
'template': current_app.config['SMS_CODE_TEMPLATE_ID'],
'template_version': 1,
'to': sample_user.mobile_number,
'personalisation': {
'verify_code': '11111'
}
})
app.celery.tasks.send_sms.apply_async.assert_called_once_with(
([current_app.config['NOTIFY_SERVICE_ID'],
"some_uuid",
@@ -274,13 +275,14 @@ def test_send_user_code_for_sms_with_optional_to_field(notify_api,
headers=[('Content-Type', 'application/json'), auth_header])
assert resp.status_code == 204
encrypted = encryption.encrypt({'template': current_app.config['SMS_CODE_TEMPLATE_ID'],
'template_version': 1,
'to': '+441119876757',
'personalisation': {
'verify_code': '11111'
}
})
encrypted = encryption.encrypt({
'template': current_app.config['SMS_CODE_TEMPLATE_ID'],
'template_version': 1,
'to': '+441119876757',
'personalisation': {
'verify_code': '11111'
}
})
assert mocked.call_count == 1
app.celery.tasks.send_sms.apply_async.assert_called_once_with(
([current_app.config['NOTIFY_SERVICE_ID'],