Ejemplo n.º 1
0
    def test_context_global(self, client, root):
        """ collect global entries, i.e. from multiple blogs """
        n1 = root.add("b1")
        n2 = root.add("b2")
        n3 = root.add("b3")
        ## blog state is actually ignored!
        _ = ValveBlog(node=n1, state="published").save()
        _ = ValveBlog(node=n2, state="published").save()
        _ = ValveBlog(node=n3, state="published").save()
        _ = ValveEntry(node=n1.add("e1"), state="published").save()
        _ = ValveEntry(node=n2.add("e2"), state="published").save()
        _ = ValveEntry(node=n3.add("e3"), state="published").save()

        request = create_request("GET", "/", data={})

        handler = MainHandlerTestable()
        handler.init_from_request(request)
        handler.instance = root

        ctx = blog_context(handler, request, root)

        assert 'paginator' in ctx
        res = ctx['paginator'].object_list
        assert len(res) == 3
        assert set(x.slug() for x in res) == set(("e1", "e2", "e3"))
Ejemplo n.º 2
0
 def test_attached_root(self, client, root):
     """ A root node with content attached. Its name should not be
         its title but 'Home' """
     Type1(node=root, title="The rootnode of this site").save()
     request = create_request("GET", "/")
     handler = MainHandlerTestable(request=request, instance=root)
     assert handler.breadcrumb() == [("Home", '')]
Ejemplo n.º 3
0
    def test_translations_create(self, client):
        root = Node.root()

        n = root.add(langslugs=dict(en="en", nl="nl", fr="fr"))
        t_nl = Type1(node=n, language="nl", title="NL").save()
        t_en = Type1(node=n, language="en", title="EN").save()


        request = create_request("GET", "/create", data=dict(type="sometype"))

        translation.activate("en")
        toolbar = Toolbar(n, request, "create")
        translations = toolbar.translations()

        assert translations['active']['id'] == 'en'

        import urllib2

        ## Do some matching magic using endswith to work around language / base prefixing.
        ## We're mosly interested in create/view/edit actions anyway
        assert len(translations['translated']) == 0
        assert len(translations['untranslated']) == 3  ## all languages incl 'any', active lang excluded

        for ut in translations['untranslated']:
            l = ut['id']
            assert l in ('nl', 'fr', 'en', 'any')
            assert ut['action_url'].endswith('switch_admin_language?path='+n.tree_path + '&switchto=' + l + '&rest=' + urllib2.quote('create?type=sometype'))
Ejemplo n.º 4
0
    def test_nosu_no_settings(self, client):
        user, _ = User.objects.get_or_create(username="******")
        request = create_request("GET", "/")
        request.user = user

        node = Node.root()
        toolbar = Toolbar(node, request, "view")
        assert not toolbar.show_settings()
Ejemplo n.º 5
0
    def test_parent_instance(self, client):
        """ handler initialized with a parent but no instance. Should
            mean edit mode, but for now assume custom breadcrumb context """
        root = Node.root()
        Type1(node=root, title="Root").save()
        request = create_request("GET", "/")
        handler = MainHandlerTestable(request=request, kw=dict(parent=root))

        assert handler.breadcrumb() == []
Ejemplo n.º 6
0
 def test_create_get_root(self, client):
     """ test create on root - get """
     root = Node.root()
     Type1(node=root).save()
     request = create_request("GET", "/", data=dict(type="type1"))
     handler = MainHandlerTestable(request=request, instance=root)
     # import pytest; pytest.set_trace()
     create = handler.create()
     assert create['path'] == "wheelcms_axe/create.html"
     assert 'form' in create['context']
Ejemplo n.º 7
0
    def test_permission_post_access(self):
        """ if permission is present, call should succeed """
        with mock.patch("wheelcms_axle.auth.has_access") as m:
            m.return_value = True
            request = create_request("POST", "/@/configuration", data={})
            h = ConfigurationHandler()
            h.init_from_request(request)

            assert h.post(request) is not None

            assert m.call_args[0][3] == p.modify_settings
Ejemplo n.º 8
0
    def test_permission_post_denied(self, client):
        """ Verify post is guarded by modify_settings permission """
        with mock.patch("wheelcms_axle.auth.has_access") as m:
            m.return_value = False
            request = create_request("POST", "/@/configuration", data={})
            h = ConfigurationHandler()
            h.init_from_request(request)
            with pytest.raises(Forbidden):
                h.post(request)

            assert m.call_args[0][3] == p.modify_settings
Ejemplo n.º 9
0
 def setup_handler(self, user=None, method="GET", with_instance=False,
                   state="private"):
     """ setup the mainhandler """
     ins = None
     if with_instance:
         cont = Type1(node=Node.root(), state=state).save()
         ins =  cont.node
     request = create_request(method, "/")
     if self.provide_user():
         request.user = self.provide_user()
     handler = MainHandler(request=request, instance=ins)
     return handler
