class LegacyPassword(DRPTestCase): """Tests for a case where a legacy password is set but no new password has been entered.""" def setUp(self): """instantiate the labgroup.""" self.labGroup = LabGroup(title="LegacyPassTest1", address='1, war drobe, Narnia', email='*****@*****.**', legacy_access_code='old_magic') formData = { 'title': 'LegacyPasstest1', 'address': '1, war drobe', 'email': '*****@*****.**', 'users': [] } self.form = LabGroupForm(formData, instance=self.labGroup) self.labGroup.save() def test_validation(self): """Assert that the test worked.""" valid = self.form.is_valid() errString = '' for e, m in self.form.errors.items(): errString += '{0}: {1}\n'.format(e, m) self.assertTrue(valid, errString) def test_databaseChange(self): """Test that saving the form (changing the databases) makes the appropriate changes.""" self.form.save() self.labGroup = LabGroup.objects.get(pk=self.labGroup.id) self.assertEqual(self.labGroup.legacy_access_code, '') self.assertTrue(check_password('old_magic', self.labGroup.access_code)) def tearDown(self): """Get rid of the things created for this test.""" self.labGroup.delete()
class LegacyPassword2(DRPTestCase): """Test for a case where a legacy password is set and a new password has been entered.""" def setUp(self): """instantiate the labgroup.""" self.labGroup = LabGroup(title="LegacyPassTest2", address='2, war drobe, Narnia', email='*****@*****.**', legacy_access_code='old_magic') self.labGroup.save() formData = {'title': 'LegacyPasstest2', 'address': '2, war drobe', 'email': '*****@*****.**', 'accessCode': 'new_magic'} self.form = LabGroupForm(formData, instance=self.labGroup) def test_validation(self): """Evaluate whether the test should pass or fail.""" self.assertTrue(self.form.is_valid()) def test_databaseChange(self): """Evaluate that a new password is updated correctly from a legacy password.""" self.form.save() self.labGroup = LabGroup.objects.get(pk=self.labGroup.id) self.assertEqual(self.labGroup.legacy_access_code, '') self.assertTrue(check_password('new_magic', self.labGroup.access_code)) def tearDown(self): """Delete lab group created for this test.""" self.labGroup.delete()
class LegacyPassword2(DRPTestCase): """Test for a case where a legacy password is set and a new password has been entered.""" def setUp(self): """instantiate the labgroup.""" self.labGroup = LabGroup(title="LegacyPassTest2", address='2, war drobe, Narnia', email='*****@*****.**', legacy_access_code='old_magic') self.labGroup.save() formData = { 'title': 'LegacyPasstest2', 'address': '2, war drobe', 'email': '*****@*****.**', 'accessCode': 'new_magic' } self.form = LabGroupForm(formData, instance=self.labGroup) def test_validation(self): """Evaluate whether the test should pass or fail.""" self.assertTrue(self.form.is_valid()) def test_databaseChange(self): """Evaluate that a new password is updated correctly from a legacy password.""" self.form.save() self.labGroup = LabGroup.objects.get(pk=self.labGroup.id) self.assertEqual(self.labGroup.legacy_access_code, '') self.assertTrue(check_password('new_magic', self.labGroup.access_code)) def tearDown(self): """Delete lab group created for this test.""" self.labGroup.delete()
class LegacyPassword(DRPTestCase): """Tests for a case where a legacy password is set but no new password has been entered.""" def setUp(self): """instantiate the labgroup.""" self.labGroup = LabGroup(title="LegacyPassTest1", address='1, war drobe, Narnia', email='*****@*****.**', legacy_access_code='old_magic') formData = {'title': 'LegacyPasstest1', 'address': '1, war drobe', 'email': '*****@*****.**', 'users': []} self.form = LabGroupForm(formData, instance=self.labGroup) self.labGroup.save() def test_validation(self): """Assert that the test worked.""" valid = self.form.is_valid() errString = '' for e, m in self.form.errors.items(): errString += '{0}: {1}\n'.format(e, m) self.assertTrue(valid, errString) def test_databaseChange(self): """Test that saving the form (changing the databases) makes the appropriate changes.""" self.form.save() self.labGroup = LabGroup.objects.get(pk=self.labGroup.id) self.assertEqual(self.labGroup.legacy_access_code, '') self.assertTrue(check_password('old_magic', self.labGroup.access_code)) def tearDown(self): """Get rid of the things created for this test.""" self.labGroup.delete()
def test_duplicateTitle(self): """Ensure that a duplicate lab group title is accepted.""" form = LabGroupForm({ 'title': 'DuplicateValues', 'address': '2, war drobe, Narnia', 'email': '*****@*****.**', 'accessCode': 'old_magic' }) self.assertFalse(form.is_valid())
def setUp(self): """instantiate the labgroup.""" self.labGroup = LabGroup(title="LegacyPassTest1", address='1, war drobe, Narnia', email='*****@*****.**', legacy_access_code='old_magic') formData = { 'title': 'LegacyPasstest1', 'address': '1, war drobe', 'email': '*****@*****.**', 'users': [] } self.form = LabGroupForm(formData, instance=self.labGroup) self.labGroup.save()
def setUp(self): """instantiate the labgroup.""" self.labGroup = LabGroup(title="LegacyPassTest2", address='2, war drobe, Narnia', email='*****@*****.**', legacy_access_code='old_magic') self.labGroup.save() formData = { 'title': 'LegacyPasstest2', 'address': '2, war drobe', 'email': '*****@*****.**', 'accessCode': 'new_magic' } self.form = LabGroupForm(formData, instance=self.labGroup)
def setUp(self): """instantiate the labgroup.""" self.labGroup = LabGroup(title="LegacyPassTest1", address='1, war drobe, Narnia', email='*****@*****.**', legacy_access_code='old_magic') formData = {'title': 'LegacyPasstest1', 'address': '1, war drobe', 'email': '*****@*****.**', 'users': []} self.form = LabGroupForm(formData, instance=self.labGroup) self.labGroup.save()
def setUp(self): """instantiate the labgroup.""" self.labGroup = LabGroup(title="LegacyPassTest2", address='2, war drobe, Narnia', email='*****@*****.**', legacy_access_code='old_magic') self.labGroup.save() formData = {'title': 'LegacyPasstest2', 'address': '2, war drobe', 'email': '*****@*****.**', 'accessCode': 'new_magic'} self.form = LabGroupForm(formData, instance=self.labGroup)
def test_missingAddress(self): formData = copy(self.formData) del formData['address'] form = LabGroupForm(formData) self.assertFalse(form.is_valid())
def test_missingEmail(self): formData = copy(self.formData) del formData['email'] form = LabGroupForm(formData) self.assertFalse(form.is_valid())
def test_missingPass(self): formData = copy(self.formData) del formData['accessCode'] form = LabGroupForm(formData) self.assertFalse(form.is_valid())
def completeDataAndUsers(self): """Test to determine whether a LabGroupForm is correctly marked as valid when it has all required information and a list of user ids.""" formData = copy(self.formData) formData['users'] = [u.id for u in self.users] form = LabGroupForm() self.assertTrue(form.is_valid())
def completeData(self): """Test to determine whether a form is correctly marked as valid when it has all required information.""" form = LabGroupForm(self.formData) self.assertTrue(form.is_valid())
def test_missingPass(self): """Test to determine whether a form is correctly marked as invalid when a password is not present.""" formData = copy(self.formData) del formData['accessCode'] form = LabGroupForm(formData) self.assertFalse(form.is_valid())
def test_missingTitle(self): """Test to determine whether a form is correctly marked as invalid when a title is not present.""" formData = copy(self.formData) del formData['title'] form = LabGroupForm(formData) self.assertFalse(form.is_valid())
def completeDataAndUsers(self): formData = copy(self.formData) formData['users'] = [u.id for u in self.users] form = LabGroupForm() self.assertTrue(form.is_valid())
def test_missingEmail(self): """Test to determine whether a form is correctly marked as invalid when an email address is not present.""" formData = copy(self.formData) del formData['email'] form = LabGroupForm(formData) self.assertFalse(form.is_valid())
def test_duplicateTitle(self): """Ensure that a duplicate lab group title is accepted.""" form = LabGroupForm({'title': 'DuplicateValues', 'address': '2, war drobe, Narnia', 'email': '*****@*****.**', 'accessCode': 'old_magic'}) self.assertFalse(form.is_valid())
def test_missingTitle(self): formData = copy(self.formData) del formData['title'] form = LabGroupForm(formData) self.assertFalse(form.is_valid())
def completeData(self): form = LabGroupForm(self.formData) self.assertTrue(form.is_valid())