def test_change_group(self): """Check that when changing an institutes group, old accounts are removed from the institute and new ones are added. """ account1 = simple_account(machine_category=self.machine_category) group1 = GroupFactory() institute = InstituteFactory(group=group1) # Test setting up initial group for institute self.resetDatastore() group1.save() group1.add_person(account1.person) self.assertEqual(self.datastore.method_calls, [ mock.call.save_group(group1), mock.call.add_account_to_group(account1, group1) ]) # Test during initial creation of the institute self.resetDatastore() institute_quota = InstituteQuota.objects.create( machine_category=self.machine_category, institute=institute, quota=100) self.assertEqual(self.datastore.method_calls, [ mock.call.save_institute(institute), mock.call.add_account_to_institute(account1, institute) ]) # Test changing an existing institutions group account2 = simple_account(institute=institute, machine_category=self.machine_category) self.resetDatastore() group2 = GroupFactory() group2.add_person(account2.person) institute.group = group2 institute.save() self.assertEqual( self.datastore.method_calls, [ mock.call.save_group(group2), mock.call.add_account_to_group(account2, group2), mock.call.save_institute(institute), # old accounts are removed mock.call.remove_account_from_institute(account1, institute), # new accounts are added mock.call.add_account_to_institute(account2, institute) ]) # Test deleting project quota self.resetDatastore() institute_quota.delete() self.assertEqual(self.datastore.method_calls, [ mock.call.remove_account_from_institute(account2, institute), mock.call.delete_institute(institute) ])
def test_change_group(self): """Check that when changing an institutes group, old accounts are removed from the institute and new ones are added. """ account1 = simple_account(machine_category=self.machine_category) group1 = GroupFactory() institute = InstituteFactory(group=group1) # Test setting up initial group for institute self.resetDatastore() group1.save() group1.add_person(account1.person) self.assertEqual( self.datastore.method_calls, [mock.call.save_group(group1), mock.call.add_account_to_group(account1, group1)]) # Test during initial creation of the institute self.resetDatastore() institute_quota = InstituteQuota.objects.create( machine_category=self.machine_category, institute=institute, quota=100) self.assertEqual( self.datastore.method_calls, [mock.call.save_institute(institute), mock.call.add_account_to_institute(account1, institute)]) # Test changing an existing institutions group account2 = simple_account(institute=institute, machine_category=self.machine_category) self.resetDatastore() group2 = GroupFactory() group2.add_person(account2.person) institute.group = group2 institute.save() self.assertEqual( self.datastore.method_calls, [mock.call.save_group(group2), mock.call.add_account_to_group(account2, group2), mock.call.save_institute(institute), # old accounts are removed mock.call.remove_account_from_institute(account1, institute), # new accounts are added mock.call.add_account_to_institute(account2, institute)]) # Test deleting project quota self.resetDatastore() institute_quota.delete() self.assertEqual( self.datastore.method_calls, [mock.call.remove_account_from_institute(account2, institute), mock.call.delete_institute(institute)])
def test_username(self): assert_raises = self.assertRaises(django_exceptions.ValidationError) # Max length institution = InstituteFactory(name="a" * 255) institution.full_clean() # Name is too long institution = InstituteFactory(name="a" * 256) with assert_raises: institution.full_clean()
def test_add_existing_name(self): group, _ = Group.objects.get_or_create(name='testinstitute27') institute = InstituteFactory( name='Test Institute 27', group=group) self.assertEqual( institute.group.name, 'testinstitute27') self.assertEqual( institute.group.name, institute.name.lower().replace(' ', ''))
def test_minimum_create(self): institute = InstituteFactory() person = Person.objects.create(username='******', password='******', short_name='RK', full_name='Rick Spicy McHaggis', email='*****@*****.**', institute=institute) person.full_clean() self.assertFalse(person.is_admin) self.assertFalse(person.is_systemuser) self.assertEqual(str(person), 'Rick Spicy McHaggis') self.assertEqual(person.short_name, 'RK') self.assertEqual(person.email, '*****@*****.**') self.assertEqual(person.first_name, 'Rick Spicy') self.assertEqual(person.last_name, 'McHaggis')
def test_change_group(self): """Check that when changing an projects group, old accounts are removed from the project and new ones are added. """ account1 = simple_account(machine_category=self.machine_category) group1 = GroupFactory() group1.add_person(account1.person) institute = InstituteFactory() # Test during initial creation of the project self.resetDatastore() project = Project.objects.create(group=group1, institute=institute) project_quota = ProjectQuota.objects.create( machine_category=self.machine_category, project=project) self.assertEqual(self.datastore.method_calls, [ mock.call.save_project(project), mock.call.add_account_to_project(account1, project) ]) # Test changing an existing projects group account2 = simple_account(machine_category=self.machine_category) self.resetDatastore() group2 = GroupFactory() group2.add_person(account2.person) project.group = group2 project.save() self.assertEqual( self.datastore.method_calls, [ mock.call.save_group(group2), mock.call.add_account_to_group(account2, group2), mock.call.save_project(project), # old accounts are removed mock.call.remove_account_from_project(account1, project), # new accounts are added mock.call.add_account_to_project(account2, project) ]) # Test deleting project quota self.resetDatastore() project_quota.delete() self.assertEqual(self.datastore.method_calls, [ mock.call.remove_account_from_project(account2, project), mock.call.delete_project(project) ])
def test_minimum_create(self): institute = InstituteFactory() project = Project.objects.create(pid='test', name='Test', institute=institute) project.full_clean() self.assertEqual(project.name, 'Test') self.assertEqual(project.pid, 'test') self.assertEqual(project.institute, institute) self.assertEqual(project.group.name, 'test') self.assertFalse(project.is_approved) self.assertEqual(project.leaders.count(), 0) self.assertTrue(project.description is None) self.assertTrue(project.deleted_by is None) self.assertTrue(project.date_deleted is None) self.assertTrue(project.approved_by is None) self.assertTrue(project.date_approved is None) self.assertTrue(project.last_usage is None) self.assertTrue(project.additional_req is None)
def test_add(self): InstituteFactory(name='TestInstitute54')