Ejemplo n.º 10
0
    def test_subsub_unattached(self, client, root):
        """ a child with content under the root, lowest child unattached """
        Type1(node=root, title="Root").save()
        child = root.add("child")
        Type1(node=child, title="Child").save()
        child2 = child.add("child2")
        request = create_request("GET", "/")

        handler = MainHandlerTestable(request=request, instance=child2)
        assert handler.breadcrumb() == [("Home", root.get_absolute_url()),
                                        ("Child", child.get_absolute_url()),
                                        ("Unattached node /child/child2", "")]
Ejemplo n.º 11
0
 def test_comment_language_create(self, client, root):
     """
         A comment should be created with the same language as its parent
     """
     nl = Type1(node=root, language="nl").save()
     en = Type1(node=root, language="en").save()
     req = create_request("POST", "/",
                          data=dict(name="1", body="1", captcha="1"))
     translation.activate('nl')
     handler = MainHandler(request=req, instance=root)
     pytest.raises(Redirect, handle_comment_post,
                  handler, req, "+post_comment")
     assert root.children()[0].content().language == 'nl'
Ejemplo n.º 12
0
    def test_sub(self, client, root):
        """ a child with content under the root """
        Type1(node=root, title="Root").save()
        child = root.add("child")
        Type1(node=child, title="Child").save()
        request = create_request("GET", "/")

        handler = MainHandlerTestable(request=request, instance=child)
        assert handler.breadcrumb() == [("Home", root.get_absolute_url()),
                                        ("Child", "")]

        ## root should ignore child
        handler = MainHandlerTestable(request=request, instance=root)
        assert handler.breadcrumb() == [("Home", '')]
Ejemplo n.º 13
0
    def test_show_translate(self, client):
        root = Node.root()

        n = root.add(langslugs=dict(en="en", nl="nl", fr="fr"))
        t_nl = Type1(node=n, language="nl", title="NL").save()
        translation.activate("en")
        request = create_request("GET", "/")
        toolbar = Toolbar(n, request, "view")

        assert toolbar.show_translate()
        assert not toolbar.show_update()
        translation.activate("nl")
        assert not toolbar.show_translate()
        assert toolbar.show_update()
Ejemplo n.º 14
0
    def test_subsub_operation(self, client, root):
        """ a child with content under the root """
        Type1(node=root, title="Root").save()
        child = root.add("child")
        Type1(node=child, title="Child").save()
        child2 = child.add("child2")
        Type1(node=child2, title="Child2").save()
        request = create_request("GET", "/")

        handler = MainHandlerTestable(request=request, instance=child2)
        assert handler.breadcrumb(operation="Edit") == [
            ("Home", root.get_absolute_url()),
            ("Child", child.get_absolute_url()),
            ("Child2", child2.get_absolute_url()), ("Edit", "")]
Ejemplo n.º 15
0
    def setup_handler(self, user=None, method="GET", with_instance=False,
                      state="private"):
        """ setup the mainhandler """
        root = Node.root()
        if with_instance:
            cont = Type1Type.create(node=root, state=state).save()
            cont.assign_perms()
        request = create_request(method, "/", data={'type':Type1.get_name()})
        if self.provide_user():
            request.user = self.provide_user()
        handler = MainHandler()
        handler.init_from_request(request)
        handler.instance = root

        return handler
Ejemplo n.º 16
0
    def test_clipboard_copy(self, client):
        root = Node.root()

        t1 = Type1(node=root.add("t1"), title="t1").save()
        t2 = Type1(node=root.add("t2"), title="t2").save()

        request = create_request("GET", "/")
        request.session['clipboard_copy'] = [t2.node.tree_path, t1.node.tree_path]

        toolbar = Toolbar(Node.root(), request, "view")
        clipboard = toolbar.clipboard()
        assert clipboard['count'] == 2
        assert clipboard['copy']
        assert not clipboard['cut']
        assert set(clipboard['items']) == set((t1, t2))
Ejemplo n.º 17
0
    def test_language_filter(self, client, root):
        """ Only return comments in the current language """
        en = Type1(node=root, language="en").save()
        nl = Type1(node=root, language="nl").save()

        nlc = Comment(title="NL comment", body="NL", state="published",
                     node=root.add("nl_comment"), language="nl").save()
        enc = Comment(title="EN comment", body="EN", state="published",
                     node=root.add("en_comment"), language="en").save()

        translation.activate('nl')
        cfn = CommentFormNode()
        req = create_request("GET", "/", data=dict())
        res = cfn.show_comments(root, req)
        assert len(res) == 1
        assert res[0].language == "nl"
Ejemplo n.º 18
0
    def test_handler_create(self, superuser, client):
        """ The handler *can* set the user """
        request = create_request("POST", "/create",
                                 data=dict(title="Test",
                                           slug="test",
                                           language="en",
                                           type=Type1.get_name()))
        request.user = superuser

        handler = MainHandler()
        res = handler.dispatch(request, nodepath="", handlerpath="create")
        assert res.status_code == 302

        node = Node.get("/test")
        assert node.content().title == "Test"
        assert node.content().owner == superuser
