Beispiel #1
0
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'])
Beispiel #2
0
 def test_migrate_node(self):
     external_admin = UserFactory()
     personal_admin = UserFactory()
     staff_user = UserFactory()
     personal_accounts = [personal_admin.username]
     conference = ConferenceFactory(admins=[external_admin, personal_admin])
     node = NodeFactory()
     node.add_contributor(staff_user)
     node.add_contributor(external_admin)
     node.add_contributor(personal_admin)
     migrate_node(node,
                  conference,
                  staff_user,
                  personal_accounts,
                  dry_run=False)
     node.reload()
     assert_in(staff_user, node.contributors)
     assert_in(external_admin, node.contributors)
     assert_not_in(personal_admin, node.contributors)
     # Verify that migration is idempotent
     migrate_node(node,
                  conference,
                  staff_user,
                  personal_accounts,
                  dry_run=False)
     node.reload()
     assert_in(staff_user, node.contributors)
     assert_in(external_admin, node.contributors)
     assert_not_in(personal_admin, node.contributors)
Beispiel #3
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()
Beispiel #4
0
    def test_add_conference_when_conference_already_exists(self):
        conf = ConferenceFactory()
        user = UserFactory()

        with assert_raises(RuntimeError):
            add_conference(conf.endpoint,
                           name='SPSP',
                           admins=[user.username],
                           active=True)
Beispiel #5
0
 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])
Beispiel #6
0
 def setUp(self):
     super(TestMeetingListView, self).setUp()
     Conference.remove()
     ConferenceFactory()
     ConferenceFactory()
     ConferenceFactory()
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)
Beispiel #8
0
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)
Beispiel #9
0
 def setUp(self):
     super(TestMeetingListView, self).setUp()
     Conference.objects.all().delete()
     ConferenceFactory()
     ConferenceFactory()
     ConferenceFactory()
Beispiel #10
0
 def setUp(self):
     super(TestsSerializeMeeting, self).setUp()
     self.conf = ConferenceFactory()