Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(12)  |  Call(10)  |  Derive(0)  |  Import(2)

src/d/j/dj.choices-0.9.2/src/dj/choices/tests.py   dj.choices(Download)
    def test_form_with_choicefields(self):
        from dj._choicestestproject.app.models import Favourites, Color,\
                MusicGenre, Sports
        from dj._choicestestproject.app.forms import FavouritesForm
        empty_form = FavouritesForm()
        self.assertEqual(empty_form._bound_value('name'), None)
        self.assertEqual(empty_form._bound_value('nullable'), None)
        empty_form_data = FavouritesForm(data={
                'color': 1, 'music': 2, 'sport': 3, 'name': 'Richard'})
        self.assertTrue(empty_form_data.is_valid())
        self.assertEqual(empty_form_data._bound_value('nullable'), None)
        judy = Favourites.create(name='Judy')
        judy_form = FavouritesForm(instance=judy)
        self.assertFalse(judy_form.is_valid()) # because it's not bound
        self.assertEqual(judy_form._bound_value('color'), Color.green.id)
        data_for_form = dict(judy_form.initial)
        data_for_form.update({'nullable': Color.red})
        judy_form_data = FavouritesForm(instance=judy, data=data_for_form)
        self.assertTrue(judy_form_data.is_valid())
        self.assertEqual(judy_form_data._bound_value('color'), Color.green.id)

src/d/j/dj.choices-HEAD/src/dj/choices/tests.py   dj.choices(Download)
    def test_form_with_choicefields(self):
        from dj._choicestestproject.app.models import Favourites, Color,\
                MusicGenre, Sports
        from dj._choicestestproject.app.forms import FavouritesForm
        empty_form = FavouritesForm()
        self.assertEqual(empty_form._bound_value('name'), None)
        self.assertEqual(empty_form._bound_value('nullable'), None)
        empty_form_data = FavouritesForm(data={
                'color': 1, 'music': 2, 'sport': 3, 'name': 'Richard'})
        self.assertTrue(empty_form_data.is_valid())
        self.assertEqual(empty_form_data._bound_value('nullable'), None)
        judy = Favourites.create(name='Judy')
        judy_form = FavouritesForm(instance=judy)
        self.assertFalse(judy_form.is_valid()) # because it's not bound
        self.assertEqual(judy_form._bound_value('color'), Color.green.id)
        data_for_form = dict(judy_form.initial)
        data_for_form.update({'nullable': Color.red})
        judy_form_data = FavouritesForm(instance=judy, data=data_for_form)
        self.assertTrue(judy_form_data.is_valid())
        self.assertEqual(judy_form_data._bound_value('color'), Color.green.id)