mirror of
https://github.com/DarrenOfficial/dpaste.git
synced 2024-12-19 00:09:21 +11:00
Moar tests.
This commit is contained in:
parent
6f563ee4ea
commit
1d8cff1dde
2 changed files with 81 additions and 1 deletions
|
@ -44,7 +44,7 @@ class SnippetAPITestCase(TestCase):
|
|||
self.assertEqual(response.status_code, 400)
|
||||
self.assertEqual(Snippet.objects.count(), 0)
|
||||
|
||||
def test_default_response(self):
|
||||
def test_default_format(self):
|
||||
"""
|
||||
A valid snippet, contains Unicode, tabs, spaces, linebreaks etc.
|
||||
"""
|
||||
|
@ -107,3 +107,21 @@ class SnippetAPITestCase(TestCase):
|
|||
self.assertEqual(json_data['content'], data['content'])
|
||||
self.assertEqual(json_data['lexer'], data['lexer'])
|
||||
self.assertTrue(json_data['url'].startswith('http'))
|
||||
|
||||
def test_invalid_format(self):
|
||||
"""
|
||||
A broken format will not raise an error, just use the default
|
||||
format.
|
||||
"""
|
||||
|
||||
data = {
|
||||
'content': u"Hello Wörld.\n\tGood Bye",
|
||||
'format': 'broken-format',
|
||||
'lexer': 'haskell'
|
||||
}
|
||||
|
||||
response = self.client.post(self.api_url, data)
|
||||
content = response.content.decode('utf-8')
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 1)
|
||||
|
|
|
@ -48,12 +48,27 @@ class SnippetTestCase(TestCase):
|
|||
self.assertEqual(Snippet.objects.count(), 0)
|
||||
|
||||
def test_new_snippet(self):
|
||||
# Simple GET
|
||||
response = self.client.get(self.new_url, follow=True)
|
||||
|
||||
# POST data
|
||||
data = self.valid_form_data()
|
||||
response = self.client.post(self.new_url, data, follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 1)
|
||||
self.assertContains(response, data['content'])
|
||||
|
||||
def test_new_spam_snippet(self):
|
||||
"""
|
||||
The form has a `title` field acting as a honeypot, if its filled,
|
||||
the snippet is considered as spam. We let the user know its spam.
|
||||
"""
|
||||
data = self.valid_form_data()
|
||||
data['title'] = u'Any content'
|
||||
response = self.client.post(self.new_url, data, follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 0)
|
||||
|
||||
def test_reply(self):
|
||||
data = self.valid_form_data()
|
||||
response = self.client.post(self.new_url, data, follow=True)
|
||||
|
@ -61,3 +76,50 @@ class SnippetTestCase(TestCase):
|
|||
self.assertContains(response, data['content'])
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 2)
|
||||
|
||||
def test_reply_invalid(self):
|
||||
data = self.valid_form_data()
|
||||
response = self.client.post(self.new_url, data, follow=True)
|
||||
del data['content']
|
||||
response = self.client.post(response.request['PATH_INFO'], data, follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 1)
|
||||
|
||||
def test_raw(self):
|
||||
data = self.valid_form_data()
|
||||
self.client.post(self.new_url, data, follow=True)
|
||||
response = self.client.get(reverse('snippet_details_raw', kwargs={
|
||||
'snippet_id': Snippet.objects.all()[0].secret_id}))
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertContains(response, data['content'])
|
||||
|
||||
def test_snippet_history(self):
|
||||
response = self.client.get(reverse('snippet_history'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 0)
|
||||
|
||||
data = self.valid_form_data()
|
||||
self.client.post(self.new_url, data, follow=True)
|
||||
response = self.client.get(reverse('snippet_history'))
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 1)
|
||||
|
||||
def test_snippet_history_delete_all(self):
|
||||
# Empty list, delete all raises no error
|
||||
response = self.client.get(reverse('snippet_history') + '?delete-all', follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 0)
|
||||
|
||||
# Create two sample pasts
|
||||
data = self.valid_form_data()
|
||||
self.client.post(self.new_url, data, follow=True)
|
||||
data = self.valid_form_data()
|
||||
self.client.post(self.new_url, data, follow=True)
|
||||
self.assertEqual(Snippet.objects.count(), 2)
|
||||
|
||||
# Delete all of them
|
||||
response = self.client.get(reverse('snippet_history') + '?delete-all', follow=True)
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(Snippet.objects.count(), 0)
|
||||
|
|
Loading…
Reference in a new issue