Exemplo n.º 1
0
def test_formregistry_ready_dict():
    fr = FormRegistry(name='default')
    newconfig = {
        'HELLO': ['test_app.forms.DatetimeForm', {'blip': 'blop'}],
        'HELLO2': {
            'int': 1,
            'email': '*****@*****.**',
            'url': 'https://news.bbc.co.uk/',
        },
    }
    with override_settings(STAGESETTINGS=newconfig):
        with patch_logger('stagesetting.utils', 'info') as logger_calls:
            result = fr.ready(sender=None, instance=None, model=RuntimeSetting)
        # implicit = RuntimeSetting.objects.get(key='HELLO2')
        # assert fr.deserialize(implicit.raw_value) == {
        #     'email': '*****@*****.**',
        #     'int': 1,
        #     'url': 'https://news.bbc.co.uk/'
        # }
        assert fr._get_default(key='HELLO2') == {
            "email": "*****@*****.**",
            "int": 1,
            "url": "https://news.bbc.co.uk/"
        }
    # assert len(result) == 2
    assert logger_calls == ['HELLO2 config is a dictionary, assuming it '
                            'represents both the form and default values']
Exemplo n.º 2
0
def test_formregistry_complex_dict_with_completely_different_defaults():
    fr = FormRegistry(name='default')
    def user(): return get_user_model()(pk=2)
    def user_qs(): return get_user_model().objects.all()
    newconfig = {
        'COMPLEX_NO_DEFAULTS': [{
            'model': user,
            'queryset': user_qs,
        }, {
            'model': 'ohgod',
            'wat': 'not-even-a-thing',  # this won't turn up ever, hopefully.
            'queryset': [11, 2],
        }]
    }
    with override_settings(STAGESETTINGS=newconfig):
        result = fr.ready(sender=None, instance=None, model=RuntimeSetting)
        # implicit = RuntimeSetting.objects.get(key='COMPLEX_NO_DEFAULTS')
        # assert fr.deserialize(implicit.raw_value) == {
        #     'model': 'ohgod',
        #     'queryset': [11, 2],
        # }
        assert fr._get_default(key='COMPLEX_NO_DEFAULTS') == {
            'model': 'ohgod',
            'queryset': [11, 2],
        }
Exemplo n.º 3
0
def test_formregistry_ready_dict_with_partial_defaults():
    fr = FormRegistry(name='default')
    newconfig = {
        'HELLO4': [{
            'int': 1,
            'email': '*****@*****.**',
            'url': 'https://news.bbc.co.uk/',
        }, {
            'int': 12,
            'url': 'https://www.bbc.com/',
        }],
    }
    with override_settings(STAGESETTINGS=newconfig):
        result = fr.ready(sender=None, instance=None, model=RuntimeSetting)
        # implicit = RuntimeSetting.objects.get(key='HELLO4')
        # assert fr.deserialize(implicit.raw_value) == {
        #     'email': '*****@*****.**',
        #     'int': 12,
        #     'url': 'https://www.bbc.com/'
        # }
        assert fr._get_default(key='HELLO4') == {
            "email": "*****@*****.**",
            "int": 12,
            "url": "https://www.bbc.com/"
        }
Exemplo n.º 4
0
def formregistry_ready():
    fr = FormRegistry(name='default')
    newconfig = {
        'HELLO': ['test_app.forms.DatetimeForm', {'blip': 'blop'}],
        'HELLO2': ['test_app.forms.ListPerPageForm'],
    }
    with override_settings(STAGESETTINGS=newconfig):
        return fr.ready(sender=None, instance=None, model=RuntimeSetting)
Exemplo n.º 5
0
def test_formregistry_complex_dict_with_no_defaults():
    fr = FormRegistry(name='default')
    def user(): return get_user_model()(pk=2)
    def user_qs(): return get_user_model().objects.all()
    newconfig = {
        'COMPLEX_NO_DEFAULTS': {
            'model': user,
            'queryset': user_qs,
        },
    }
    with override_settings(STAGESETTINGS=newconfig):
        result = fr.ready(sender=None, instance=None, model=RuntimeSetting)
        # implicit = RuntimeSetting.objects.get(key='COMPLEX_NO_DEFAULTS')
        # assert fr.deserialize(implicit.raw_value) == {
        #     'model': '2',
        #     'queryset': []
        # }
        assert fr._get_default(key='COMPLEX_NO_DEFAULTS') == {
            'model': user,
            'queryset': user_qs,
        }