Exemple #1
0
 def setUp(self):
     super(TestAppDataForms, self).setUp()
     MyAppContainer = AppDataContainer.from_form(self.MyForm)
     app_registry.register('myapp', MyAppContainer)
     self.data = {'title': 'First!', 'publish_from': '2010-10-1'}
     MyOtherContainer = AppDataContainer.from_form(self.MyOtherForm)
     app_registry.register('myotherapp', MyOtherContainer)
 def test_registered_classes_can_be_set_as_attrs(self):
     app_registry.register('dummy', DummyAppDataContainer)
     art = Article()
     art.app_data.dummy = {'answer': 42}
     assert isinstance(art.app_data.dummy, DummyAppDataContainer)
     assert art.app_data.dummy == DummyAppDataContainer(art, {'answer': 42})
     assert art.app_data == {'dummy': {'answer': 42}}
Exemple #3
0
 def test_registered_classes_can_be_set_as_attrs(self):
     app_registry.register('dummy', DummyAppDataContainer)
     art = Article()
     art.app_data.dummy = {'answer': 42}
     tools.assert_true(isinstance(art.app_data.dummy, DummyAppDataContainer))
     tools.assert_equals(DummyAppDataContainer(art, {'answer': 42}), art.app_data.dummy)
     tools.assert_equals({'dummy': {'answer': 42}}, art.app_data)
Exemple #4
0
 def test_override_class_for_model_only(self):
     app_registry.register('dummy', DummyAppDataContainer)
     app_registry.register('dummy',
                           DummyAppDataContainer2,
                           model=Publishable)
     inst = Publishable()
     tools.assert_true(
         isinstance(inst.app_data.get('dummy', {}), DummyAppDataContainer2))
 def setUp(self):
     super(TestAppDataForms, self).setUp()
     MyAppContainer = AppDataContainer.from_form(self.MyForm)
     app_registry.register('myapp', MyAppContainer)
     self.data = {
         'title': 'First!',
         'publish_from': '2010-10-1'
     }
Exemple #6
0
    def test_container_from_form(self):
        class MyForm(AppDataForm):
            publish_from = forms.DateField()
        MyAppContainer = AppDataContainer.from_form(MyForm)
        app_registry.register('myapp', MyAppContainer)

        art = Article()
        tools.assert_true(isinstance(art.app_data['myapp'], MyAppContainer))
Exemple #7
0
    def setUp(self):
        super(TestSerialization, self).setUp()

        MyAppContainer = AppDataContainer.from_form(self.MyForm)
        app_registry.register('myapp', MyAppContainer)
        self.article = Article()
        self.article.app_data.myapp.publish_from = date(2012, 8, 26)
        self.article.save()
Exemple #8
0
    def setUp(self):
        super(TestSerialization, self).setUp()

        MyAppContainer = AppDataContainer.from_form(self.MyForm)
        app_registry.register('myapp', MyAppContainer)
        self.article = Article()
        self.article.app_data.myapp.publish_from = date(2012, 8, 26)
        self.article.save()
Exemple #9
0
 def test_registered_classes_can_be_set_as_attrs(self):
     app_registry.register('dummy', DummyAppDataContainer)
     art = Article()
     art.app_data.dummy = {'answer': 42}
     tools.assert_true(isinstance(art.app_data.dummy,
                                  DummyAppDataContainer))
     tools.assert_equals(DummyAppDataContainer(art, {'answer': 42}),
                         art.app_data.dummy)
     tools.assert_equals({'dummy': {'answer': 42}}, art.app_data)
Exemple #10
0
    def test_get_fallback_value(self):
        class MyForm(AppDataForm):
            title = forms.CharField(max_length=25, initial='Hullo!')
        MyAppContainer = AppDataContainer.from_form(MyForm)
        app_registry.register('myapp', MyAppContainer)

        art = Article()
        tools.assert_equals(None, art.app_data.myapp.get('foo'))
        tools.assert_equals('bar', art.app_data.myapp.get('foo', 'bar'))
Exemple #11
0
    def test_initial_get_used_as_default(self):
        class MyForm(AppDataForm):
            title = forms.CharField(max_length=25, initial='Hullo!')
        MyAppContainer = AppDataContainer.from_form(MyForm)
        app_registry.register('myapp', MyAppContainer)

        art = Article()
        tools.assert_true(isinstance(art.app_data['myapp'], MyAppContainer))
        tools.assert_equals('Hullo!', art.app_data.myapp.get('title'))
Exemple #12
0
    def test_container_from_form(self):
        class MyForm(AppDataForm):
            publish_from = forms.DateField()

        MyAppContainer = AppDataContainer.from_form(MyForm)
        app_registry.register('myapp', MyAppContainer)

        art = Article()
        tools.assert_true(isinstance(art.app_data['myapp'], MyAppContainer))
Exemple #13
0
    def test_get_fallback_value(self):
        class MyForm(AppDataForm):
            title = forms.CharField(max_length=25, initial='Hullo!')

        MyAppContainer = AppDataContainer.from_form(MyForm)
        app_registry.register('myapp', MyAppContainer)

        art = Article()
        tools.assert_equals(None, art.app_data.myapp.get('foo'))
        tools.assert_equals('bar', art.app_data.myapp.get('foo', 'bar'))
Exemple #14
0
    def test_initial_get_used_as_default(self):
        class MyForm(AppDataForm):
            title = forms.CharField(max_length=25, initial='Hullo!')

        MyAppContainer = AppDataContainer.from_form(MyForm)
        app_registry.register('myapp', MyAppContainer)

        art = Article()
        tools.assert_true(isinstance(art.app_data['myapp'], MyAppContainer))
        tools.assert_equals('Hullo!', art.app_data.myapp.get('title'))
