Exemple #1
0
    def test_get_node(self):
        request = self.factory.get('/')
        request.session = {}

        node1 = nodes.get_node(request)
        self.assertNotEqual(node1, None)

        node2 = nodes.get_node(request)
        self.assertEqual(node1.id, node2.id)
Exemple #2
0
    def test_get_node(self):
        request = self.factory.get('/')
        request.session = {}

        node1 = nodes.get_node(request)
        self.assertNotEqual(node1, None)

        node2 = nodes.get_node(request)
        self.assertEqual(node1.id, node2.id)
Exemple #3
0
    def process_request(self, request):
        outside_url = urlresolvers.reverse('outside')
        request.node = nodes.get_node(request)

        if request.path == outside_url:
            if request.node is None:
                # We do nothing special for outside view if request
                # is from outside and without geolocation data
                return None
            elif settings.DEBUG:
                # We allow access if request is from inside if DEBUG is true
                # (So that we can test the view)
                request.node = None
                return None
            else:
                # Otherwise we redirect to home
                return http.HttpResponseRedirect(urlresolvers.reverse('home'))

        for exception in getattr(settings, 'NODES_MIDDLEWARE_EXCEPTIONS', ()):
            if request.path.startswith(exception):
                return None

        if request.node is None:
            # Outside request and without geolocation data, we redirect
            return http.HttpResponseRedirect(outside_url)
        else:
            # Inside request, or request with geolocation data, we do not do anything
            return None
Exemple #4
0
    def test_bicikelj(self):
        node = next(itertools.islice(nodes.get_all_nodes(), 12, 13))

        self.assertEqual(node.name, 'fri')

        request = self.factory.get('/')
        request.session = {
            nodes.SESSION_KEY: node.id,
            nodes.BACKEND_SESSION_KEY: node.backend.get_full_name(),
        }
        request.node = nodes.get_node(request)

        self.assertEqual(node.id, request.node.id)

        context = template.RequestContext(request)

        data = {}
        on_template_render = functional.curry(client.store_rendered_templates, data)
        signals.template_rendered.connect(on_template_render, dispatch_uid="template-render")

        try:
            panel.BicikeljPanel().render(request, context)
        finally:
            signals.template_rendered.disconnect(dispatch_uid="template-render")

        self.assertEqual(len(data['context']['stations']), 1)
    def test_bicikelj(self):
        node = next(itertools.islice(nodes.get_all_nodes(), 12, 13))

        self.assertEqual(node.name, 'fri')

        request = self.factory.get('/')
        request.session = {
            nodes.SESSION_KEY: node.id,
            nodes.BACKEND_SESSION_KEY: node.backend.get_full_name(),
        }
        request.node = nodes.get_node(request)

        self.assertEqual(node.id, request.node.id)

        context = template.RequestContext(request)

        data = {}

        def store_rendered_templates(signal, sender, template, context, **kwargs):
            for d in context.dicts:
                for e in d.dicts:
                    data.update(e)

        signals.template_rendered.connect(store_rendered_templates, dispatch_uid="template-render")

        try:
            panel.BicikeljPanel().render(request, context)
        finally:
            signals.template_rendered.disconnect(dispatch_uid="template-render")

        self.assertEqual(len(data['stations']), 1)
Exemple #6
0
    def process_request(self, request):
        outside_url = urlresolvers.reverse('outside')
        request.node = nodes.get_node(request)

        if request.path == outside_url:
            if request.node is None:
                # We do nothing special for outside view if request
                # is from outside and without geolocation data
                return None
            elif settings.DEBUG:
                # We allow access if request is from inside if DEBUG is true
                # (So that we can test the view)
                request.node = None
                return None
            else:
                # Otherwise we redirect to home
                return http.HttpResponseRedirect(urlresolvers.reverse('home'))

        for exception in getattr(settings, 'NODES_MIDDLEWARE_EXCEPTIONS', ()):
            if request.path.startswith(exception):
                return None

        if request.node is None:
            # Outside request and without geolocation data, we redirect
            return http.HttpResponseRedirect(outside_url)
        else:
            # Inside request, or request with geolocation data, we do not do anything
            return None