Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@scenario(prepare_data, cleanup_data)
def test_search_with_multiple_sorts(context):
"""
Search with multiple sorts
"""
# When create a query block
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": 10, "baz": 1})
add_document("foo", {"bar": 10, "baz": 2})
add_document("foo", {"bar": 10, "baz": 3})
# And I add sorting
first_sort = Sort("bar", order="asc")
second_sort = Sort("baz", order="asc")
t.order_by(first_sort)
@scenario(prepare_output_stream)
def test_output_black_foreground(spec):
"Test output: black foreground"
spec.make_shell()
spec.sh.black("Hello Black!")
spec.check_output("\033[30mHello Black!\033[0m")
@scenario([prepare_real_model], [delete_modelo_objects])
def test_create_with_invalid_fields(context):
"Create with invalid fields raises error"
resource = RestroomResource(Modelo,
{'fields': ['text', 'slug', 'awesome']})
(resource.create.when.called_with(
{'blah': 'Awesome text', 'slug': 'awesome-slug', 'awesome': True})
.should.throw(RestroomInvalidFieldError,
"Cannot resolve the following field names: blah"))
@scenario(prepare_data, cleanup_data)
def test_search_with_lt_range(context):
"""
Search with lt range filter
"""
# When create a query block
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": 1})
add_document("foo", {"bar": 2})
add_document("foo", {"bar": 3})
# And I add a range filter
_type = Range("bar", lt=2)
t.filter(_type)
results = t[0:10]
@scenario(prepare_data, cleanup_data)
def test_geo_distance_search_dict(context):
"""
Search with geo distance filter with dictionary
"""
# When create a queryset
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"location": {"lat": 1.1, "lon": 2.1}})
add_document("foo", {"location": {"lat": 40.1, "lon": 80.1}})
# And I filter for distance
t.filter(GeoDistance({"lat": 1.0, "lon": 2.0}, "20mi"))
results = t[0:10]
# Then I get a the expected results
@scenario(prepare_data, cleanup_data)
def test_wrappers(context):
"""
Search with wrapped match_all query
"""
# When create a queryset
t = QuerySet("localhost", index="foo")
# And there are records
add_document("foo", {"bar": 1})
add_document("foo", {"bar": 2})
add_document("foo", {"bar": 3})
# And I do a search
def wrapper_function(search_results):
return list(map(lambda x: x['_source']['bar'] + 1, search_results))
t.wrappers(wrapper_function)
@scenario([prepare_real_model], [delete_modelo_objects])
def test_create(context):
"Create"
resource = RestroomResource(Modelo,
{'fields': ['text', 'slug', 'awesome']})
(expect(resource.create(
{'text': 'Awesome text', 'slug': 'awesome-slug', 'awesome': True}))
.to.equal({'id': 3,
'text': 'Awesome text',
'slug': 'awesome-slug',
'awesome': True})
)
@scenario(prepare_output_stream)
def test_update_shell_mixed_with_bold(spec):
"updating the shell with mixed output and bold enabled"
spec.make_shell(bold=True)
spec.sh.yellow("Yellow")
spec.sh.yellow_and_normal_and_red("Yellow| and |Red", True)
spec.sh.green("Green")
spec.check_output(
"\033[1m\033[33mYellow\033[0m\r\033[A\033[1m\033[33mYellow\033[0m\033[39m and \033[0m\033[31mRed\033[0m\033[1m\033[32mGreen\033[0m"
)
@scenario(prepare_data, cleanup_data)
def test_string_search(context):
"""
Search with string query
"""
# When create a queryset
t = QuerySet("localhost", query="cheese", index="foo")
# And there are records
add_document("foo", {"bar": "banana"})
add_document("foo", {"bar": "cheese"})
# And I do a search
results = t[0:10]
# Then I get a the expected results
len(results).should.equal(1)
@scenario([prepare_real_model], [delete_modelo_objects])
def test_update_one(context):
"Update_one"
resource = RestroomResource(Modelo,
{'fields': ['text', 'slug', 'awesome']})
expect(resource.update_one(1,
{'text': 'Amazing text'})).to.equal(
{'id': 1,
'text': 'Amazing text',
'slug': 'a-slug',
'awesome': True})