def test_self(self): """Authenticated users shouldn't be able to create countries.""" TestUsers.new_user(username="******", password="******") self.client.login(username="******", password="******") response = self.get_response(self.params) self.assertMethodNotAllowed(response, "POST")
def test_superuser(self): '''Superusers shouldn't be able to update committees.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.committee.id, params=self.params) self.assertMethodNotAllowed(response, 'PATCH')
def test_self(self): '''Authenticated users shouldn't have permission to delete committees.''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.committee.id) self.assertMethodNotAllowed(response, 'DELETE')
def test_self(self): '''Authenticated users shouldn't be able to create countries.''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.params) self.assertMethodNotAllowed(response, 'POST')
def test_authenticated_user(self): '''Authenticated users shouldn't be able to update committees.''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.committee.id, params=self.params) self.assertMethodNotAllowed(response, 'PATCH')
def test_self(self): """Authenticated users shouldn't have permission to delete countries.""" TestUsers.new_user(username="******", password="******") self.client.login(username="******", password="******") response = self.get_response(self.country.id) self.assertMethodNotAllowed(response, "DELETE")
def test_import(self): '''Test that the admin panel can import delegates. ''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') school = TestSchools.new_school() cm1 = TestCommittees.new_committee(name='SPD') cm2 = TestCommittees.new_committee(name='USS') co1 = TestCountries.new_country(name="Côte d'Ivoire") co2 = TestCountries.new_country(name='Barbara Boxer') Assignment.objects.create(committee=cm1, country=co1, school=school) Assignment.objects.create(committee=cm2, country=co2, school=school) f = TestFiles.new_csv([ ['Name', 'Committee', 'Country', 'School'], ['John Doe', 'SPD', "Côte d'Ivoire", 'Test School'], ['Jane Doe', 'USS', 'Barbara Boxer', 'Test School'], ]) with closing(f) as f: self.client.post(reverse('admin:core_delegate_load'), {'csv': f}) self.assertTrue( Delegate.objects.filter(assignment=Assignment.objects.get( school=School.objects.get(name='Test School'), committee=Committee.objects.get(name='SPD'), country=Country.objects.get(name="Côte d'Ivoire")), name='John Doe').exists()) self.assertTrue( Delegate.objects.filter(assignment=Assignment.objects.get( school=School.objects.get(name='Test School'), committee=Committee.objects.get(name='USS'), country=Country.objects.get(name='Barbara Boxer')), name='Jane Doe').exists())
def test_authenticated_user(self): '''Authenticated users shouldn't be able to update countries.''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.country.id, params=self.params) self.assertPermissionDenied(response)
def test_import(self): '''Test that the admin panel can import committees.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') f = TestFiles.new_csv([ ['SPD', 'Special Pôlitical and Decolonization', 2, ''], ['USS', 'United States Senate', 2, True] ]) with closing(f) as f: self.client.post(reverse('admin:core_committee_load'), {'csv': f}) self.assertTrue(Committee.objects.filter( name='SPD', full_name='Special Pôlitical and Decolonization', delegation_size=2, special=False ).exists()) self.assertTrue(Committee.objects.filter( name='USS', full_name='United States Senate', delegation_size=2, special=True ).exists())
def test_anonymous_user(self): '''It should reject the request from an anonymous user.''' TestUsers.new_user(username='******') TestUsers.new_user(username='******') response = self.get_response() self.assertNotAuthenticated(response)
def test_super_user(self): '''Countries should not be able to be deleted''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.country.id) self.assertMethodNotAllowed(response, 'DELETE')
def test_superuser(self): '''It finalizes the assignments for a superuser.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.school.id) self.assertFinalized(response)
def test_self(self): '''Authenticated users shouldn't have permission to delete countries.''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.country.id) self.assertPermissionDenied(response)
def test_import(self): '''Test that the admin panel can import Assignments.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') school = TestSchools.new_school() cm1 = TestCommittees.new_committee(name='SPD') cm2 = TestCommittees.new_committee(name='USS') co1 = TestCountries.new_country(name="Côte d'Ivoire") co2 = TestCountries.new_country(name='Barbara Boxer') f = TestFiles.new_csv([['Test School', 'SPD', "Côte d'Ivoire"], ['Test School', 'USS', 'Barbara Boxer']]) with closing(f) as f: self.client.post(reverse('admin:core_assignment_load'), {'csv': f}) self.assertTrue( Assignment.objects.filter( school=School.objects.get(name='Test School'), committee=Committee.objects.get(name='SPD'), country=Country.objects.get(name="Côte d'Ivoire")).exists()) self.assertTrue( Assignment.objects.filter( school=School.objects.get(name='Test School'), committee=Committee.objects.get(name='USS'), country=Country.objects.get(name='Barbara Boxer')).exists())
def test_superuser(self): '''Assignments should not be able to be deleted through API''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.assignment.id) self.assert204(response)
def test_superuser(self): '''It returns the assignments for a superuser.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.school.id) self.assert_assignments_equal(response)
def test_superuser(self): '''It finalizes the assignments for a superuser.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.assignment.id) self.assertDeleted(response)
def test_superuser(self): '''Superusers shouldn't be able to update countries.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.country.id, params=self.params) self.assertMethodNotAllowed(response, 'PATCH')
def test_superuser(self): '''It updates the delegates for a superuser.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.school.id) self.assertEqual(dict(response.data[0]), { 'id': self.delegate1.id, 'assignment': self.params[0]['assignment'], 'school': self.delegate1.school.id, 'name': unicode(self.delegate1.name), 'email': unicode(self.delegate1.email), 'summary': unicode(self.delegate1.summary), 'created_at': self.delegate1.created_at.isoformat() }, ) self.assertEqual(dict(response.data[1]), { 'id': self.delegate2.id, 'assignment': self.params[1]['assignment'], 'school': self.delegate2.school.id, 'name': unicode(self.delegate2.name), 'email': unicode(self.delegate2.email), 'summary': unicode(self.delegate2.summary), 'created_at': self.delegate2.created_at.isoformat() }, )
def test_super_user(self): """Countries should not be able to be deleted""" TestUsers.new_superuser(username="******", password="******") self.client.login(username="******", password="******") response = self.get_response(self.country.id) self.assertMethodNotAllowed(response, "DELETE")
def test_super_user(self): '''Superusers shouldn't be able to create countries.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.params) self.assertMethodNotAllowed(response, 'POST')
def test_import(self): '''Test that the admin panel can import Assignments.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') school = TestSchools.new_school() cm1 = TestCommittees.new_committee(name='SPD') cm2 = TestCommittees.new_committee(name='USS') co1 = TestCountries.new_country(name="Côte d'Ivoire") co2 = TestCountries.new_country(name='Barbara Boxer') f = TestFiles.new_csv([ ['Test School', 'SPD', "Côte d'Ivoire"], ['Test School', 'USS', 'Barbara Boxer'] ]) with closing(f) as f: self.client.post(reverse('admin:core_assignment_load'), {'csv': f}) self.assertTrue(Assignment.objects.filter( school=School.objects.get(name='Test School'), committee=Committee.objects.get(name='SPD'), country=Country.objects.get(name="Côte d'Ivoire") ).exists()) self.assertTrue(Assignment.objects.filter( school=School.objects.get(name='Test School'), committee=Committee.objects.get(name='USS'), country=Country.objects.get(name='Barbara Boxer') ).exists())
def test_superuser(self): """Superusers shouldn't be able to update countries.""" TestUsers.new_superuser(username="******", password="******") self.client.login(username="******", password="******") response = self.get_response(self.country.id, params=self.params) self.assertMethodNotAllowed(response, "PATCH")
def test_preference_export(self): '''Test that the admin panel can properly export school preferences.''' TestUsers.new_user(username='******', password='******') TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') school = TestSchools.new_school() self.client.logout() self.client.login(username='******', password='******') response = self.client.get(reverse('admin:core_school_preferences')) self.assertTrue(response) header = [ "Name", "Assignments Requested", "Beginners", "Intermediates", "Advanced", "Spanish Speakers", "Bilingual?", "Specialized/Regional?", "Crisis?", "Alternative?", "Press Corps?", "Country 1", "Country 2", "Country 3", "Country 4", "Country 5", "Country 6", "Country 7", "Country 8", "Country 9", "Country 10", "Registration Comments" ] fields_csv = ",".join(map(str, header)) + "\r\n" countryprefs = [c for c in school.countrypreferences.all()] countryprefs += [''] * (10 - len(countryprefs)) fields = [ school.name, school.beginner_delegates + school.intermediate_delegates + school.advanced_delegates, school.beginner_delegates, school.intermediate_delegates, school.advanced_delegates, school.spanish_speaking_delegates, school.prefers_bilingual, school.prefers_specialized_regional, school.prefers_crisis, school.prefers_alternative, school.prefers_press_corps] fields.extend(countryprefs) fields.append(school.registration_comments) fields_csv += ",".join(map(str, fields)) self.assertEquals(fields_csv, response.content[:-2])
def test_superuser(self): '''Superusers shouldn't be able to create committees.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.params) self.assertMethodNotAllowed(response, 'POST')
def test_authenticated_user(self): '''Authenticated users shouldn't be able to create committees.''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.params) self.assertMethodNotAllowed(response, 'POST')
def test_import(self): '''Test that the admin panel can import countries. ''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') f = TestFiles.new_csv([ ['United States of America', ''], ['Barbara Boxer', True], ["Côte d'Ivoire", ''] ]) with closing(f) as f: self.client.post(reverse('admin:core_country_load'), {'csv': f}) self.assertTrue(Country.objects.filter( name='United States of America', special=False ).exists()) self.assertTrue(Country.objects.filter( name='Barbara Boxer', special=True ).exists()) self.assertTrue(Country.objects.filter( name="Côte d'Ivoire", special=False ).exists())
def test_superuser(self): '''It returns the delegates for a superuser.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.school.id) self.assert_delegate_equal(response)
def test_superuser(self): '''A superuser should not be able to delete an account.''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.school.id) self.assertPermissionDenied(response) self.assertTrue(School.objects.filter(id=self.school.id).exists())
def test_superuser(self): '''It should reject a request from a superuser.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response() self.assertMethodNotAllowed(response, 'GET')
def test_user(self): '''It should reject the request from a regular user.''' TestUsers.new_user(username='******', password='******') TestUsers.new_user(username='******') self.client.login(username='******', password='******') response = self.get_response() self.assertPermissionDenied(response)
def test_other_user(self): '''It should reject the request from another user.''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.user.id) self.assertPermissionDenied(response) self.assertTrue(User.objects.filter(id=self.user.id).exists())
def test_superuser(self): '''It should allow a superuser to delete a user.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.user.id) self.assertEqual(response.status_code, 204) self.assertFalse(User.objects.filter(id=self.user.id).exists())
def test_other_user(self): '''It should reject the request from another user.''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.user.id) self.assertPermissionDenied(response) self.assertTrue(HuxleyUser.objects.filter(id=self.user.id).exists())
def test_superuser(self): '''It should allow a superuser to delete a user.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.user.id) self.assertEqual(response.status_code, 204) self.assertFalse(HuxleyUser.objects.filter(id=self.user.id).exists())
def test_superuser(self): '''This should allow a superuser to change school data.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.school.id, params=self.params) self.school = School.objects.get(id=self.school.id) self.assertEqual(response.data['name'], self.school.name) self.assertEqual(response.data['city'], self.school.city)
def test_superuser(self): '''A superuser should be allowed to change information about a user.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.user.id, params=self.params) user = User.objects.get(id=self.user.id) self.assertEqual(response.data['first_name'], user.first_name) self.assertEqual(response.data['last_name'], user.last_name)
def test_other_user(self): '''it should not allow a get request from another user.''' school = TestSchools.new_school() TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(school.id) self.assertPermissionDenied(response)
def test_other_user(self): '''It should reject request from another user.''' user1 = TestUsers.new_user(username='******') user2 = TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(user1.id) self.assertPermissionDenied(response)
def test_superuser(self): '''A superuser should be allowed to change information about a user.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.user.id, params=self.params) user = HuxleyUser.objects.get(id=self.user.id) self.assertEqual(response.data['first_name'], user.first_name) self.assertEqual(response.data['last_name'], user.last_name)
def test_other_user(self): '''Should not allow another user to change a school's data''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.school.id, params=self.params) updated_school = School.objects.get(id=self.school.id) self.assertPermissionDenied(response) self.assertEqual(updated_school.name, self.school.name) self.assertEqual(updated_school.city, self.school.city)
def test_other_user(self): '''Another user should not be able to change information about any other user.''' TestUsers.new_user(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(self.user.id, params=self.params) self.assertPermissionDenied(response) user = HuxleyUser.objects.get(id=self.user.id) self.assertEqual(user.first_name, 'Test') self.assertEqual(user.last_name, 'User')
def test_reset_password(self): '''It should correctly reset a user's password or raise an error.''' password = '******' user = TestUsers.new_user(username='******', password=password) self.assertTrue(user.check_password(password)) User.reset_password('lololol') user = User.objects.get(id=user.id) self.assertFalse(user.check_password(password)) with self.assertRaises(User.DoesNotExist): TestUsers.new_user(username='', email='') User.reset_password('')
def test_superuser(self): '''Superusers should be able to create assignments.''' TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(params=self.params) response.data.pop('id') self.assertEqual( response.data, { "committee": self.committee.id, "country": self.country.id, "school": self.school.id, "rejected": True, })
def test_superuser(self): '''it should allow a get request from a superuser.''' school = TestSchools.new_school() user = TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(school.id) self.assertEqual( response.data, { 'id': school.id, 'registered': school.registered, 'name': school.name, 'address': school.address, 'city': school.city, 'state': school.state, 'zip_code': school.zip_code, 'country': school.country, 'primary_name': school.primary_name, 'primary_email': school.primary_email, 'primary_phone': school.primary_phone, 'secondary_name': school.secondary_name, 'secondary_email': school.secondary_email, 'secondary_phone': school.secondary_phone, 'program_type': school.program_type, 'times_attended': school.times_attended, 'min_delegation_size': school.min_delegation_size, 'max_delegation_size': school.max_delegation_size, 'international': school.international, 'waitlist': school.waitlist })
def test_superuser(self): '''It should return the correct fields for a superuser.''' user1 = TestUsers.new_user(username='******') user2 = TestUsers.new_superuser(username='******', password='******') self.client.login(username='******', password='******') response = self.get_response(user1.id) self.assertEqual(response.data, { 'id': user1.id, 'username': user1.username, 'first_name': user1.first_name, 'last_name': user1.last_name, 'user_type': user1.user_type, 'school': user1.school_id, 'committee': user1.committee_id})