Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail on new project - can't reverse "javascript-catalog" - have proposed fix #92

Closed
mcscope opened this issue Aug 6, 2019 · 5 comments

Comments

@mcscope
Copy link

mcscope commented Aug 6, 2019

edit: I have a proposed fix to this - see my final comment

Following the setup guide on a first install, I'm getting test failures.
I did the cookiecutter fetch step, then make install then make tests - I believe I have all relevant dependencies and no errors on the first two steps before make test. I have both python 3.7 and python 2.7 installed, looks like this is using 3.7, it's in all the paths.

E django.urls.exceptions.NoReverseMatch: Reverse for 'javascript-catalog' not found. 'javascript-catalog' is not a valid view function or pattern name.
There are 32 failures
================== 32 failed, 156 passed, 70 warnings in 105.55 seconds ===================

Here's one of the failing tests in its entirety

tests/mapideas/views/test_mapidea_update.py:126:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.7/site-packages/django/test/client.py:543: in post
    response = super().post(path, data=data, content_type=content_type, secure=secure, **extra)
venv/lib/python3.7/site-packages/django/test/client.py:357: in post
    secure=secure, **extra)
venv/lib/python3.7/site-packages/django/test/client.py:422: in generic
    return self.request(**r)
venv/lib/python3.7/site-packages/django/test/client.py:485: in request
    response = self.handler(environ)
venv/lib/python3.7/site-packages/django/test/client.py:140: in __call__
    response = self.get_response(request)
venv/lib/python3.7/site-packages/django/core/handlers/base.py:75: in get_response
    response = self._middleware_chain(request)
venv/lib/python3.7/site-packages/django/core/handlers/exception.py:36: in inner
    response = response_for_exception(request, exc)
venv/lib/python3.7/site-packages/django/core/handlers/exception.py:90: in response_for_exception
    response = handle_uncaught_exception(request, get_resolver(get_urlconf()), sys.exc_info())
venv/lib/python3.7/site-packages/django/core/handlers/exception.py:129: in handle_uncaught_exception
    return callback(request, **param_dict)
venv/lib/python3.7/site-packages/django/utils/decorators.py:142: in _wrapped_view
    response = view_func(request, *args, **kwargs)
venv/lib/python3.7/site-packages/django/views/defaults.py:80: in server_error
    return HttpResponseServerError(template.render())
venv/lib/python3.7/site-packages/django/template/backends/django.py:61: in render
    return self.template.render(context)
venv/lib/python3.7/site-packages/django/template/base.py:171: in render
    return self._render(context)
venv/lib/python3.7/site-packages/django/test/utils.py:96: in instrumented_test_render
    return self.nodelist.render(context)
venv/lib/python3.7/site-packages/django/template/base.py:937: in render
    bit = node.render_annotated(context)
venv/lib/python3.7/site-packages/django/template/base.py:904: in render_annotated
    return self.render(context)
venv/lib/python3.7/site-packages/django/template/loader_tags.py:150: in render
    return compiled_parent._render(context)
venv/lib/python3.7/site-packages/django/test/utils.py:96: in instrumented_test_render
    return self.nodelist.render(context)
venv/lib/python3.7/site-packages/django/template/base.py:937: in render
    bit = node.render_annotated(context)
venv/lib/python3.7/site-packages/django/template/base.py:904: in render_annotated
    return self.render(context)
venv/lib/python3.7/site-packages/django/template/loader_tags.py:150: in render
    return compiled_parent._render(context)
venv/lib/python3.7/site-packages/django/test/utils.py:96: in instrumented_test_render
    return self.nodelist.render(context)
venv/lib/python3.7/site-packages/django/template/base.py:937: in render
    bit = node.render_annotated(context)
venv/lib/python3.7/site-packages/django/template/base.py:904: in render_annotated
    return self.render(context)
venv/lib/python3.7/site-packages/django/template/defaulttags.py:443: in render
    url = reverse(view_name, args=args, kwargs=kwargs, current_app=current_app)
venv/lib/python3.7/site-packages/django/urls/base.py:90: in reverse
    return iri_to_uri(resolver._reverse_with_prefix(view, prefix, *args, **kwargs))
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

