def test_create(self):
        # Login should be required
        r = self.client.get(reverse('badger.views.create'))
        eq_(302, r.status_code)
        ok_('/accounts/login' in r['Location'])

        # Should be fine after login
        settings.BADGER_ALLOW_ADD_BY_ANYONE = True
        self.client.login(username="tester", password="trustno1")
        r = self.client.get(reverse('badger.views.create'))
        eq_(200, r.status_code)

        # Make a chick check for expected form elements
        doc = pq(r.content)

        form = doc('form#create_badge')
        eq_(1, form.length)

        eq_(1, form.find('input[name=title]').length)
        eq_(1, form.find('textarea[name=description]').length)
        # For styling purposes, we'll allow either an input or button element
        eq_(1, form.find('input.submit,button.submit').length)

        r = self.client.post(reverse('badger.views.create'), dict(
        ), follow=True)
        doc = pq(r.content)
        eq_(1, doc.find('form .error > input[name=title]').length)

        badge_title = "Test badge #1"
        badge_desc = "This is a test badge"

        r = self.client.post(reverse('badger.views.create'), dict(
            title=badge_title,
            description=badge_desc,
        ), follow=True)
        doc = pq(r.content)

        eq_('badge_detail', doc.find('body').attr('id'))
        ok_(badge_title in doc.find('.badge .title').text())
        eq_(badge_desc, doc.find('.badge .description').text())

        slug = doc.find('.badge').attr('data-slug')

        badge = Badge.objects.get(slug=slug)
        eq_(badge_title, badge.title)
        eq_(badge_desc, badge.description)
Can create badge with form
dataset/ETHPy150Open mozilla/django-badger/badger/tests/test_views.py/BadgerViewsTest.test_create