Skip to content

Commit

Permalink
Improve test running with changed settings/order.
Browse files Browse the repository at this point in the history
A couple of tests were e.g. altering mapit.models.countries and not
setting it back, and another two would only pass if COUNTRY was set
to 'GB'. Set those to skip, and restore original settings.
  • Loading branch information
dracos committed May 9, 2017
1 parent 212d387 commit 2b47eae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
4 changes: 4 additions & 0 deletions mapit/tests/test_names.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ def setUp(self):
def test_new_name_changes_area_name_in_gb(self):
"""We can't use override_settings, as mapit.countries has been set
based upon MAPIT_COUNTRY already in initial import"""
orig_countries = mapit.models.countries
mapit.models.countries = mapit_gb.countries
Name.objects.create(name='New Name (B)', type=self.name_type, area=self.area)
self.assertEqual(self.area.name, 'New Name Borough')
mapit.models.countries = orig_countries

def test_new_name_does_not_change_area_name_elsewhere(self):
orig_countries = mapit.models.countries
mapit.models.countries = None
Name.objects.create(name='New Name', type=self.name_type, area=self.area)
self.assertEqual(self.area.name, 'Big Area')
mapit.models.countries = orig_countries

def test_geometry_name_works(self):
name = smart_text('Big “Area”')
Expand Down
7 changes: 3 additions & 4 deletions mapit/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import json
import unittest

from django.test import TestCase
from django.conf import settings
from django.contrib.gis.geos import Polygon, Point

from mapit.models import Type, Area, Geometry, Generation, Postcode
from mapit.tests.utils import get_content
import mapit_gb.countries
import mapit.views


class AreaViewsTest(TestCase):
Expand Down Expand Up @@ -89,8 +88,8 @@ def test_front_page(self):
response = self.client.get('/')
self.assertContains(response, 'MapIt')

@unittest.skipUnless(settings.MAPIT_COUNTRY == 'GB', 'UK only test')
def test_postcode_submission(self):
mapit.views.countries = mapit_gb.countries
response = self.client.post('/postcode/', {'pc': 'PO14 1NT'}, follow=True)
self.assertRedirects(response, '/postcode/PO141NT.html')
response = self.client.post('/postcode/', {'pc': 'PO141NT.'}, follow=True)
Expand All @@ -107,7 +106,7 @@ def test_example_postcode(self):
url = '/area/%d/example_postcode' % id
response = self.client.get(url)
content = get_content(response)
self.assertEqual(content, self.postcode.postcode)
self.assertEqual(content, str(self.postcode))

def test_nearest_with_bad_srid(self):
url = '/nearest/84/0,0.json'
Expand Down
9 changes: 7 additions & 2 deletions mapit_gb/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import unittest
from django.conf import settings
from django.test import TestCase
from django.contrib.gis.geos import Polygon, Point
Expand All @@ -16,8 +17,8 @@ def url_postcode(pc):
class GBViewsTest(TestCase):
def setUp(self):
# Make sure we're using the GB postcode functions here
models.countries = countries
utils.countries = countries
self.orig_countries = models.countries
models.countries = utils.countries = countries

self.postcode = models.Postcode.objects.create(
postcode='SW1A1AA',
Expand Down Expand Up @@ -67,6 +68,9 @@ def setUp(self):
code='E05000025',
)

def tearDown(self):
models.countries = utils.countries = self.orig_countries

def test_ni_postcode(self):
postcode = models.Postcode(postcode='BT170XD', location=Point(-6.037555, 54.556533))
grid = postcode.as_uk_grid()
Expand Down Expand Up @@ -158,6 +162,7 @@ def test_nearest_json_link(self):
pc = self.postcode.postcode
self.assertContains(response, '"/postcode/%s"' % url_postcode(pc))

@unittest.skipUnless(settings.MAPIT_COUNTRY == 'GB', 'UK only tests')
def test_gss_code(self):
response = self.client.get('/area/E05000025')
self.assertRedirects(response, '/area/%d' % self.area.id)
Expand Down

0 comments on commit 2b47eae

Please sign in to comment.