Skip to content

Commit

Permalink
Simplify admin id test and remove obsolete references do module_name. F…
Browse files Browse the repository at this point in the history
…ixes #324.
  • Loading branch information
spectras committed Jan 28, 2017
1 parent 77ffd92 commit 017c311
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 55 deletions.
4 changes: 2 additions & 2 deletions hvad/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ def get_urls(self):
from django.conf.urls import url
urlpatterns = super(InlineModelAdmin, self).get_urls()

info = self.model._meta.app_label, self.model._meta.module_name
info = self.model._meta.app_label, self.model._meta.model_name

return [
url(r'^(.+)/delete-translation/(.+)/$',
Expand Down Expand Up @@ -507,7 +507,7 @@ def delete_translation(self, request, object_id, language_code):
if not self.has_change_permission(request, None):
return HttpResponseRedirect(reverse('admin:index'))
return HttpResponseRedirect(reverse('admin:%s_%s_changelist' % (opts.app_label, opts.module_name)))
return HttpResponseRedirect(reverse('admin:%s_%s_changelist' % (opts.app_label, opts.model_name)))
object_name = '%s Translation' % force_text(opts.verbose_name)
Expand Down
73 changes: 20 additions & 53 deletions hvad/tests/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -569,6 +569,25 @@ class Meta:
class AdminRelationTests(HvadTestCase, BaseAdminTests, UsersFixture, NormalFixture):
normal_count = 1

def create_fixtures(self):
super(AdminRelationTests, self).create_fixtures()
self.simple = SimpleRelated.objects.language('en').create(
normal_id=self.normal_id[1], translated_field='English inline'
)
self.simple.translated_fields.create(language_code='fr', translated_field='French inline')
self.simple.translated_fields.create(language_code='da', translated_field='Danish inline')

def test_correct_id_in_inline(self):
with translation.override('da'):
instance = SimpleRelated.objects.get(pk=self.simple.pk)
class ExampleInlineForm(InlineModelForm):
class Meta:
model = SimpleRelated
exclude = []
form = ExampleInlineForm(instance=instance)

self.assertTrue(form.initial["id"] == instance.id)

def test_adding_related_object(self):
url = reverse('admin:app_simplerelated_add')
TRANS_FIELD = "English Content"
Expand All @@ -582,60 +601,8 @@ def test_adding_related_object(self):
}
response = self.client.post(url, data)

simplerel = SimpleRelated.objects.all()[0]
simplerel = SimpleRelated.objects.language().get(translated_field=TRANS_FIELD)
self.assertEqual(simplerel.normal.pk, en.pk)
self.assertEqual(simplerel.translated_field, TRANS_FIELD)

expected_url = reverse('admin:app_simplerelated_change', args=(simplerel.pk,))
self.assertRedirects(response, expected_url)


class TranslatableInlineAdminTests(HvadTestCase, BaseAdminTests, UsersFixture):
def test_correct_id_in_inline(self):
LANGUAGES = (
('en', u'English'),
('fr', u'Français'),
('da', u'Dansk'),
('ja', u'日本語'),
)
with self.settings(LANGUAGES=LANGUAGES):
with translation.override('en'):
normal = Normal.objects.language().create(
shared_field="whatever1",
translated_field="whatever in another language1"
)
normal2 = Normal.objects.language().create(
shared_field="whatever2",
translated_field="whatever in another language2"
)
normal3 = Normal.objects.language().create(
shared_field="whatever3",
translated_field="whatever in another language3"
)

simple1 = SimpleRelated.objects.language("en").create(
normal=normal3, translated_field="inline whatever translated"
)

simple1.translate("ja")
simple1.translated_field ="japanese stuff"
simple1.save()

simple1.translate("fr")
simple1.translated_field ="french stuff"
simple1.save()

simple1.translate("da")
simple1.translated_field ="danish stuff"
simple1.save()


with translation.override('da'):
instance = SimpleRelated.objects.get(pk=simple1.pk)
class ExampleInlineForm(InlineModelForm):
class Meta:
model = SimpleRelated
exclude = []
form = ExampleInlineForm(instance=instance)

self.assertTrue(form.initial["id"] == instance.id)

0 comments on commit 017c311

Please sign in to comment.