def setUp(self): self.trek = TrekFactory.build() self.trek.name_fr = 'Voie lactee' self.trek.name_en = 'Milky way' self.trek.name_it = 'Via Lattea' self.trek.published_fr = True self.trek.published_it = False self.trek.save()
def test_json_translation(self): trek = TrekFactory.build() trek.name_fr = 'Voie lactee' trek.name_en = 'Milky way' trek.name_it = 'Via Lattea' trek.save() url = reverse('trekking:trek_json_detail', kwargs={'pk': trek.pk}) # Test default case response = self.client.get(url) obj = json.loads(response.content) self.assertEqual(obj['name'], trek.name) # Test with another language response = self.client.get(url, HTTP_ACCEPT_LANGUAGE='it-IT') obj = json.loads(response.content) self.assertEqual(obj['name'], trek.name_it) # Test with yet another language response = self.client.get(url, HTTP_ACCEPT_LANGUAGE='fr-FR') obj = json.loads(response.content) self.assertEqual(obj['name'], trek.name_fr)