-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7aee10e
commit aa3ffe1
Showing
9 changed files
with
95 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations | ||
|
||
|
||
def convert_notifications(apps, schema_editor): | ||
""" Fixes any broken URL's in pending migrations due to: NoReverseMatch at / Reverse for 'docs' #175. """ | ||
Notification = apps.get_model('dsmr_frontend', 'Notification') | ||
Notification.objects.filter(redirect_to='frontend:docs').update(redirect_to='frontend:docs-redirect') | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dsmr_frontend', '0008_merge_electricity_tariffs_notification'), | ||
] | ||
|
||
operations = [ | ||
migrations.RunPython(convert_notifications), | ||
] |
41 changes: 41 additions & 0 deletions
41
dsmr_frontend/tests/regression/test_renamed_docs_reverse_url.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from django.db.migrations.executor import MigrationExecutor | ||
from django.core.urlresolvers import reverse, NoReverseMatch | ||
from django.test import TestCase, Client | ||
from django.db import connection | ||
from django.apps import apps | ||
|
||
from dsmr_frontend.models.message import Notification | ||
from django.db.migrations.recorder import MigrationRecorder | ||
|
||
|
||
class TestRegression(TestCase): | ||
""" | ||
Regression for: NoReverseMatch at / Reverse for 'docs' #175. | ||
Thanks to: https://www.caktusgroup.com/blog/2016/02/02/writing-unit-tests-django-migrations/ | ||
""" | ||
|
||
@property | ||
def app(self): | ||
return apps.get_containing_app_config(type(self).__module__).name | ||
|
||
def setUp(self): | ||
self.client = Client() | ||
|
||
def test_no_reverse_match_docs(self): | ||
""" Test whether the docs URL in old notfications are converted to their new location. """ | ||
Notification.objects.create( | ||
message='Fake', | ||
redirect_to='frontend:docs', # Non-existing legacy. | ||
) | ||
|
||
with self.assertRaises(NoReverseMatch): | ||
# This SHOULD crash. | ||
self.client.get(reverse('frontend:dashboard')) | ||
|
||
# Now we fake applying the migration (again for this test). | ||
MigrationRecorder.Migration.objects.filter(app='dsmr_frontend', name='0009_docs_no_reverse_match').delete() | ||
MigrationExecutor(connection=connection).migrate([(self.app, '0009_docs_no_reverse_match')]) | ||
|
||
# The error should be fixed now. | ||
response = self.client.get(reverse('frontend:dashboard')) | ||
self.assertEqual(response.status_code, 200) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters