~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to wlmaps/tests/test_models.py

  • Committer: Holger Rapp
  • Date: 2009-02-21 18:24:02 UTC
  • Revision ID: sirver@kallisto.local-20090221182402-k3tuf5c4gjwslbjf
Main Page contains now the same informations as before

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python -tt
2
 
# encoding: utf-8
3
 
#
4
 
 
5
 
from django.test import TestCase as DjangoTest, Client
6
 
from django.contrib.auth.models import User
7
 
from django.db import IntegrityError
8
 
 
9
 
from wlmaps.models import *
10
 
 
11
 
import os
12
 
 
13
 
#############
14
 
# TestCases #
15
 
#############
16
 
 
17
 
 
18
 
class TestWLMapsModels_Map(DjangoTest):
19
 
    urls = 'wlmaps.test_urls'
20
 
 
21
 
    def setUp(self):
22
 
        self.user = User.objects.create(username='testuser')
23
 
        self.user.save()
24
 
 
25
 
        # Add maps
26
 
        nm = Map.objects.create(
27
 
            name='Map',
28
 
            author='Author',
29
 
            w=128,
30
 
            h=64,
31
 
            nr_players=4,
32
 
            descr='a good map to play with',
33
 
            minimap='/wlmaps/minimaps/Map.png',
34
 
            world_name='blackland',
35
 
 
36
 
            uploader=self.user,
37
 
            uploader_comment='Rockdamap'
38
 
        )
39
 
        nm.save()
40
 
        self.map = nm
41
 
        nm = Map.objects.create(
42
 
            name='Map with a long slug',
43
 
            author='Author Paul',
44
 
            w=128,
45
 
            h=64,
46
 
            nr_players=4,
47
 
            descr='a good map to play with',
48
 
            minimap='/wlmaps/minimaps/Map with long slug.png',
49
 
            world_name='blackland',
50
 
 
51
 
            uploader=self.user,
52
 
            uploader_comment='Rockdamap'
53
 
        )
54
 
        nm.save()
55
 
        self.map1 = nm
56
 
 
57
 
    def test_validMapInsertion_expectCorrectResult(self):
58
 
        # This really tests the setUp functionality. let's
59
 
        # hope that this worked out
60
 
        self.assertEqual(Map.objects.get(pk=1), self.map)
61
 
 
62
 
    def test_MapNameGeneration_expectCorrectResult(self):
63
 
        self.assertEqual(repr(self.map), '<Map: Map by Author>')
64
 
 
65
 
    def test_Permalink_expectCorrectResult(self):
66
 
        self.assertEqual(self.map.get_absolute_url(), '/wlmaps/map/')
67
 
        self.assertEqual(self.map1.get_absolute_url(),
68
 
                         '/wlmaps/map-with-a-long-slug/')
69
 
 
70
 
    def test_Rating_ExceptCorrectResult(self):
71
 
        self.map.rating.add(score=10, user=self.user,
72
 
                            ip_address='127.0.0.1')
73
 
        self.assertEqual(self.map.rating.votes, 1)
74
 
        self.assertEqual(self.map.rating.score, 10)
75
 
 
76
 
    def test_DoubleAddingMapWithSameSlug_ExceptRaise(self):
77
 
        self.assertRaises(IntegrityError, Map.objects.create, ** {
78
 
            'name':             'Map with-a-long slug',
79
 
            'author':           'Author',
80
 
            'w':                128,
81
 
            'h':                64,
82
 
            'nr_players': 4,
83
 
            'descr':            'a good map to play with',
84
 
            'minimap':          '/wlmaps/minimaps/Map.png',
85
 
            'world_name':       'blackland',
86
 
            'uploader':         self.user,
87
 
            'uploader_comment': 'Rockdamap'
88
 
        }
89
 
        )
90
 
 
91
 
    def test_DoubleAddingMapWithSameName_ExceptRaise(self):
92
 
        self.assertRaises(IntegrityError, Map.objects.create, **{
93
 
            'name': 'Map',
94
 
            'slug': 'something-other',
95
 
            'author': 'Author',
96
 
            'w': 128,
97
 
            'h': 64,
98
 
            'nr_players': 4,
99
 
            'descr': 'a good map to play with',
100
 
            'minimap': '/wlmaps/minimaps/Map.png',
101
 
            'world_name': 'blackland',
102
 
            'uploader': self.user,
103
 
            'uploader_comment': 'Rockdamap'
104
 
        }
105
 
        )