Ejemplo n.º 19
0
    def test_handler_create(self, client):
        """ The handler *can* set the user """
        request = create_request("POST", "/create",
                                 data=dict(title="Test",
                                           slug="test",
                                           language="en"))
        request.user = self.user

        root = Node.root()
        handler = MainHandler(request=request, post=True,
                              instance=dict(parent=root))
        pytest.raises(Redirect, handler.create, type=Type1.get_name())

        node = Node.get("/test")
        assert node.content().title == "Test"
        assert node.content().owner == self.user
Ejemplo n.º 20
0
    def test_context_on_blog(self, client, root):
        """ should find published entries, several levels deep """
        _ = ValveBlog(node=root, state="published").save()
        _ = ValveEntry(node=root.add("e1"), state="published").save()
        _ = ValveEntry(node=root.add("e2"), state="published").save()
        _ = ValveEntry(node=root.add("e3"), state="private").save()

        request = create_request("GET", "/", data={})

        handler = MainHandlerTestable()
        handler.init_from_request(request)
        handler.instance = root
        ctx = blog_context(handler, request, root)

        assert 'paginator' in ctx
        res = ctx['paginator'].object_list
        assert len(res) == 2
        assert set(x.slug() for x in res) == set(("e1", "e2"))
Ejemplo n.º 21
0
    def test_show_comments_anonymous(self, client, root):
        """ An anonymous user should only see published and "own" comments """
        t = Type1(node=root).save()
        req = create_request("POST", "/",
                             data=dict(name="1", body="1", captcha="1"))
        handler = MainHandler(request=req, instance=root)
        pytest.raises(Redirect, handle_comment_post,
                     handler, req, "+post_comment")
        c2 = Comment(title="2", body="2", state="published",
                     node=root.add("c2")).save()
        rejected = Comment(title="3", body="3", state="rejected",
                           node=root.add("c3")).save()
        cfn = CommentFormNode()
        res = cfn.show_comments(root, req)

        assert len(res) == 2
        ## all children except rejected
        assert set(res) == set(c.content() for c in root.children()) - \
                           set((rejected,))
Ejemplo n.º 22
0
    def test_translations_list(self, client):
        root = Node.root()

        n = root.add(langslugs=dict(en="en", nl="nl", fr="fr"))
        t_nl = Type1(node=n, language="nl", title="NL").save()
        t_en = Type1(node=n, language="en", title="EN").save()


        request = create_request("GET", "/")

        translation.activate("en")
        toolbar = Toolbar(n, request, "list")
        translations = toolbar.translations()

        assert translations['active']['id'] == 'en'

        ## Do some matching magic using endswith to work around language / base prefixing.
        ## We're mosly interested in create/view/edit actions anyway
        assert translations['translated'][0]['id'] == "nl"
        assert translations['translated'][0]['action_url'].endswith('switch_admin_language?path='+n.tree_path + '&switchto=nl&rest=list')
        assert translations['untranslated'][0]['id'] == 'fr'
        assert translations['untranslated'][0]['action_url'].endswith('switch_admin_language?path='+n.tree_path + '&switchto=fr&rest=list')
Ejemplo n.º 23
0
    def test_allblogs(self, client, root):
        """ in a global context (i.e. not directly on a blog instance) we
            want a list of all underlying (published) blogs for proper rss
            feed linking """
        n1 = root.add("b1")
        n2 = root.add("b2")
        n3 = root.add("b3")
        
        _ = ValveBlog(node=n1, state="published").save()
        _ = ValveBlog(node=n2, state="private").save()
        _ = ValveBlog(node=n3, state="published").save()

        request = create_request("GET", "/", data={})

        handler = MainHandlerTestable()
        handler.init_from_request(request)
        handler.instance = root

        ctx = global_blog_context(handler, request, root)

        res = ctx['all_blogs']
        assert res.count() == 2
        assert set(x.node.slug() for x in res) == set(("b1", "b3"))
Ejemplo n.º 24
0
def super_request():
    r = create_request("GET", "/")
    r.user = superuser()
    return r
Ejemplo n.º 25
0
def auth_request():
    r = create_request("GET", "/")
    r.user = user()
    return r
Ejemplo n.º 26
0
def anon_request():
    return create_request("GET", "/")
Ejemplo n.º 27
0
def superuser_request(_path, method="GET", **data):
    superuser, _ = User.objects.get_or_create(username="******",
                                                   is_superuser=True)
    request = create_request(method, _path, data=data)
    request.user = superuser
    return request
Ejemplo n.º 28
0
 def test_unattached_root(self, client, root):
     request = create_request("GET", "/edit")
     handler = MainHandlerTestable(request=request, instance=root)
     assert handler.breadcrumb() == [("Unattached rootnode", '')]
Ejemplo n.º 29
0
 def test_anon_no_settings(self, client):
     node = Node.root()
     toolbar = Toolbar(node, create_request("GET", "/"), "view")
     assert not toolbar.show_settings()