コード例 #1
0
 def test_strap_image_ordering(self):
     """Strap imags should be ordered by their order attribute"""
     s = Strap()
     s.name = 'test'
     s.save()
     # now create the strap image
     r = open('%s/ccstraps/red.png' % settings.STATIC_ROOT)
     s1  = StrapImage()
     s1.src = File(r, 'ccstraps/red.png')
     s1.order = Decimal('10.00')
     s1.strap = s
     s1.save()
     # Another
     p = open('%s/ccstraps/purple.png' % settings.STATIC_ROOT)
     s2  = StrapImage()
     s2.src = File(r, 'ccstraps/purple.png')
     s2.order = Decimal('1.00')
     s2.strap = s
     s2.save()
     # close the images
     r.close()
     p.close()
     # now the order of the straps is s2, s1
     self.assertEqual(s.strapimage_set.all()[0].pk, s2.pk)
     self.assertEqual(s.strapimage_set.all()[1].pk, s1.pk)
     # change the order around
     s1.order = Decimal('2')
     s1.save()
     s2.order = Decimal('3')
     s2.save()
     # now the order has change
     self.assertEqual(s.strapimage_set.all()[0].pk, s1.pk)
     self.assertEqual(s.strapimage_set.all()[1].pk, s2.pk)
コード例 #2
0
 def test_get_strap_expected(self, get_template, Context):
     # make the straps
     s = Strap()
     s.name = 'test'
     s.save()
     # now create the strap image
     r = open('%s/ccstraps/red.png' % settings.STATIC_ROOT)
     s1  = StrapImage()
     s1.src = File(r, 'ccstraps/red.png')
     s1.order = Decimal('10.00')
     s1.strap = s
     s1.save()
     # Another
     p = open('%s/ccstraps/purple.png' % settings.STATIC_ROOT)
     s2  = StrapImage()
     s2.src = File(r, 'ccstraps/purple.png')
     s2.order = Decimal('1.00')
     s2.strap = s
     s2.save()
     # close the images
     r.close()
     p.close()
     # get the node
     node = ccstrap_tags.StrapNode('test', 'strap')
     # now build the context
     context = ContextMock({})
     # now we can render
     node.render(context)
     self.assertEqual('test', context['strap'].name)