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
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'
def test_get_order_by_none_fields(): result = get_order_by(None, FIELD_EXPRESSION_DICT) assert result == ''
def test_get_order_by_empty_fields(): result = get_order_by(',,', FIELD_EXPRESSION_DICT) assert result == ''
def test_get_order_by_partial_empty_fields(): result = get_order_by('likes,', FIELD_EXPRESSION_DICT) assert result == 'ORDER BY `likes` ASC'
def test_get_order_by_empty_minus_field(): result = get_order_by('-', FIELD_EXPRESSION_DICT) assert result == ''
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',)