Advertisement
Guest User

Untitled

a guest
Feb 18th, 2015
254
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.01 KB | None | 0 0
  1. from django.utils import unittest
  2.  
  3. from postorius.forms import UserPreferences, DomainNew, ListNew, UserNew
  4.  
  5. class UserPreferencesTest(unittest.TestCase):
  6.  
  7.     def test_form_fields_valid(self):
  8.         form = UserPreferences({
  9.             'acknowledge_posts': 'True',
  10.             'hide_address': 'True',
  11.             'receive_list_copy': 'False',
  12.             'receive_own_postings': 'False',
  13.         })
  14.         self.assertTrue(form.is_valid())
  15.  
  16. class DomainNewTest(unittest.TestCase):
  17.  
  18.     def setUp(self):
  19.         self.form_data = {
  20.             'mail_host': 'mailman.most-desirable.org',
  21.             'web_host': 'http://mailman.most-desirable.org',
  22.             'description': 'The Most Desirable organization',
  23.             'contact_address': 'contact@mailman.most-desirable.org',
  24.         }
  25.  
  26.     def test_form_fields_webhost(self):
  27.         form = DomainNew(self.form_data)
  28.         self.assertTrue(form.is_valid())
  29.  
  30.     def test_form_fields_webhost_invalid(self):
  31.         self.form_data['web_host'] = 'mailman.most-desirable.org'
  32.         form = DomainNew(self.form_data)
  33.         self.assertFalse(form.is_valid())
  34.  
  35.     def test_form_fields_mailhost(self):
  36.         form = DomainNew(self.form_data)
  37.         self.assertTrue(form.is_valid())
  38.  
  39.     def test_form_fields_mailhost_invalid(self):
  40.         self.form_data['mail_host'] = 'mailman.most-desirable..org'
  41.         form = DomainNew(self.form_data)
  42.         self.assertFalse(form.is_valid())
  43.  
  44. class ListNewTest(unittest.TestCase):
  45.  
  46.     def setUp(self):
  47.         self.form_data = {
  48.             'listname' : 'test_list1',
  49.             'mail_host': 'mailman.most-desirable.org',
  50.             'list_owner': 'james@example.com',
  51.             'advertised': True,
  52.             'description': 'The Most Desirable organization',
  53.         }
  54.        
  55.     def test_form_fields_listname(self):
  56.         form = ListNew(self.form_data)
  57.         self.assertTrue(form.is_valid())    
  58.  
  59.     def test_form_fields_listname_invalid(self):
  60.         self.form_data['listname'] = 'test$list1'
  61.         form = ListNew(self.form_data)
  62.         self.assertFalse(form.is_valid())
  63.  
  64. class UserNewTest(unittest.TestCase):
  65.  
  66.     def setUp(self):
  67.         self.form_data = {
  68.             'display_name' : 'Pranjal Yadav',
  69.             'email' : 'pranjal@example.com',
  70.             'password' : 'password123',                  
  71.             'password_repeat' : 'password123',
  72.         }
  73.  
  74.     def test_form_fields_password(self):
  75.         form = UserNew(self.form_data)
  76.         self.assertTrue(form.is_valid())
  77.  
  78.     def test_form_fields_password_invalid(self):
  79.         self.form_data['password_repeat'] = 'random'
  80.         form = UserNew(self.form_data)
  81.         self.assertFalse(form.is_valid())
  82.  
  83.     def test_form_fields_email(self):
  84.         form = UserNew(self.form_data)
  85.         self.assertTrue(form.is_valid())
  86.  
  87.     def test_form_fields_email_invalid(self):
  88.         self.form_data['email'] = 'pranjal@example..com'
  89.         form = UserNew(self.form_data)
  90.         self.assertFalse(form.is_valid())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement