예제 #1
0
def test_get_order_by():
    sort_expressions = 'likes,-timestamp'

    result = get_order_by(sort_expressions, FIELD_EXPRESSION_DICT)

    assert result.count(',') == 1
    assert 'ORDER BY ' == result[:9]
    assert '`timestamp` DESC' in result
    assert '`likes` ASC' in result
예제 #2
0
def test_get_order_by_invalid_column():
    with pytest.raises(InvalidUsage) as exception:
        get_order_by('foobar', FIELD_EXPRESSION_DICT)

    assert exception.value.message == 'Invalid sort field'
예제 #3
0
def test_get_order_by_none_fields():
    result = get_order_by(None, FIELD_EXPRESSION_DICT)

    assert result == ''
예제 #4
0
def test_get_order_by_empty_fields():
    result = get_order_by(',,', FIELD_EXPRESSION_DICT)

    assert result == ''
예제 #5
0
def test_get_order_by_partial_empty_fields():
    result = get_order_by('likes,', FIELD_EXPRESSION_DICT)

    assert result == 'ORDER BY `likes` ASC'
예제 #6
0
def test_get_order_by_empty_minus_field():
    result = get_order_by('-', FIELD_EXPRESSION_DICT)

    assert result == ''
예제 #7
0
def test_get_order_by_invalid_column():
    with pytest.raises(ApiException) as exception:
        get_order_by('foobar', FIELD_EXPRESSION_DICT)

    assert exception.value.errors[0].code == ErrorCode.QUERY_INVALID_SORT_FIELD
    assert exception.value.errors[0].args == ('foobar',)