~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlmaps/tests/test_views.py

  • Committer: franku
  • Date: 2018-11-21 17:54:32 UTC
  • mfrom: (508.1.1 widelands)
  • Revision ID: somal@arcor.de-20181121175432-8rc3h0332xmgmma4
merged trunk, resolved conflicts

Show diffs side-by-side

added added

removed removed

Lines of Context:
143
143
            reverse('wlmaps_view', args=('a-map-that-doesnt-exist',)))
144
144
        self.assertEqual(c.status_code, 404)
145
145
 
146
 
 
147
 
############
148
 
#  RATING  #
149
 
############
150
 
class TestWLMapsViews_Rating(_LoginToSite):
151
 
 
152
 
    def setUp(self):
153
 
        _LoginToSite.setUp(self)
154
 
 
155
 
        # Add maps
156
 
        nm = Map.objects.create(
157
 
            name='Map',
158
 
            author='Author',
159
 
            w=128,
160
 
            h=64,
161
 
            nr_players=4,
162
 
            descr='a good map to play with',
163
 
            minimap='/wlmaps/minimaps/Map.png',
164
 
            world_name='blackland',
165
 
 
166
 
            uploader=self.user,
167
 
            uploader_comment='Rockdamap'
168
 
        )
169
 
        nm.save()
170
 
        self.map = nm
171
 
 
172
 
    def test_RatingNonExistingMap_Except404(self):
173
 
        c = self.client.post(
174
 
            reverse('wlmaps_rate', args=('a-map-that-doesnt-exist',)),
175
 
            {'vote': 10})
176
 
        self.assertEqual(c.status_code, 404)
177
 
 
178
 
    def test_RatingGet_Except405(self):
179
 
        c = self.client.get(
180
 
            reverse('wlmaps_rate', args=('map',)),
181
 
            {'vote': 10})
182
 
        self.assertEqual(c.status_code, 405)
183
 
 
184
 
    def test_RatingInvalidValue_Except400(self):
185
 
        c = self.client.post(
186
 
            reverse('wlmaps_rate', args=('map',)),
187
 
            {'vote': 11})
188
 
        self.assertEqual(c.status_code, 400)
189
 
 
190
 
    def test_RatingNonIntegerValue_Except400(self):
191
 
        c = self.client.post(
192
 
            reverse('wlmaps_rate', args=('map',)),
193
 
            {'vote': 'shubidu'})
194
 
        self.assertEqual(c.status_code, 400)
195
 
 
196
 
    def test_RatingExistingMap_ExceptCorrectResult(self):
197
 
        c = self.client.post(
198
 
            reverse('wlmaps_rate', args=('map',)),
199
 
            {'vote': 7})
200
 
        # Except redirect
201
 
        self.assertEqual(c.status_code, 302)
202
 
 
203
 
        # We have to refetch this map, because
204
 
        # votes doesn't hit the database
205
 
        m = Map.objects.get(slug='map')
206
 
 
207
 
        self.assertEqual(m.rating.votes, 1)
208
 
        self.assertEqual(m.rating.score, 7)