self = <URLResolver 'movie_night.urls' (None:None) '^/'>
lookup_view = 'javascript-catalog', _prefix = '/', args = (), kwargs = {}
possibilities = []

    def _reverse_with_prefix(self, lookup_view, _prefix, *args, **kwargs):
        if args and kwargs:
            raise ValueError("Don't mix *args and **kwargs in call to reverse()!")

        if not self._populated:
            self._populate()

        possibilities = self.reverse_dict.getlist(lookup_view)

        for possibility, pattern, defaults, converters in possibilities:
            for result, params in possibility:
                if args:
                    if len(args) != len(params):
                        continue
                    candidate_subs = dict(zip(params, args))
                else:
                    if set(kwargs).symmetric_difference(params).difference(defaults):
                        continue
                    if any(kwargs.get(k, v) != v for k, v in defaults.items()):
                        continue
                    candidate_subs = kwargs
                # Convert the candidate subs to text using Converter.to_url().
                text_candidate_subs = {}
                for k, v in candidate_subs.items():
                    if k in converters:
                        text_candidate_subs[k] = converters[k].to_url(v)
                    else:
                        text_candidate_subs[k] = str(v)
                # WSGI provides decoded URLs, without %xx escapes, and the URL
                # resolver operates on such URLs. First substitute arguments
                # without quoting to build a decoded URL and look for a match.
                # Then, if we have a match, redo the substitution with quoted
                # arguments in order to return a properly encoded URL.
                candidate_pat = _prefix.replace('%', '%%') + result
                if re.search('^%s%s' % (re.escape(_prefix), pattern), candidate_pat % text_candidate_subs):
                    # safe characters from `pchar` definition of RFC 3986
                    url = quote(candidate_pat % text_candidate_subs, safe=RFC3986_SUBDELIMS + '/~:@')
                    # Don't allow construction of scheme relative urls.
                    return escape_leading_slashes(url)
        # lookup_view can be URL name or callable, but callables are not
        # friendly in error messages.
        m = getattr(lookup_view, '__module__', None)
        n = getattr(lookup_view, '__name__', None)
        if m is not None and n is not None:
            lookup_view_s = "%s.%s" % (m, n)
        else:
            lookup_view_s = lookup_view

        patterns = [pattern for (_, pattern, _, _) in possibilities]
        if patterns:
            if args:
                arg_msg = "arguments '%s'" % (args,)
            elif kwargs:
                arg_msg = "keyword arguments '%s'" % (kwargs,)
            else:
                arg_msg = "no arguments"
            msg = (
                "Reverse for '%s' with %s not found. %d pattern(s) tried: %s" %
                (lookup_view_s, arg_msg, len(patterns), patterns)
            )
        else:
            msg = (
                "Reverse for '%(view)s' not found. '%(view)s' is not "
                "a valid view function or pattern name." % {'view': lookup_view_s}
            )
>       raise NoReverseMatch(msg)
E       django.urls.exceptions.NoReverseMatch: Reverse for 'javascript-catalog' not found. 'javascript-catalog' is not a valid view function or pattern name.

venv/lib/python3.7/site-packages/django/urls/resolvers.py:668: NoReverseMatch

Here are the only references to javascript catalog in the folder -

venv/lib/python3.7/site-packages/treebeard/admin.py
73:            from django.views.i18n import javascript_catalog
74:            jsi18n_url = url(r'^jsi18n/$', javascript_catalog, {'packages': ('treebeard',)})```
@mcscope
Copy link
Author

mcscope commented Aug 6, 2019

This error also prevents the server from rendering on 8000 base
image

@mcscope
Copy link
Author

mcscope commented Aug 6, 2019

Django version 2.2.3.0, javascript_catalog does exist if I import it from django within the virtualenv. I'm a python dev but not a django dev so I'm not great at debugging this

>> from django.views.i18n import JavaScriptCatalog
>>> JavaScriptCatalog(
... )
<django.views.i18n.JavaScriptCatalog object at 0x1025dc198>
>>> django.VERSION
(2, 2, 3, 'final', 0)

@mcscope
Copy link
Author

mcscope commented Aug 6, 2019

I suspect the problem is something related to this line in the recent django update patch - https://github.com/liqd/a4-cookiecutter/pull/90/files#diff-521ab0577f937972db3f4fa5f0c0ec06L74

@mcscope
Copy link
Author

mcscope commented Aug 6, 2019

If I replace line 74 in urls.py with

    url(r'^jsi18n/$', JavaScriptCatalog.as_view(**js_info_dict), name='javascript-catalog'),

Then the tests pass and the page renders.

I'd make a pull request with that 'fix' but I'm too new to this project and django to understand the implications of this.
I found it from this documentation example.
https://docs.djangoproject.com/en/2.2/topics/i18n/translation/#module-django.views.i18n

Even with this line though, the page looks weird- like broken JS, so this may not be the full answer.
image

@mcscope mcscope changed the title Tests fail on new project - can't reverse "javascript-catalog" Tests fail on new project - can't reverse "javascript-catalog" - have proposed fix Aug 6, 2019
@MagdaN
Copy link
Contributor

MagdaN commented Aug 7, 2019

@mcscope thanks a lot for the issue and also for the solution. It is fixed.

@MagdaN MagdaN closed this as completed Aug 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants