~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to wlmaps/tests/test_models.py

  • Committer: Holger Rapp
  • Date: 2009-02-25 16:55:36 UTC
  • Revision ID: sirver@kallisto.local-20090225165536-3abfhjx8qsgtzyru
- Added my hacked version of pybb. Remerging new versions is very difficult at this point :(

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