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())
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)
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_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_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())
def test_category_hidden(self): """only hidden categorys are returned""" i1 = Category() i1.slug = '1' i1.title = '1' i1.description = '1' i1.status = Category.VISIBLE i1.save() i2 = Category() i2.slug = '2' i2.title = '2' i2.description = '2' i2.order = Decimal('2.00') i2.status = Category.VISIBLE i2.save() # visible returns 1 self.assertEqual(0, Category.objects.hidden().count()) # hidden returns 1 i2.status = Category.HIDDEN i2.save() self.assertEqual(1, Category.objects.hidden().count())