def test_response_filtered_with_some_bogus_fields():
    response = APIClient().get('/quotes/parrot/?fields=sketch,spam,eggs')
    expected = {
        'sketch': 'PET SHOP',
    }
    content = decode_content(response)
    assert content == expected
Exemple #2
0
def test_model_response_filtered_with_include_and_exclude():
    response = APIClient().get('/snippets/3/?fields=id&fields!=language')
    expected = {
        'id': 3,
    }
    content = decode_content(response)
    assert content == expected
Exemple #3
0
def test_model_response_filtered_with_some_bogus_fields():
    response = APIClient().get('/snippets/3/?fields=title,spam,eggs')
    expected = {
        'title': 'Russian roulette',
    }
    content = decode_content(response)
    assert content == expected
def test_detail_response_filtered_excludes():
    response = APIClient().get('/quotes/parrot/?fields!=character')
    expected = {
        'line': "Well, he's...he's, ah...probably pining for the fjords",
        'sketch': 'PET SHOP',
    }
    content = decode_content(response)
    assert content == expected
Exemple #5
0
def test_model_detail_response_filtered_excludes():
    response = APIClient().get('/snippets/3/?fields!=id,linenos,code')
    expected = {
        'title': 'Russian roulette',
        'language': 'bash',
    }
    content = decode_content(response)
    assert content == expected
def test_detail_response_filtered_includes():
    response = APIClient().get('/quotes/parrot/?fields=character,line')
    expected = {
        'character': 'Shopkeeper',
        'line': "Well, he's...he's, ah...probably pining for the fjords",
    }
    content = decode_content(response)
    assert content == expected
def test_exclude_wins_for_ambiguous_filtering():
    response = APIClient().get(
        '/quotes/parrot/?fields=line,sketch&fields!=line')
    expected = {
        'sketch': 'PET SHOP',
    }
    content = decode_content(response)
    assert content == expected
Exemple #8
0
def test_model_exclude_wins_for_ambiguous_filtering():
    response = APIClient().get('/snippets/3/?fields=id,title,code&fields!=id')
    expected = {
        'title': 'Russian roulette',
        'code': '[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "click"',
    }
    content = decode_content(response)
    assert content == expected
def test_response_filtered_with_include_and_exclude():
    response = APIClient().get(
        '/quotes/parrot/?fields=character&fields=sketch&fields!=line')
    expected = {
        'character': 'Shopkeeper',
        'sketch': 'PET SHOP',
    }
    content = decode_content(response)
    assert content == expected
Exemple #10
0
def test_model_response_filtered_with_multiple_fields_in_separate_query_args():
    response = APIClient().get('/snippets/3/?fields=title&fields=linenos,language')
    expected = {
        'title': 'Russian roulette',
        'linenos': False,
        'language': 'bash',
    }
    content = decode_content(response)
    assert content == expected
def test_detail_response_unfiltered():
    response = APIClient().get('/quotes/parrot/')
    expected = {
        'character': 'Shopkeeper',
        'line': "Well, he's...he's, ah...probably pining for the fjords",
        'sketch': 'PET SHOP',
    }
    content = decode_content(response)
    assert content == expected
def test_response_filtered_with_multiple_fields_in_separate_query_args():
    response = APIClient().get(
        '/quotes/parrot/?fields=character&fields=sketch')
    expected = {
        'character': 'Shopkeeper',
        'sketch': 'PET SHOP',
    }
    content = decode_content(response)
    assert content == expected
Exemple #13
0
def test_model_detail_response_unfiltered():
    response = APIClient().get('/snippets/3/')
    expected = {
        'id': 3,
        'title': 'Russian roulette',
        'code': '[ $[ $RANDOM % 6 ] == 0 ] && rm -rf / || echo "click"',
        'linenos': False,
        'language': 'bash',
    }
    content = decode_content(response)
    assert content == expected
def test_post_ignores_queryfields():
    # Ensures that fields aren't dropped for other types of request
    response = APIClient().post('/quotes/?fields=line,sketch')
    expected = {
        'request_method': 'POST',
        'serializer_instance_fields': ['character', 'line', 'sketch'],
        'request_query': {
            'fields': 'line,sketch'
        },
    }
    content = decode_content(response)
    assert content == expected
