1
+ from __future__ import unicode_literals
2
+
1
3
import datetime
2
4
import os
3
5
4
6
from django import get_version
5
- from django .utils import unittest
6
- from django .test import SimpleTestCase
7
- from django .test .utils import override_settings
8
7
from django .db import models
9
8
from django .template import Template , Context
9
+ from django .test import SimpleTestCase
10
+ from django .test .utils import override_settings
11
+ from django .utils import unittest
12
+ from django .utils .encoding import python_2_unicode_compatible
13
+ from django .utils .six .moves import range
10
14
11
15
from .models import (
12
16
SingleBrick ,
18
22
BaseWallFactory ,
19
23
wall_factory ,
20
24
)
21
- from .exceptions import TemplateNameNotFound
25
+ from djangobricks .exceptions import TemplateNameNotFound
22
26
23
27
CURRENT_DIR = os .path .abspath (os .path .dirname (__file__ ))
24
28
@@ -51,40 +55,43 @@ class NotABrick(object): pass
51
55
class TestBrickWall (BaseWall ): pass
52
56
53
57
58
+ @python_2_unicode_compatible
54
59
class TestModelA (models .Model ):
55
60
name = models .CharField (max_length = 8 )
56
61
popularity = models .PositiveIntegerField ()
57
62
pub_date = models .DateTimeField ()
58
63
is_sticky = models .BooleanField (default = False )
59
64
60
- def __unicode__ (self ):
61
- return unicode ( self .name )
65
+ def __str__ (self ):
66
+ return self .name
62
67
63
68
def callable_popularity (self ):
64
69
return self .popularity
65
70
66
71
72
+ @python_2_unicode_compatible
67
73
class TestModelB (models .Model ):
68
74
name = models .CharField (max_length = 8 )
69
75
date_add = models .DateTimeField ()
70
76
popularity = models .PositiveIntegerField ()
71
77
is_sticky = models .BooleanField (default = False )
72
78
73
- def __unicode__ (self ):
74
- return unicode ( self .name )
79
+ def __str__ (self ):
80
+ return self .name
75
81
76
82
def pub_date (self ):
77
83
return self .date_add
78
84
79
85
86
+ @python_2_unicode_compatible
80
87
class TestModelC (models .Model ):
81
88
name = models .CharField (max_length = 8 )
82
89
pub_date = models .DateTimeField ()
83
90
popularity = models .PositiveIntegerField ()
84
91
is_sticky = models .BooleanField (default = False )
85
92
86
- def __unicode__ (self ):
87
- return unicode ( self .name )
93
+ def __str__ (self ):
94
+ return self .name
88
95
89
96
90
97
class TestWallFactory (BaseWallFactory ):
@@ -131,7 +138,7 @@ def _create_model_a_objects_and_bricks(self):
131
138
pub_date = datetime .datetime (2012 , 1 , 1 , 12 , 0 ), is_sticky = True )
132
139
objectA4 = TestModelA .objects .create (name = 'objectA4' , popularity = 2 ,
133
140
pub_date = datetime .datetime (2013 , 1 , 1 , 12 , 0 ), is_sticky = False )
134
-
141
+
135
142
self .brickA1 = SingleBrick (objectA1 )
136
143
self .brickA2 = SingleBrick (objectA2 )
137
144
self .brickA3 = SingleBrick (objectA3 )
@@ -148,7 +155,7 @@ def _create_model_b_objects_and_bricks(self):
148
155
date_add = datetime .datetime (2008 , 1 , 1 , 12 , 0 ), is_sticky = True )
149
156
objectB4 = TestModelB .objects .create (name = 'objectB4' , popularity = 7 ,
150
157
date_add = datetime .datetime (2009 , 1 , 1 , 12 , 0 ), is_sticky = False )
151
-
158
+
152
159
self .brickB1 = SingleBrick (objectB1 )
153
160
self .brickB2 = SingleBrick (objectB2 )
154
161
self .brickB3 = SingleBrick (objectB3 )
@@ -165,7 +172,7 @@ def _create_model_c_objects_and_bricks(self):
165
172
pub_date = datetime .datetime (2004 , 1 , 1 , 12 , 0 ), is_sticky = True )
166
173
objectC4 = TestModelC .objects .create (name = 'objectC4' , popularity = 17 ,
167
174
pub_date = datetime .datetime (2005 , 1 , 1 , 12 , 0 ), is_sticky = False )
168
-
175
+
169
176
self .brickC1 = ListBrick ([objectC1 , objectC2 ])
170
177
self .brickC2 = ListBrick ([objectC3 , objectC4 ])
171
178
for i in range (1 , 3 ):
@@ -203,7 +210,7 @@ def test_single_brick_init(self):
203
210
pub_date = datetime .datetime (2012 , 1 , 1 , 12 , 0 ), is_sticky = True )
204
211
objectA4 = TestModelA .objects .create (name = 'objectA4' , popularity = 2 ,
205
212
pub_date = datetime .datetime (2013 , 1 , 1 , 12 , 0 ), is_sticky = False )
206
-
213
+
207
214
bricks = SingleBrick .get_bricks_for_queryset (TestModelA .objects .all ())
208
215
wall = TestBrickWall (bricks )
209
216
self .assertEqual (wall [0 ].item , objectA1 )
@@ -220,7 +227,7 @@ def test_list_brick_init(self):
220
227
pub_date = datetime .datetime (2012 , 1 , 1 , 12 , 0 ), is_sticky = True )
221
228
objectA4 = TestModelA .objects .create (name = 'objectA4' , popularity = 2 ,
222
229
pub_date = datetime .datetime (2013 , 1 , 1 , 12 , 0 ), is_sticky = False )
223
-
230
+
224
231
bricks = ListBrick .get_bricks_for_queryset (TestModelA .objects .all ())
225
232
wall = TestBrickWall (bricks )
226
233
self .assertEqual (wall [0 ].items , [objectA1 , objectA2 , objectA3 , objectA4 ])
@@ -558,11 +565,11 @@ def test_list_brick_context(self):
558
565
def test_list_brick_chunk (self ):
559
566
now = datetime .datetime .now ()
560
567
objects = []
561
- for i in xrange (12 ):
568
+ for i in range (12 ):
562
569
obj = TestModelC .objects .create (name = i , popularity = i , pub_date = now )
563
570
objects .append (obj )
564
571
bricks = TestListBrick .get_bricks_for_queryset (TestModelC .objects .all ())
565
- for i in xrange (3 ):
572
+ for i in range (3 ):
566
573
start = i * TestListBrick .chunk_size
567
574
stop = start + TestListBrick .chunk_size
568
575
self .assertEqual (bricks [i ].items , objects [start :stop ])
@@ -748,4 +755,4 @@ def test_factory_method_multiple_queryset(self):
748
755
expected = [self .brickB1 .item , self .brickB2 .item , self .brickB4 .item ,
749
756
self .brickA1 .item , self .brickA2 .item , self .brickA4 .item ,
750
757
self .brickB3 .item , self .brickA3 .item ]
751
- self .assertEqual ([b .item for b in wall ], expected )
758
+ self .assertEqual ([b .item for b in wall ], expected )
0 commit comments