Ejemplo n.º 1
0
def addCategory(request, title="title"):
    if not request.user.is_authenticated:
        raise PermissionDenied
    print("It got so far")
    cat = Category(title=title)
    cat.save()
    return HttpResponseRedirect('/index')
Ejemplo n.º 2
0
    def test_document_category(self):
        user = User(username='******', password='******')
        user.save()
        category = Category(name='Book', slug='book')
        category.save()
        document1 = Document(title='abcd',
                             slug='a',
                             user=user,
                             category=category,
                             content='abcd')
        document1.save()

        saved_document1 = Document.objects.first()

        self.assertEqual(saved_document1.category.name, 'Book')
Ejemplo n.º 3
0
    def test_saving_and_retrieving_category(self):
        category1 = Category(name='Book', slug='book')
        category1.save()
        category2 = Category(name='Movie', slug='movie')
        category2.save()

        saved_categories = Category.objects.all()
        self.assertEqual(saved_categories.count(), 2)

        saved_category1 = saved_categories[0]
        saved_category2 = saved_categories[1]
        self.assertEqual(saved_category1.name, 'Book')
        self.assertEqual(saved_category2.name, 'Movie')
        self.assertEqual(saved_category2.__str__(), 'Movie')