Exemplo n.º 1
0
 def test_url(self):
     """items return their url correctly"""
     i = Item()
     i.slug = "1"
     i.title = "1"
     i.description = "1"
     i.save()
     self.assertTrue(len(i.get_absolute_url()) > 0)
Exemplo n.º 2
0
 def test_url(self):
     """items return their url correctly"""
     i = Item()
     i.slug = '1'
     i.title = '1'
     i.description = '1'
     i.save()
     self.assertEqual('/gallery/1.html', i.get_absolute_url())
Exemplo n.º 3
0
 def test_created(self):
     """items have a created date added when they're created"""
     i = Item()
     i.slug = "1"
     i.title = "1"
     i.description = "1"
     i.save()
     self.assertTrue(i.created)
Exemplo n.º 4
0
 def test_item_200(self):
     """item responds with a 200 OK"""
     i1 = Item()
     i1.slug = '1'
     i1.title = '1'
     i1.description = '1'
     i1.save()
     request = self.rf.get(reverse('ccgallery:item', args=[i1.slug]))
     response  = item(request, i1.slug)
     # is 200
     self.assertEqual(200, response.status_code)
Exemplo n.º 5
0
 def test_category_200(self):
     """category responds with a 200 OK"""
     c1 = Category()
     c1.slug = '1'
     c1.title = '1'
     c1.description = '1'
     c1.status = Category.VISIBLE
     c1.save()
     i1 = Item()
     i1.slug = '1'
     i1.title = '1'
     i1.description = '1'
     i1.save()
     i1.categories.add(c1)
     request = self.rf.get(
             reverse('ccgallery:category', args=[c1.slug]))
     response = category(request, c1.slug)
     # is 200
     self.assertEqual(200, response.status_code)
 def test_get_item_one_category(self, get_template, Context):
     """get items with one category works as expected"""
     # make category
     c1 = Category()
     c1.slug = "1"
     c1.title = "1"
     c1.description = "1"
     c1.status = Category.VISIBLE
     c1.save()
     # make two items
     i1 = Item()
     i1.status = Item.VISIBLE
     i1.name = "1"
     i1.slug = "1"
     i1.title = "1"
     i1.description = "1"
     i1.save()
     i1.categories.add(c1)
     i2 = Item()
     i2.status = Item.HIDDEN
     i2.name = "2"
     i2.slug = "2"
     i2.title = "2"
     i2.description = "2"
     i2.order = Decimal("2.00")
     i2.save()
     i2.categories.add(c1)
     # get the node
     node = ccgallery_tags.ItemNode("items", c1.pk)
     # now build the context
     context = ContextMock({})
     # now we can render
     node.render(context)
     self.assertEqual(1, context["items"].count())
     # make i2 visible and the count changes
     i2.status = Item.VISIBLE
     i2.save()
     # get the node
     node = ccgallery_tags.ItemNode("items", c1.pk)
     # now build the context
     context = ContextMock({})
     # now we can render
     node.render(context)
     self.assertEqual(2, context["items"].count())
 def test_get_item_no_category(self, get_template, Context):
     """get items with no category works as expected"""
     # make two items
     i1 = Item()
     i1.status = Item.VISIBLE
     i1.name = "1"
     i1.slug = "1"
     i1.title = "1"
     i1.description = "1"
     i1.save()
     i2 = Item()
     i2.status = Item.HIDDEN
     i2.name = "2"
     i2.slug = "2"
     i2.title = "2"
     i2.description = "2"
     i2.order = Decimal("2.00")
     i2.save()
     # get the node
     node = ccgallery_tags.ItemNode("items")
     # now build the context
     context = ContextMock({})
     # now we can render
     node.render(context)
     self.assertEqual(1, context["items"].count())
 def test_get_item_category_comma(self, get_template, Context):
     """get items with comma seperated categories work as expected"""
     # make category
     c1 = Category()
     c1.slug = "1"
     c1.title = "1"
     c1.description = "1"
     c1.status = Category.VISIBLE
     c1.save()
     c2 = Category()
     c2.slug = "1"
     c2.title = "1"
     c2.description = "1"
     c2.status = Category.VISIBLE
     c2.save()
     # make two items
     i1 = Item()
     i1.status = Item.VISIBLE
     i1.name = "1"
     i1.slug = "1"
     i1.title = "1"
     i1.description = "1"
     i1.save()
     i1.categories.add(c1)
     i2 = Item()
     i2.status = Item.HIDDEN
     i2.name = "2"
     i2.slug = "2"
     i2.title = "2"
     i2.description = "2"
     i2.order = Decimal("2.00")
     i2.save()
     i2.categories.add(c1)
     # get the node
     node = ccgallery_tags.ItemNode("items", "%s,%s" % (c1.pk, c2.pk))
     # now build the context
     context = ContextMock({})
     # now we can render
     node.render(context)
     self.assertEqual(1, context["items"].count())
