Skip to content

Commit

Permalink
update initial test in readme to be accurate
Browse files Browse the repository at this point in the history
  • Loading branch information
Inveracity committed Jul 26, 2023
1 parent 38baa72 commit 9449821
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ pipenv install --dev rethinkdb-mock

```python
from pprint import pprint
from rethinkdb import RethinkDB
from rethinkdb_mock import MockThink
import rethinkdb as r

r = RethinkDB()
db = MockThink({
'dbs': {
'tara': {
Expand All @@ -42,38 +43,39 @@ db = MockThink({
}
})

with db.connect() as conn:
result = r.db('tara').table('people').map(
lambda doc: doc.merge({'also_name': doc['name']})
).run(conn)
pprint(list(result))
def test_mytest():
with db.connect() as conn:
result = r.db('tara').table('people').map(
lambda doc: doc.merge({'also_name': doc['name']})
).run(conn)
pprint(list(result))

# [
# {'also_name': 'John', 'id': 'john-id', 'name': 'John'},
# {'also_name': 'Sam', 'id': 'sam-id', 'name': 'Sam'}
# ]
# [
# {'also_name': 'John', 'id': 'john-id', 'name': 'John'},
# {'also_name': 'Sam', 'id': 'sam-id', 'name': 'Sam'}
# ]

r.db('tara').table('people').update(
{'likes_fonz': True}
).run(conn)
r.db('tara').table('people').update(
{'likes_fonz': True}
).run(conn)

result = r.db('tara').table('people').run(conn)
pprint(list(result))
result = r.db('tara').table('people').run(conn)
pprint(list(result))

# [
# {'id': 'john-id', 'likes_fonz': True, 'name': 'John'},
# {'id': 'sam-id', 'likes_fonz': True, 'name': 'Sam'}
# ]
# [
# {'id': 'john-id', 'likes_fonz': True, 'name': 'John'},
# {'id': 'sam-id', 'likes_fonz': True, 'name': 'Sam'}
# ]

# data is reset at exit of context manager above
# data is reset at exit of context manager above

with db.connect() as conn:
result = r.db('tara').table('people').run(conn)
pprint(list(result))
# [
# {'id': 'john-id', 'name': 'John'},
# {'id': 'sam-id', 'name': 'Sam'}
# ]
with db.connect() as conn:
result = r.db('tara').table('people').run(conn)
pprint(list(result))
# [
# {'id': 'john-id', 'name': 'John'},
# {'id': 'sam-id', 'name': 'Sam'}
# ]
```

### Set the default database for the connection
Expand Down

0 comments on commit 9449821

Please sign in to comment.