def test_mk_entriableadmin(self):
    admincls = CPMAdmin
    make_entrieable_admin(admincls)
    self.assertTrue(admincls.is_menu_entrieable)
    instance = ConcretePublishableLangModel.objects.create(foo='x')
    data = instance.__dict__
    menu = Menu.objects.add_root(title='Menu1')
    admininstance = admincls(model=ConcretePublishableLangModel, admin_site=self.site)
    self.assertTrue(admininstance.get_fields({}, instance), [])
    self.assertTrue(admininstance.get_fieldsets({}, instance), [])
    formcls = admincls.form
    formcls._meta.model = ConcretePublishableLangModel
    form = formcls(instance.__dict__)
    self.assertTrue(('menus' in form.fields.keys()))
    valid = form.is_valid()
    self.assertTrue(valid)
    data['menus'] = [menu.pk]
    form = formcls(data, instance=instance)
    self.assertTrue(('menus' in form.fields.keys()))
    valid = form.is_valid()
    self.assertTrue(valid)
    data['status_changed_0'] = '2016-01-01'
    data['status_changed_1'] = '23:00'
    adminurl = get_adminedit_url(instance)
    response = self.client.post(adminurl, data)
    self.assertIn(response.status_code, (200, 302))
    self.assertEqual(MenuEntry.objects.count(), 2)
    response = self.client.get(adminurl)
    content = str(response.content)
    start = content.find('<input type="checkbox" name="menus"')
    end = content[start:].find('>')
    tag = content[start:((start + end) + 1)]
    self.assertTrue((' checked' in tag))
def test_mk_entriableadmin(self):
    admincls = CPMAdmin
    make_entrieable_admin(admincls)
    self.assertTrue(admincls.is_menu_entrieable)
    instance = ConcretePublishableLangModel.objects.create(foo='x')
    data = instance.__dict__
    menu = Menu.objects.add_root(title='Menu1')
    admininstance = admincls(model=ConcretePublishableLangModel, admin_site=self.site)
    self.assertTrue(admininstance.get_fields({}, instance), [])
    self.assertTrue(admininstance.get_fieldsets({}, instance), [])
    formcls = admincls.form
    formcls._meta.model = ConcretePublishableLangModel
    form = formcls(instance.__dict__)
    self.assertTrue(('menus' in form.fields.keys()))
    valid = form.is_valid()
    self.assertTrue(valid)
    data['menus'] = [menu.pk]
    form = formcls(data, instance=instance)
    self.assertTrue(('menus' in form.fields.keys()))
    valid = form.is_valid()
    self.assertTrue(valid)
    data['status_changed_0'] = '2016-01-01'
    data['status_changed_1'] = '23:00'
    adminurl = get_adminedit_url(instance)
    response = self.client.post(adminurl, data)
    self.assertIn(response.status_code, (200, 302))
    self.assertEqual(MenuEntry.objects.count(), 2)
    response = self.client.get(adminurl)
    content = str(response.content)
    start = content.find('<input type="checkbox" name="menus"')
    end = content[start:].find('>')
    tag = content[start:((start + end) + 1)]
    self.assertTrue((' checked' in tag))