~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: 2016-08-08 10:06:42 UTC
  • mto: This revision was merged to the branch mainline in revision 419.
  • Revision ID: sirver@gmx.de-20160808100642-z62vwqitxoyl5fh4
Added the apt-get update script I run every 30 days.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#############
14
14
# TestCases #
15
15
#############
16
 
 
17
 
 
18
16
class TestWLMapsModels_Map(DjangoTest):
19
17
    urls = 'wlmaps.test_urls'
20
 
 
 
18
    
21
19
    def setUp(self):
22
 
        self.user = User.objects.create(username='testuser')
 
20
        self.user = User.objects.create(username="testuser")
23
21
        self.user.save()
24
 
 
 
22
        
25
23
        # Add maps
26
24
        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',
 
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",
35
33
 
36
 
            uploader=self.user,
37
 
            uploader_comment='Rockdamap'
 
34
                        uploader = self.user,
 
35
                        uploader_comment = "Rockdamap"
38
36
        )
39
37
        nm.save()
40
38
        self.map = nm
41
39
        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',
 
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",
50
48
 
51
 
            uploader=self.user,
52
 
            uploader_comment='Rockdamap'
 
49
                        uploader = self.user,
 
50
                        uploader_comment = "Rockdamap"
53
51
        )
54
52
        nm.save()
55
53
        self.map1 = nm
56
 
 
 
54
    
57
55
    def test_validMapInsertion_expectCorrectResult(self):
58
56
        # This really tests the setUp functionality. let's
59
57
        # hope that this worked out
60
 
        self.assertEqual(Map.objects.get(pk=1), self.map)
 
58
        self.assertEqual( Map.objects.get(pk=1), self.map)
61
59
 
62
60
    def test_MapNameGeneration_expectCorrectResult(self):
63
 
        self.assertEqual(repr(self.map), '<Map: Map by Author>')
 
61
        self.assertEqual( repr(self.map), "<Map: Map by Author>")
64
62
 
65
63
    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
 
 
 
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
    
70
67
    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)
 
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) 
75
72
 
76
73
    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'
 
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"
88
85
        }
89
86
        )
90
87
 
91
88
    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'
 
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"
104
101
        }
105
102
        )
 
103
 
 
104
    
 
105
 
 
106