From 853d68ff6ee5922f6d362bbc9f68098a5f028d95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Boros?= Date: Thu, 25 Apr 2019 21:10:47 +0200 Subject: [PATCH 1/3] Fix issue #110 --- rethinkdb/errors.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/rethinkdb/errors.py b/rethinkdb/errors.py index 1c1c6432..5e39f96f 100644 --- a/rethinkdb/errors.py +++ b/rethinkdb/errors.py @@ -243,10 +243,16 @@ def __init__(self, *seq, **opts): def __iter__(self): itr = iter(self.seq) - for sub in next(itr): - yield sub + + try: + for sub in next(itr): + yield sub + except StopIteration: + return + for token in itr: for sub in self.intsp: yield sub + for sub in token: yield sub From b5f72a88c8b6630497c2a12dc9d81f25bfe51dd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Boros?= Date: Fri, 26 Apr 2019 10:28:59 +0200 Subject: [PATCH 2/3] Add unit and integration tests for r.now() --- tests/integration/test_date_and_time.py | 46 +++++++++++++++++++++++++ tests/test_date_and_time.py | 13 +++++++ 2 files changed, 59 insertions(+) create mode 100644 tests/integration/test_date_and_time.py create mode 100644 tests/test_date_and_time.py diff --git a/tests/integration/test_date_and_time.py b/tests/integration/test_date_and_time.py new file mode 100644 index 00000000..59d3b5e6 --- /dev/null +++ b/tests/integration/test_date_and_time.py @@ -0,0 +1,46 @@ +import pytest +from copy import deepcopy +from tests.helpers import IntegrationTestCaseBase + + +@pytest.mark.integration +class TestDateAndTime(IntegrationTestCaseBase): + def setup_method(self): + super(TestDateAndTime, self).setup_method() + self.table_name = 'test_now' + self.r.table_create(self.table_name).run(self.conn) + + self.expected_insert_response = { + 'deleted': 0, + 'errors': 0, + 'inserted': 1, + 'replaced': 0, + 'skipped': 0, + 'unchanged': 0, + } + + @staticmethod + def compare_seconds(a, b): + """ + During the tests, the milliseconds are a little different, so we need to look at the results in seconds. + """ + def second_precision(dt): + return str(dt).split('.')[0] + + assert second_precision(a) == second_precision(b) + + def test_insert_with_now(self): + now = self.r.now() + insert_data = { + 'id': 1, + 'name': 'Captain America', + 'real_name': 'Steven Rogers', + 'universe': 'Earth-616', + 'created_at': now + } + + response = self.r.table(self.table_name).insert(insert_data).run(self.conn) + document = self.r.table(self.table_name).get(1).run(self.conn) + + assert response == self.expected_insert_response + self.compare_seconds(document['created_at'], self.r.now().run(self.conn)) diff --git a/tests/test_date_and_time.py b/tests/test_date_and_time.py new file mode 100644 index 00000000..b4ca18bd --- /dev/null +++ b/tests/test_date_and_time.py @@ -0,0 +1,13 @@ +import pytest +from mock import call, patch, ANY, Mock +from rethinkdb import r, ast + + +@pytest.mark.unit +class TestNow(object): + def setup_method(self): + pass + + def test_get_now(self): + now = r.now() + assert type(now) == ast.Now From a8fc35407968028c4824602e124617200c91954d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=A1bor=20Boros?= Date: Fri, 26 Apr 2019 10:29:29 +0200 Subject: [PATCH 3/3] Fix indentation --- rethinkdb/errors.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rethinkdb/errors.py b/rethinkdb/errors.py index 5e39f96f..93caff53 100644 --- a/rethinkdb/errors.py +++ b/rethinkdb/errors.py @@ -248,7 +248,7 @@ def __iter__(self): for sub in next(itr): yield sub except StopIteration: - return + return for token in itr: for sub in self.intsp: