def test_extract_attributes():
    fields = {
        'id': serializers.Field(),
        'username': serializers.Field(),
        'deleted': serializers.ReadOnlyField(),
    }
    resource = {'id': 1, 'deleted': None, 'username': '******'}
    expected = {'username': '******', 'deleted': None}
    assert sorted(JSONRenderer.extract_attributes(
        fields,
        resource)) == sorted(expected), 'Regular fields should be extracted'
    assert sorted(JSONRenderer.extract_attributes(fields, {})) == sorted(
        {'username':
         ''}), 'Should not extract read_only fields on empty serializer'
Exemplo n.º 2
0
def test_extract_attributes():
    fields = {
        "id": serializers.Field(),
        "username": serializers.Field(),
        "deleted": serializers.ReadOnlyField(),
    }
    resource = {"id": 1, "deleted": None, "username": "******"}
    expected = {"username": "******", "deleted": None}
    assert sorted(JSONRenderer.extract_attributes(
        fields,
        resource)) == sorted(expected), "Regular fields should be extracted"
    assert sorted(JSONRenderer.extract_attributes(fields, {})) == sorted(
        {"username":
         ""}), "Should not extract read_only fields on empty serializer"