Exemplo n.º 9
0
 def test_ordering(self):
     """items are ordered by their order"""
     i1 = Item()
     i1.slug = "1"
     i1.title = "1"
     i1.description = "1"
     i1.save()
     i2 = Item()
     i2.slug = "2"
     i2.title = "2"
     i2.description = "2"
     i2.order = Decimal("2.00")
     i2.save()
     i3 = Item()
     i3.slug = "3"
     i3.title = "3"
     i3.description = "3"
     i3.order = Decimal("1.00")
     i3.save()
     # 3 is first, 2 second and 1 third
     self.assertEqual("3", Item.objects.all()[0].slug)
     self.assertEqual("2", Item.objects.all()[1].slug)
     self.assertEqual("1", Item.objects.all()[2].slug)
Exemplo n.º 10
0
 def test_category_images(self):
     """ A category will return the first image from the first 
     available item in it's set"""
     # the images
     red = open("%s/ccgallery/red.jpg" % settings.STATIC_ROOT)
     blue = open("%s/ccgallery/blue.jpg" % settings.STATIC_ROOT)
     # make items
     i1 = Item()
     i1.status = Item.VISIBLE
     i1.name = "1"
     i1.slug = "1"
     i1.title = "1"
     i1.description = "1"
     i1.save()
     i2 = Item()
     i2.status = Item.VISIBLE
     i2.name = "2"
     i2.slug = "2"
     i2.title = "2"
     i2.description = "2"
     i2.order = Decimal("2.00")
     i2.save()
     # make the images
     ii1 = ItemImage()
     ii1.item = i1
     ii1.src = File(red, "ccgallery/red.jpg")
     ii1.order = Decimal("10.00")
     ii1.save()
     ii2 = ItemImage()
     ii2.item = i2
     ii2.src = File(blue, "ccgallery/blue.jpg")
     ii2.save()
     # make category
     c1 = Category()
     c1.slug = "1"
     c1.title = "1"
     c1.description = "1"
     c1.status = Category.VISIBLE
     c1.save()
     # add images to the categories
     i1.categories.add(c1)
     i2.categories.add(c1)
     # close the images
     red.close()
     blue.close()
     # now the category image is ii2
     self.assertEqual(c1.image.pk, ii2.pk)
     # make i2 hidden
     i2.status = Item.HIDDEN
     i2.save()
     # now the category image is ii1
     self.assertEqual(c1.image.pk, ii1.pk)
     # make i1 hidden and now it's none
     i1.status = Item.HIDDEN
     i1.save()
     # now the category image is ii1
     self.assertEqual(c1.image, None)
Exemplo n.º 11
0
 def test_item_visible(self):
     """only visible items are returned"""
     i1 = Item()
     i1.slug = '1'
     i1.title = '1'
     i1.description = '1'
     i1.status = Item.VISIBLE
     i1.save()
     i2 = Item()
     i2.slug = '2'
     i2.title = '2'
     i2.description = '2'
     i2.order = Decimal('2.00')
     i2.status = Item.VISIBLE
     i2.save()
     # visible returns 1
     self.assertEqual(2, Item.objects.visible().count())
     # hidden returns 1
     i2.status = Item.HIDDEN
     i2.save()
     self.assertEqual(1, Item.objects.visible().count())
Exemplo n.º 12
0
 def test_item_for_category(self):
     """the for item manager method"""
     c1 = Category()
     c1.slug = '1'
     c1.title = '1'
     c1.description = '1'
     c1.status = Category.VISIBLE
     c1.save()
     # make the items
     i1 = Item()
     i1.slug = '1'
     i1.title = '1'
     i1.description = '1'
     i1.status = Item.VISIBLE
     i1.save()
     i1.categories.add(c1)
     i2 = Item()
     i2.slug = '2'
     i2.title = '2'
     i2.description = '2'
     i2.order = Decimal('2.00')
     i2.status = Item.VISIBLE
     i2.save()
     i2.categories.add(c1)
     # visible returns 1
     self.assertEqual(2, Item.objects.for_category(c1).count())
     # hidden returns 1
     i2.status = Item.HIDDEN
     i2.save()
     self.assertEqual(1, Item.objects.for_category(c1).count())
     # make the category invisible
     c1.status = Category.HIDDEN
     c1.save()
     self.assertEqual(0, Item.objects.for_category(c1).count())
Exemplo n.º 13
0
 def test_ordering(self):
     """items are ordered by their order"""
     i1 = Item()
     i1.slug = '1'
     i1.title = '1'
     i1.description = '1'
     i1.save()
     i2 = Item()
     i2.slug = '2'
     i2.title = '2'
     i2.description = '2'
     i2.order = Decimal('2.00')
     i2.save()
     i3 = Item()
     i3.slug = '3'
     i3.title = '3'
     i3.description = '3'
     i3.order = Decimal('1.00')
     i3.save()
     # 3 is first, 2 second and 1 third
     self.assertEqual('3', Item.objects.all()[0].slug)
     self.assertEqual('2', Item.objects.all()[1].slug)
     self.assertEqual('1', Item.objects.all()[2].slug)