Reverse не работает с kwargs во время работы в другой функции - почему?

    def test_no_errors_direct_flights_rendered_in_template(self):
        request = HttpRequest()
        response = render(request,'app1/flight-search-result.html', {
            'direct_flights': [
                {
---- not relevant
            })
        self.assertContains(response, 'Direct connection')
        self.assertNotContains(response, 'No options for your search')
        self.assertNotContains(response, 'One change')
        # this assertContains will ensure that the searched word is not in the form - we don't pass
        # the form to the render function above
        self.assertContains(response, 'Venice Airport Marco Polo')
        self.assertContains(response, 'Dubai International Airport')
        # you can add more once you change the template
        url = reverse('app1:flight-search-detail-passenger-form', kwargs={'to_first': "VCEDXB2201040"}) ---- works!
        self.assertContains(response, '<a href="{}">'.format(url))

    def test_no_errors_indirect_flights_rendered_in_template(self):
        request = HttpRequest()
        response = render(request, 'app1/flight-search-detail-passenger-form.html', {
            'indirect_flights': [
                { ----- not relevant
                        {
                       }
                    ]
                 }
            ]
        })
        self.assertContains(response, 'One change')
        self.assertNotContains(response, 'No options for your search')
        self.assertNotContains(response, 'Direct flight')
        # you can add more once you change the template
        kwargs = {'to_first': "VCEDXB2201040"}
        _url = reverse('app1:flight-search-detail-passenger-form', kwargs=kwargs)------- doesn't work!
        self.assertContains(response, '<a href="{}">'.format(_url))

Очень странная проблема, но первый реверс работает отлично, а второй выбрасывает следующую ошибку:

django.urls.exceptions.NoReverseMatch: Reverse for 'flight-search-detail-passenger-form' with arguments '('',)' not found. 2 pattern(s) tried: ['flights/detail/passenger/to=(?P<to_first>[
A-Z0-9]{13})&(?P<to_second>[A-Z0-9]{13})$', 'flights/detail/passenger/to=(?P<to_first>[A-Z0-9]{13})$']

Сталкивался ли кто-нибудь с этим раньше? Как ее можно решить?

Вернуться на верх