Avoid assigning notification.template when creating test objects

`Notification.template` changed from being a Template relationship
to TemplateHistory. When a relationship attribute is being assigned,
SQLAlchemy checks that the assigned value type matches the relationship
type. Since most tests at the moment create a notification using a
Template instance this check fails.

Rewriting the tests to use TemplateHistory objects would require
changes to the majority of tests. Instead, when creating a notification
objects we assign the foreign key attributes directly. This skips the
SQLAlchemy type check, but we still get the constraint check on the
foreign keys, so a matching TemplateHistory object needs to exist in
the database.
This commit is contained in:
Alexey Bezhan
2017-11-09 14:31:31 +00:00
parent e73513f519
commit 94dae42902
5 changed files with 12 additions and 14 deletions

View File

@@ -544,8 +544,7 @@ def sample_notification(
'job': job,
'service_id': service.id,
'service': service,
'template_id': template.id if template else None,
'template': template,
'template_id': template.id,
'template_version': template.version,
'status': status,
'reference': reference,
@@ -624,7 +623,7 @@ def sample_email_notification(notify_db, notify_db_session):
'job': job,
'service_id': service.id,
'service': service,
'template': template,
'template_id': template.id,
'template_version': template.version,
'status': 'created',
'reference': None,