Exemple #15
0
    def test_get_semantics_for_getitem(self):
        class MyForm(AppDataForm):
            title = forms.CharField(max_length=25, initial='Hullo!')
            description = forms.CharField(max_length=25, required=False)
        MyAppContainer = AppDataContainer.from_form(MyForm)
        app_registry.register('myapp', MyAppContainer)

        art = Article()
        tools.assert_equals('Hullo!', art.app_data.myapp.title)
        # empty initial value falls back to field's type
        tools.assert_equals('', art.app_data.myapp.description)
Exemple #16
0
    def test_get_semantics_for_getitem(self):
        class MyForm(AppDataForm):
            title = forms.CharField(max_length=25, initial='Hullo!')
            description = forms.CharField(max_length=25, required=False)

        MyAppContainer = AppDataContainer.from_form(MyForm)
        app_registry.register('myapp', MyAppContainer)

        art = Article()
        tools.assert_equals('Hullo!', art.app_data.myapp.title)
        # empty initial value falls back to field's type
        tools.assert_equals('', art.app_data.myapp.description)
Exemple #17
0
 def test_unregistered_namespace_cannot_be_unregistered(self):
     app_registry.register('dummy', DummyAppDataContainer)
     app_registry.unregister('dummy')
     app_registry.unregister('dummy')
Exemple #18
0
 def test_namespace_can_only_be_registered_once(self):
     app_registry.register('dummy', DummyAppDataContainer)
     app_registry.register('dummy', DummyAppDataContainer2)
Exemple #19
0
 def test_registered_classes_get_stored_on_access(self):
     app_registry.register('dummy', DummyAppDataContainer)
     art = Article()
     art.app_data['dummy']
     tools.assert_equals({'dummy': {}}, art.app_data)
Exemple #20
0
 def test_namespace_can_only_be_registered_once(self):
     app_registry.register('dummy', DummyAppDataContainer)
     app_registry.register('dummy', DummyAppDataContainer2)
Exemple #21
0
 def test_existing_values_get_wrapped_in_proper_class(self):
     app_registry.register('dummy', DummyAppDataContainer)
     inst = Publishable()
     inst.app_data = {'dummy': {'hullo': 'there'}}
     tools.assert_true(isinstance(inst.app_data['dummy'], DummyAppDataContainer))
Exemple #22
0
 def test_registered_classes_can_behave_as_attrs(self):
     app_registry.register('dummy', DummyAppDataContainer)
     art = Article()
     tools.assert_true(isinstance(art.app_data.dummy,
                                  DummyAppDataContainer))
Exemple #23
0
 def test_get_app_data_returns_registered_class_instance(self):
     app_registry.register('dummy', DummyAppDataContainer)
     inst = Publishable()
     tools.assert_true(
         isinstance(inst.app_data.get('dummy', {}), DummyAppDataContainer))
Exemple #24
0
 def test_override_class_for_model_only(self):
     app_registry.register('dummy', DummyAppDataContainer)
     app_registry.register('dummy', DummyAppDataContainer2, model=Publishable)
     inst = Publishable()
     tools.assert_true(isinstance(inst.app_data.get('dummy', {}), DummyAppDataContainer2))
Exemple #25
0
 def test_unregistered_namespace_cannot_be_unregistered(self):
     app_registry.register('dummy', DummyAppDataContainer)
     app_registry.unregister('dummy')
     app_registry.unregister('dummy')
Exemple #26
0
 def test_get_app_data_returns_registered_class_instance(self):
     app_registry.register('dummy', DummyAppDataContainer)
     inst = Publishable()
     tools.assert_true(isinstance(inst.app_data.get('dummy', {}), DummyAppDataContainer))
 def setUp(self):
     super(TestMultiForm, self).setUp()
     MyAppContainer = AppDataContainer.from_form(self.MyForm)
     app_registry.register('myapp', MyAppContainer)
     app_registry.register('myapp2', AppDataContainer.from_form(self.MyForm2))
Exemple #28
0
 def test_registered_classes_get_stored_on_access(self):
     app_registry.register('dummy', DummyAppDataContainer)
     art = Article()
     art.app_data['dummy']
     tools.assert_equals({'dummy': {}}, art.app_data)
Exemple #29
0
 def test_registered_classes_can_behave_as_attrs(self):
     app_registry.register('dummy', DummyAppDataContainer)
     art = Article()
     tools.assert_true(isinstance(art.app_data.dummy, DummyAppDataContainer))
 def test_namespace_can_only_be_registered_once(self):
     with pytest.raises(NamespaceConflict):
         app_registry.register('dummy', DummyAppDataContainer)
         app_registry.register('dummy', DummyAppDataContainer2)
Exemple #31
0
 def test_existing_values_get_wrapped_in_proper_class(self):
     app_registry.register('dummy', DummyAppDataContainer)
     inst = Publishable()
     inst.app_data = {'dummy': {'hullo': 'there'}}
     tools.assert_true(
         isinstance(inst.app_data['dummy'], DummyAppDataContainer))
Exemple #32
0
 def setUp(self):
     super(TestMultiForm, self).setUp()
     MyAppContainer = AppDataContainer.from_form(self.MyForm)
     app_registry.register('myapp', MyAppContainer)
     app_registry.register('myapp2',
                           AppDataContainer.from_form(self.MyForm2))
 def test_unregistered_namespace_cannot_be_unregistered(self):
     with pytest.raises(NamespaceMissing):
         app_registry.register('dummy', DummyAppDataContainer)
         app_registry.unregister('dummy')
         app_registry.unregister('dummy')