Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add write hook tests #160

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 13 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,15 @@ default: help
help:
@echo "Usage:"
@echo
@echo " make help Print this help message"
@echo " make test-unit Run unit tests"
@echo " make test-integration Run integration tests"
@echo " make test-remote Run tests on digital ocean"
@echo " make upload-coverage Upload unit test coverage"
@echo " make upload-pypi Release ${PACKAGE_NAME} package to PyPi"
@echo " make clean Cleanup source directory"
@echo " make prepare Prepare ${PACKAGE_NAME} for build"
@echo " make help Print this help message"
@echo " make test-unit Run unit tests"
@echo " make test-integration Run integration tests"
@echo " make test-integration-2.4 Run integration tests"
@echo " make test-remote Run tests on digital ocean"
@echo " make upload-coverage Upload unit test coverage"
@echo " make upload-pypi Release ${PACKAGE_NAME} package to PyPi"
@echo " make clean Cleanup source directory"
@echo " make prepare Prepare ${PACKAGE_NAME} for build"

test-unit:
pytest -v -m unit
Expand All @@ -49,9 +50,12 @@ test-integration:
pytest -v -m integration
@killall rethinkdb

test-integration-2.4:
pytest -v -m integration_v2_4_x

test-ci:
@rethinkdb&
pytest -v --cov rethinkdb --cov-report xml
pytest -v --cov rethinkdb --cov-report xml --ignore=tests/integration/test_write_hooks.py
@killall rethinkdb

test-remote:
Expand Down
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ python_files = test_*.py
markers =
unit: Run unit tests
integration: Run integration tests
integration_v2_4_x: Run 2.4.x only integration tests
trio: Run trio related tests
tornado: Run tornado related tests
asyncio: Run asyncio related tests
51 changes: 51 additions & 0 deletions tests/integration/test_write_hooks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import pytest

from tests.helpers import IntegrationTestCaseBase

@pytest.mark.integration_v2_4_x
class TestWriteHooks(IntegrationTestCaseBase):
def setup_method(self):
super(TestWriteHooks, self).setup_method()

self.table_name = 'test_write_hooks'
self.documents = [
{'id': 1, 'name': 'Testing write hooks 1'},
]

self.r.table_create(self.table_name).run(self.conn)
self.r.table(self.table_name).insert(self.documents).run(self.conn)

def test_set_write_hook(self):
response = self.r.table(self.table_name).set_write_hook(lambda context, old_val, new_val:
new_val.merge({
'modified_at': context['timestamp']
})
).run(self.conn)

assert response == {'created': 1}

def test_write_hook_add_extra_data(self):
self.r.table(self.table_name).set_write_hook(lambda context, old_val, new_val:
new_val.merge({
'modified_at': context['timestamp']
})
).run(self.conn)

self.r.table(self.table_name).insert({
'id': 2, 'name': 'Testing write hooks 1'
}).run(self.conn)

document = self.r.table(self.table_name).get(2).run(self.conn)

assert document.get('modified_at') != None

def test_get_write_hook(self):
self.r.table(self.table_name).set_write_hook(lambda context, old_val, new_val:
new_val.merge({
'modified_at': context['timestamp']
})
).run(self.conn)

hook = self.r.table(self.table_name).get_write_hook().run(self.conn)

assert list(hook.keys()) == ['function', 'query']