def test_creation(self):
        """blogs.tests.testapp.Article: creation works correctly"""
        article = Article(title='foo', body='bar')
        article.full_clean()
        self.assertEqual(article.title, 'foo')
        self.assertEqual(article.body, 'bar')

        article.save()
        article = Article.objects.get(pk=article.pk)
        self.assertEqual(article.title, 'foo')
        self.assertEqual(article.body, 'bar')
示例#2
0
 def test_worker_launched(self):
     """
     and check that the previous cache is served while reconstructing cache
     """
     url = "/"
     response = self.client.get(url)
     headers = dict(response.items())
     key = headers["ETag"]
     modified_model = Article(title="modified", body="modified")
     modified_model.save()
     response2 = self.client.get(url)
     headers2 = dict(response2.items())
     key2 = headers["ETag"]
     self.assertEqual(key, key2)
def populate_db(django_db_blocker):
    with django_db_blocker.unblock():
        a1 = Article(title='Plain Text',
                     text='A piece of plain text. The second sentence.')
        a1.save()
        a2 = Article(title='Rich Text',
                     text='<p>A piece of rich text with HTML tags. '
                     'The <strong>second sentence</strong>. '
                     'The <em>third sentence</em>.</p>')
        a2.save()
    def test_deletion(self):
        """blogs.tests.testapp.Article: deletion works correctly"""
        article = Article(title='foo', body='bar')
        article.full_clean()
        article.save()

        num = Article.objects.all().count()
        article.delete()
        self.assertEqual(Article.objects.all().count(), num - 1)
    def test_validation(self):
        """blogs.tests.testapp.Article: validation works correctly"""
        from django.core.exceptions import ValidationError
        article = Article(title='foo', body='bar')
        article.full_clean()
        article.save()

        article.title = ''
        self.assertRaises(ValidationError, article.full_clean)

        article.body = ''
        self.assertRaises(ValidationError, article.full_clean)

        article.title = '*' * 100
        self.assertRaises(ValidationError, article.full_clean)
示例#6
0
 def test_deserialize__functional_from_instance(self):
     instance = Article(title='foo')
     assert deserialize_model(serialize_model(instance)) == Article