コード例 #1
0
def test_delete_restores_default():
    test_value = {'testing': 1, 'count': 2}
    value = RuntimeSetting(key="TEST", raw_value=json.dumps(test_value))
    value.save()
    db_obj = value.__class__.objects.get(key='TEST')
    with form('TEST'):
        assert db_obj.value == {'count': 2}
        value.delete()
        db_obj2 = value.__class__.objects.get(key='TEST')
        assert db_obj2.raw_value == '{"amdefault": null}'
        assert db_obj2.value == {}
コード例 #2
0
def test_api_get_single(api_client):
    test_value = {'testing': 1, 'count': 4}
    setting = RuntimeSetting(key="TEST2")
    with form('TEST2'):
        setting.value = test_value
    setting.save()
    url = reverse('runtimesetting-detail', args=(setting.pk,))
    with form('TEST2'):
        response = api_client.get(url)
    assert response.data == {
        'value': {'count': 4},
        'key': 'TEST2'
    }
コード例 #3
0
def test_api_getlist(api_client):
    test_value = {'testing': 1, 'count': 2}
    setting = RuntimeSetting(key="TEST")
    with form('TEST'):
        setting.value = test_value
    setting.save()
    url = reverse('runtimesetting-list')
    with form('TEST'):
        response = api_client.get(url)
    assert response.data == [
        OrderedDict(
            [('key', 'TEST'), 
             ('value', {'count': 2})]
        )
    ]
コード例 #4
0
def test_api_put_does_update(api_client):
    initial_value = {
        'key': 'TEST4',
        'value': {'testing': 1, 'count': 1},
    }
    setting = RuntimeSetting(key="TEST4")
    with form('TEST4'):
        setting.value = initial_value
    setting.save()
    test_value = {
        'key': 'TEST4',
        'value': {'testing': 1, 'count': 25},
    }
    url = reverse('runtimesetting-detail', args=(setting.pk,))
    with form('TEST4'):
        response = api_client.put(url, data=test_value, format='json')
    assert response.data == {
        'value': {'count': 25},
        'key': 'TEST4'
    }
    obj = RuntimeSetting.objects.get(key='TEST4')
    with form('TEST4'):
        assert obj.value == {'count': 25}