Exemplo n.º 1
0
    def test_delete_redirects_to_org_list(self, matchers, org, pyramid_request):
        ctrl = OrganizationEditController(org, pyramid_request)

        response = ctrl.delete()

        list_url = pyramid_request.route_path('admin_organizations')
        assert response == matchers.Redirect302To(list_url)
Exemplo n.º 2
0
    def test_logo_is_empty_if_not_set(self, pyramid_request, org):
        org.logo = None
        ctrl = OrganizationEditController(org, pyramid_request)

        ctx = ctrl.read()

        assert ctx['form']['logo'] == ''
Exemplo n.º 3
0
    def test_logo_is_empty_if_not_set(self, pyramid_request, org):
        org.logo = None
        ctrl = OrganizationEditController(org, pyramid_request)

        ctx = ctrl.read()

        assert ctx['form']['logo'] == ''
Exemplo n.º 4
0
    def test_read_does_not_show_delete_button_for_default_org(self, pyramid_request, org):
        org.pubid = '__default__'
        ctrl = OrganizationEditController(org, pyramid_request)

        ctx = ctrl.read()

        assert ctx['delete_url'] is None
Exemplo n.º 5
0
    def test_delete_redirects_to_org_list(self, org, pyramid_request):
        ctrl = OrganizationEditController(org, pyramid_request)

        response = ctrl.delete()

        list_url = pyramid_request.route_path('admin_organizations')
        assert response == redirect_302_to(list_url)
Exemplo n.º 6
0
    def test_read_does_not_show_delete_button_for_default_org(
            self, pyramid_request, org):
        org.pubid = '__default__'
        ctrl = OrganizationEditController(org, pyramid_request)

        ctx = ctrl.read()

        assert ctx['delete_url'] is None
Exemplo n.º 7
0
    def test_delete_fails_if_org_has_groups(self, factories, matchers, org, pyramid_request):
        factories.Group(name='Test', organization=org)
        ctrl = OrganizationEditController(org, pyramid_request)

        ctx = ctrl.delete()

        assert org not in pyramid_request.db.deleted
        assert pyramid_request.response.status_int == 400
        pyramid_request.session.flash.assert_called_with(
            matchers.Regex('.*Cannot delete.*1 groups'), 'error')
        assert ctx['form'] == self._expected_form(org)
Exemplo n.º 8
0
    def test_delete_fails_if_org_has_groups(self, factories, matchers, org,
                                            pyramid_request):
        factories.Group(name='Test', organization=org)
        ctrl = OrganizationEditController(org, pyramid_request)

        ctx = ctrl.delete()

        assert org not in pyramid_request.db.deleted
        assert pyramid_request.response.status_int == 400
        pyramid_request.session.flash.assert_called_with(
            matchers.Regex('.*Cannot delete.*1 groups'), 'error')
        assert ctx['form'] == self._expected_form(org)
Exemplo n.º 9
0
    def test_update_saves_org(self, pyramid_request, org, handle_form_submission):
        def call_on_success(request, form, on_success, on_failure):
            return on_success({'name': 'Updated name',
                               'authority': org.authority,
                               'logo': '<svg>new logo</svg>'})
        handle_form_submission.side_effect = call_on_success
        ctrl = OrganizationEditController(org, pyramid_request)

        ctx = ctrl.update()

        assert org.name == 'Updated name'
        assert org.logo == '<svg>new logo</svg>'
        assert ctx['form'] == self._expected_form(org)
Exemplo n.º 10
0
    def test_update_saves_org(self, pyramid_request, org,
                              handle_form_submission):
        def call_on_success(request, form, on_success, on_failure):
            return on_success({
                'name': 'Updated name',
                'authority': org.authority,
                'logo': '<svg>new logo</svg>'
            })

        handle_form_submission.side_effect = call_on_success
        ctrl = OrganizationEditController(org, pyramid_request)

        ctx = ctrl.update()

        assert org.name == 'Updated name'
        assert org.logo == '<svg>new logo</svg>'
        assert ctx['form'] == self._expected_form(org)
Exemplo n.º 11
0
 def test_read_shows_delete_button(self, pyramid_request, org):
     ctrl = OrganizationEditController(org, pyramid_request)
     ctx = ctrl.read()
     assert ctx['delete_url'] == pyramid_request.route_url('admin_organizations_delete', pubid=org.pubid)
Exemplo n.º 12
0
 def test_read_presents_org(self, pyramid_request, org):
     ctrl = OrganizationEditController(org, pyramid_request)
     ctx = ctrl.read()
     assert ctx['form'] == self._expected_form(org)
Exemplo n.º 13
0
 def test_delete_removes_org(self, pyramid_request, db_session, org):
     ctrl = OrganizationEditController(org, pyramid_request)
     ctrl.delete()
     assert org in db_session.deleted
Exemplo n.º 14
0
 def test_read_presents_org(self, pyramid_request, org):
     ctrl = OrganizationEditController(org, pyramid_request)
     ctx = ctrl.read()
     assert ctx['form'] == self._expected_form(org)
Exemplo n.º 15
0
 def test_delete_removes_org(self, pyramid_request, db_session, org):
     ctrl = OrganizationEditController(org, pyramid_request)
     ctrl.delete()
     assert org in db_session.deleted
Exemplo n.º 16
0
 def test_read_shows_delete_button(self, pyramid_request, org):
     ctrl = OrganizationEditController(org, pyramid_request)
     ctx = ctrl.read()
     assert ctx['delete_url'] == pyramid_request.route_url(
         'admin_organizations_delete', pubid=org.pubid)