class TestMeetingCreateFormView(AdminTestCase): def setUp(self): super(TestMeetingCreateFormView, self).setUp() Conference.remove() self.user = AuthUserFactory() self.request = RequestFactory().post('/fake_path') self.view = MeetingCreateFormView() mod_data = dict(data) mod_data.update({'admins': self.user.emails[0]}) self.form = MeetingForm(data=mod_data) self.form.is_valid() def test_get_initial(self): self.view.get_initial() nt.assert_equal(self.view.initial['edit'], False) nt.assert_equal(self.view.initial['submission1'], DEFAULT_FIELD_NAMES['submission1']) def test_form_valid(self): view = setup_form_view(self.view, self.request, self.form) view.form_valid(self.form) nt.assert_equal( Conference.find(Q('endpoint', 'iexact', data['endpoint'])).count(), 1 )
def test_clean_admins_okay(self): mod_data = dict(data) mod_data.update({ 'admins': self.user.emails.values_list('address', flat=True).first() }) form = MeetingForm(data=mod_data) nt.assert_true(form.is_valid())
def setUp(self): super(TestMeetingCreateFormView, self).setUp() Conference.remove() self.user = AuthUserFactory() self.request = RequestFactory().post('/fake_path') self.view = MeetingCreateFormView() mod_data = dict(data) mod_data.update({'admins': self.user.emails[0]}) self.form = MeetingForm(data=mod_data) self.form.is_valid()
def setUp(self): super(TestMeetingCreateFormView, self).setUp() Conference.objects.all().delete() self.user = AuthUserFactory() self.request = RequestFactory().post('/fake_path') self.view = MeetingCreateFormView mod_data = dict(data) mod_data.update({'admins': self.user.emails.first().address}) self.form = MeetingForm(data=mod_data) self.form.is_valid() self.url = reverse('meetings:create')
class TestMeetingFormView(AdminTestCase): def setUp(self): super(TestMeetingFormView, self).setUp() self.conf = ConferenceFactory() self.user = AuthUserFactory() self.request = RequestFactory().post('/fake_path') self.view = MeetingFormView() mod_data = dict(data) mod_data.update({ 'edit': 'True', 'endpoint': self.conf.endpoint, 'admins': self.user.emails[0], 'location': 'Timbuktu, Mali', 'start date': 'Dec 11 2014', 'end_date': 'Jan 12 2013' }) self.form = MeetingForm(data=mod_data) self.form.is_valid() def test_dispatch_raise_404(self): view = setup_form_view(self.view, self.request, self.form, endpoint='meh') with nt.assert_raises(Http404): view.dispatch(self.request, endpoint='meh') def test_get_context(self): view = setup_form_view(self.view, self.request, self.form, endpoint=self.conf.endpoint) view.conf = self.conf res = view.get_context_data() nt.assert_is_instance(res, dict) nt.assert_in('endpoint', res) nt.assert_equal(res['endpoint'], self.conf.endpoint) def test_get_initial(self): view = setup_form_view(self.view, self.request, self.form, endpoint=self.conf.endpoint) view.conf = self.conf res = view.get_initial() nt.assert_is_instance(res, dict) nt.assert_in('endpoint', res) nt.assert_in('submission2_plural', res) def test_form_valid(self): view = setup_form_view(self.view, self.request, self.form, endpoint=self.conf.endpoint) view.conf = self.conf view.form_valid(self.form) self.conf.reload() nt.assert_equal(self.conf.admins[0].emails[0], self.user.emails[0]) nt.assert_equal(self.conf.location, self.form.cleaned_data['location']) nt.assert_equal(self.conf.start_date, self.form.cleaned_data['start_date'])
def test_clean_endpoint_raise_not_exist(self): mod_data = dict(data) mod_data.update({'admins': self.user.emails[0], 'edit': 'True'}) form = MeetingForm(data=mod_data) nt.assert_in('endpoint', form.errors) nt.assert_equal('Meeting not found with this endpoint to update', form.errors['endpoint'][0])
def setUp(self): super(TestMeetingFormView, self).setUp() self.conf = ConferenceFactory() self.user = AuthUserFactory() self.request = RequestFactory().post('/fake_path') self.view = MeetingFormView() mod_data = dict(data) mod_data.update({ 'edit': 'True', 'endpoint': self.conf.endpoint, 'admins': self.user.emails[0], 'location': 'Timbuktu, Mali', 'start date': 'Dec 11 2014', 'end_date': 'Jan 12 2013' }) self.form = MeetingForm(data=mod_data) self.form.is_valid()
class TestMeetingCreateFormView(AdminTestCase): def setUp(self): super(TestMeetingCreateFormView, self).setUp() Conference.remove() self.user = AuthUserFactory() self.request = RequestFactory().post('/fake_path') self.view = MeetingCreateFormView mod_data = dict(data) mod_data.update({'admins': self.user.emails.first().address}) self.form = MeetingForm(data=mod_data) self.form.is_valid() self.url = reverse('meetings:create') def test_get_initial(self): self.view().get_initial() nt.assert_equal(self.view().initial['edit'], False) nt.assert_equal(self.view.initial['submission1'], DEFAULT_FIELD_NAMES['submission1']) def test_form_valid(self): view = setup_form_view(self.view(), self.request, self.form) view.form_valid(self.form) nt.assert_equal( Conference.objects.filter(endpoint=data['endpoint']).count(), 1) def test_no_user_permissions_raises_error(self): request = RequestFactory().get(self.url) request.user = self.user with nt.assert_raises(PermissionDenied): self.view.as_view()(request) def test_correct_view_permissions(self): change_permission = Permission.objects.get(codename='view_conference') view_permission = Permission.objects.get(codename='change_conference') self.user.user_permissions.add(view_permission) self.user.user_permissions.add(change_permission) self.user.save() request = RequestFactory().get(self.url) request.user = self.user response = self.view.as_view()(request) nt.assert_equal(response.status_code, 200)
def test_clean_endpoint_raise_exists(self): conf = ConferenceFactory() mod_data = dict(data) mod_data.update({'admins': self.user.emails[0], 'endpoint': conf.endpoint}) form = MeetingForm(data=mod_data) nt.assert_in('endpoint', form.errors) nt.assert_equal('A meeting with this endpoint exists already.', form.errors['endpoint'][0])
class TestMeetingCreateFormView(AdminTestCase): def setUp(self): super(TestMeetingCreateFormView, self).setUp() Conference.objects.all().delete() self.user = AuthUserFactory() self.request = RequestFactory().post('/fake_path') self.view = MeetingCreateFormView mod_data = dict(data) mod_data.update({'admins': self.user.emails.first().address}) self.form = MeetingForm(data=mod_data) self.form.is_valid() self.url = reverse('meetings:create') def test_get_initial(self): self.view().get_initial() nt.assert_equal(self.view().initial['edit'], False) nt.assert_equal(self.view.initial['submission1'], DEFAULT_FIELD_NAMES['submission1']) def test_form_valid(self): view = setup_form_view(self.view(), self.request, self.form) view.form_valid(self.form) nt.assert_equal(Conference.objects.filter(endpoint=data['endpoint']).count(), 1) def test_no_user_permissions_raises_error(self): request = RequestFactory().get(self.url) request.user = self.user with nt.assert_raises(PermissionDenied): self.view.as_view()(request) def test_correct_view_permissions(self): change_permission = Permission.objects.get(codename='view_conference') view_permission = Permission.objects.get(codename='change_conference') self.user.user_permissions.add(view_permission) self.user.user_permissions.add(change_permission) self.user.save() request = RequestFactory().get(self.url) request.user = self.user response = self.view.as_view()(request) nt.assert_equal(response.status_code, 200)
def test_clean_admins_okay(self): mod_data = dict(data) mod_data.update({"admins": self.user.emails[0]}) form = MeetingForm(data=mod_data) nt.assert_true(form.is_valid())
class TestMeetingFormView(AdminTestCase): def setUp(self): super(TestMeetingFormView, self).setUp() self.conf = ConferenceFactory() self.user = AuthUserFactory() self.request = RequestFactory().post('/fake_path') self.view = MeetingFormView mod_data = dict(data) mod_data.update({ 'edit': 'True', 'endpoint': self.conf.endpoint, 'admins': self.user.emails.first().address, 'location': 'Timbuktu, Mali', 'start date': 'Dec 11 2014', 'end_date': 'Jan 12 2013' }) self.form = MeetingForm(data=mod_data) self.form.is_valid() self.url = reverse('meetings:detail', kwargs={'endpoint': self.conf.endpoint}) def test_dispatch_raise_404(self): view = setup_form_view(self.view(), self.request, self.form, endpoint='meh') with nt.assert_raises(Http404): view.dispatch(self.request, endpoint='meh') def test_get_context(self): view = setup_form_view(self.view(), self.request, self.form, endpoint=self.conf.endpoint) view.conf = self.conf res = view.get_context_data() nt.assert_is_instance(res, dict) nt.assert_in('endpoint', res) nt.assert_equal(res['endpoint'], self.conf.endpoint) def test_get_initial(self): view = setup_form_view(self.view(), self.request, self.form, endpoint=self.conf.endpoint) view.conf = self.conf res = view.get_initial() nt.assert_is_instance(res, dict) nt.assert_in('endpoint', res) nt.assert_in('submission2_plural', res) def test_form_valid(self): view = setup_form_view(self.view(), self.request, self.form, endpoint=self.conf.endpoint) view.conf = self.conf view.form_valid(self.form) self.conf.reload() nt.assert_equal(self.conf.admins.all()[0].emails.first().address, self.user.emails.first().address) nt.assert_equal(self.conf.location, self.form.cleaned_data['location']) nt.assert_equal(self.conf.start_date, self.form.cleaned_data['start_date']) def test_no_user_permissions_raises_error(self): request = RequestFactory().get(self.url) request.user = self.user with nt.assert_raises(PermissionDenied): self.view.as_view()(request, endpoint=self.conf.endpoint) def test_correct_view_permissions(self): view_permission = Permission.objects.get(codename='change_conference') self.user.user_permissions.add(view_permission) self.user.save() request = RequestFactory().get(self.url) request.user = self.user response = self.view.as_view()(request, endpoint=self.conf.endpoint) nt.assert_equal(response.status_code, 200)
def test_clean_admins_okay(self): mod_data = dict(data) mod_data.update({'admins': self.user.emails[0]}) form = MeetingForm(data=mod_data) nt.assert_true(form.is_valid())
def test_clean_admins_raise(self): form = MeetingForm(data=data) nt.assert_false(form.is_valid()) nt.assert_in('admins', form.errors) nt.assert_in('*****@*****.**', form.errors['admins'][0]) nt.assert_in('does not have an OSF account', form.errors['admins'][0])
def test_clean_admins_okay(self): mod_data = dict(data) mod_data.update({'admins': self.user.emails.values_list('address', flat=True).first()}) form = MeetingForm(data=mod_data) nt.assert_true(form.is_valid())
def test_clean_admins_raise(self): form = MeetingForm(data=data) nt.assert_false(form.is_valid()) nt.assert_in("admins", form.errors) nt.assert_in("*****@*****.**", form.errors["admins"][0]) nt.assert_in("does not have an OSF account", form.errors["admins"][0])