vendredi 21 août 2015

Unittest problems when started using i18n

I write some simple unittests. Tests succeeded without internationalization. Sample of one of them:

def test_brands(self):
    response = self.client.get(reverse('core:brands'))
    self.assertEqual(response.status_code, 200)
    self.assertTemplateUsed(response, 'brands.html')
    self.assertTrue('brands' in response.context)

As long as I start using i18n, then response.status_code equals to 404. When I replace reverse('core:brands') with its value ('/brands'/), then response.status_code equeals to 302. As I understand, it happens because it redirects to the url prefixed with current language. But in this case next asserts are false:

self.assertTemplateUsed(response, 'brands.html')
self.assertTrue('brands' in response.context)

because my get request doesn't render a template, but just redirect to url. How to resolve it?

Aucun commentaire:

Enregistrer un commentaire