Skip to content

Commit dbd1708

Browse files
PiDelportblag
authored andcommitted
Add regression tests for saving with force_insert
1 parent a54857c commit dbd1708

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed
Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
from django.contrib.gis.geos import Point
2+
from django.test import TestCase
3+
4+
from cities import models
5+
6+
7+
class SlugModelTest(object):
8+
"""
9+
Common tests for SlugModel subclasses.
10+
"""
11+
12+
def instantiate(self):
13+
"""
14+
Implement this to return a valid instance of the model under test.
15+
"""
16+
raise NotImplementedError
17+
18+
def test_save(self):
19+
instance = self.instantiate()
20+
instance.save()
21+
22+
def test_save_force_insert(self):
23+
"""
24+
Regression test: save() with force_insert=True should work.
25+
"""
26+
instance = self.instantiate()
27+
instance.save(force_insert=True)
28+
29+
30+
class ContinentTestCase(SlugModelTest, TestCase):
31+
32+
def instantiate(self):
33+
return models.Continent()
34+
35+
36+
class CountryTestCase(SlugModelTest, TestCase):
37+
38+
def instantiate(self):
39+
return models.Country(
40+
population=0,
41+
)
42+
43+
44+
class RegionTestCase(SlugModelTest, TestCase):
45+
46+
def instantiate(self):
47+
country = models.Country(
48+
population=0
49+
)
50+
country.save()
51+
return models.Region(
52+
country=country,
53+
)
54+
55+
56+
class SubregionTestCase(SlugModelTest, TestCase):
57+
58+
def instantiate(self):
59+
country = models.Country(
60+
population=0
61+
)
62+
country.save()
63+
region = models.Region(
64+
country=country,
65+
)
66+
region.save()
67+
return models.Subregion(
68+
region=region,
69+
)
70+
71+
72+
class CityTestCase(SlugModelTest, TestCase):
73+
74+
def instantiate(self):
75+
country = models.Country(
76+
population=0
77+
)
78+
country.save()
79+
return models.City(
80+
country=country,
81+
location=Point(0, 0),
82+
population=0,
83+
)
84+
85+
86+
class DistrictTestCase(SlugModelTest, TestCase):
87+
88+
def instantiate(self):
89+
country = models.Country(
90+
population=0
91+
)
92+
country.save()
93+
city = models.City(
94+
country=country,
95+
location=Point(0, 0),
96+
population=0,
97+
)
98+
city.save()
99+
return models.District(
100+
location=Point(0, 0),
101+
population=0,
102+
city=city,
103+
)
104+
105+
106+
class AlternativeNameTestCase(SlugModelTest, TestCase):
107+
108+
def instantiate(self):
109+
return models.AlternativeName()
110+
111+
112+
class PostalCodeTestCase(SlugModelTest, TestCase):
113+
114+
def instantiate(self):
115+
country = models.Country(
116+
population=0
117+
)
118+
country.save()
119+
return models.PostalCode(
120+
location=Point(0, 0),
121+
country=country,
122+
)

0 commit comments

Comments
 (0)