def test_response_with_filter():
    response = APIClient().get('/snippets/?filter=title')
    expected = [
        {
            'title': 'Fork bomb',
        },
        {
            'title': 'French flag',
        },
    ]
    content = decode_content(response)
    assert content == expected
def test_response_with_fields_and_filter():
    response = APIClient().get('/snippets/?fields=code&filter=code')
    expected = [
        {
            'code': ':(){ :|: & };:',
        },
        {
            'code':
            "print((u'\x1b[3%s;1m\u2588'*78+u'\n')%((4,)*26+(7,)*26+(1,)*26)*30)",
        },
    ]
    content = decode_content(response)
    assert content == expected
def test_list_response_filtered_includes():
    response = APIClient().get('/quotes/?fields=character,line')
    expected = [
        {
            'character': 'Customer',
            'line': "It's certainly uncontaminated by cheese",
        },
        {
            'character': 'The Black Knight',
            'line': "It's just a flesh wound",
        },
    ]
    content = decode_content(response)
    assert content == expected
def test_list_response_filtered_excludes():
    response = APIClient().get('/quotes/?fields!=character')
    expected = [
        {
            'line': "It's certainly uncontaminated by cheese",
            'sketch': 'CHEESE SHOP',
        },
        {
            'line': "It's just a flesh wound",
            'sketch': 'HOLY GRAIL',
        },
    ]
    content = decode_content(response)
    assert content == expected
Exemple #19
0
def test_model_list_response_filtered_includes():
    response = APIClient().get('/snippets/?fields=title,language')
    expected = [
        {
            'title': 'Fork bomb',
            'language': 'bash',
        },
        {
            'title': 'French flag',
            'language': 'python',
        },
    ]
    content = decode_content(response)
    assert content == expected
Exemple #20
0
def test_model_list_response_filtered_excludes():
    response = APIClient().get('/snippets/?fields!=code,language')
    expected = [
        {
            'id': 1,
            'title': 'Fork bomb',
            'linenos': False,
        },
        {
            'id': 2,
            'title': 'French flag',
            'linenos': False,
        },
    ]
    content = decode_content(response)
    assert content == expected
def test_list_response_unfiltered():
    response = APIClient().get('/quotes/')
    expected = [
        {
            'character': 'Customer',
            'line': "It's certainly uncontaminated by cheese",
            'sketch': 'CHEESE SHOP',
        },
        {
            'character': 'The Black Knight',
            'line': "It's just a flesh wound",
            'sketch': 'HOLY GRAIL',
        },
    ]
    content = decode_content(response)
    assert content == expected
def test_response_without_fields():
    response = APIClient().get('/snippets/')
    expected = [
        {
            'id': 1,
            'title': 'Fork bomb',
            'linenos': False,
            'language': 'bash',
        },
        {
            'id': 2,
            'title': 'French flag',
            'linenos': False,
            'language': 'python',
        },
    ]
    content = decode_content(response)
    assert content == expected
Exemple #23
0
def test_model_list_response_unfiltered():
    response = APIClient().get('/snippets/')
    expected = [
        {
            'id': 1,
            'title': 'Fork bomb',
            'code': ':(){ :|: & };:',
            'linenos': False,
            'language': 'bash',
        },
        {
            'id': 2,
            'title': 'French flag',
            'code': "print((u'\x1b[3%s;1m\u2588'*78+u'\n')%((4,)*26+(7,)*26+(1,)*26)*30)",
            'linenos': False,
            'language': 'python',
        },
    ]
    content = decode_content(response)
    assert content == expected
Exemple #24
0
def test_model_response_filtered_with_only_bogus_fields():
    response = APIClient().get('/snippets/3/?fields=blah')
    expected = {}
    content = decode_content(response)
    assert content == expected
def test_detail_response_filtered_excludes():
    response = APIClient().get('/explosives/bunger/?fields!=boom')
    expected = {'safe': 'tom thumb'}
    content = decode_content(response)
    assert content == expected
def test_response_filtered_with_only_bogus_fields():
    response = APIClient().get('/quotes/parrot/?fields=blah')
    expected = {}
    content = decode_content(response)
    assert content == expected
def test_list_response_filtered_excludes():
    response = APIClient().get('/explosives/?fields!=boom')
    expected = [{'safe': 'green wire'}, {'safe': 'helium'}]
    content = decode_content(response)
    assert content == expected