From 09b5be250dee0294da7605d5bd4c0669348d92ca Mon Sep 17 00:00:00 2001 From: Isaac Bythewood Date: Thu, 10 May 2012 03:04:40 +0000 Subject: [PATCH] Added some more basic tests, for pins this time. --- pinry/pins/tests.py | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 pinry/pins/tests.py diff --git a/pinry/pins/tests.py b/pinry/pins/tests.py new file mode 100644 index 0000000..b4151eb --- /dev/null +++ b/pinry/pins/tests.py @@ -0,0 +1,61 @@ +from django.test import TestCase +from django.test.client import Client +from django.core.urlresolvers import reverse + +from .forms import PinForm + + +class RecentPinsTest(TestCase): + def setUp(self): + self.client = Client() + self.url = reverse('pins:recent-pins') + + def test_url(self): + self.assertEqual(self.url, '/pins/') + + def test_status_code(self): + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + + +class NewPinTest(TestCase): + def setUp(self): + self.client = Client() + self.url = reverse('pins:new-pin') + + def test_url(self): + self.assertEqual(self.url, '/pins/new-pin/') + + def test_status_code(self): + response = self.client.get(self.url) + self.assertEqual(response.status_code, 200) + + def test_new_pin(self): + response = self.client.post(self.url, { + 'url': 'https://github.com/overshard/pinry/raw/master/screenshot.png', + }) + self.assertEqual(response.status_code, 302) + + def test_new_pin_fail(self): + # Invalid protocol + response = self.client.post(self.url, { + 'url': 'ftp://github.com/overshard/pinry/raw/master/screenshot.png', + }) + self.assertEqual(response.status_code, 200) + #self.assertFormError(response, PinForm(), 'url', + # 'Currently only support HTTP and HTTPS protocols, please be sure you include this in the URL.') + + # Invalid file type. + response = self.client.post(self.url, { + 'url': 'https://raw.github.com/overshard/pinry/master/README.md', + }) + self.assertEqual(response.status_code, 200) + + # Already Pinned + response = self.client.post(self.url, { + 'url': 'https://github.com/overshard/pinry/raw/master/screenshot.png', + }) + response = self.client.post(self.url, { + 'url': 'https://github.com/overshard/pinry/raw/master/screenshot.png', + }) + self.assertEqual(response.status_code, 200)