Skip to content

Commit 65a082d

Browse files
committed
PYTHON-2475 Implement Atlas Data Lake prose specification tests (#665)
(cherry picked from commit 00ed232)
1 parent 43e079d commit 65a082d

File tree

3 files changed

+75
-8
lines changed

3 files changed

+75
-8
lines changed

.evergreen/config.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,17 +309,15 @@ functions:
309309
script: |
310310
set -o xtrace
311311
${PREPARE_SHELL}
312-
cd ${DRIVERS_TOOLS}/.evergreen/atlas_data_lake
313-
DRIVERS_TOOLS="${DRIVERS_TOOLS}" sh build-mongohouse-local.sh
312+
sh ${DRIVERS_TOOLS}/.evergreen/atlas_data_lake/build-mongohouse-local.sh
314313
- command: shell.exec
315314
type: setup
316315
params:
317316
background: true
318317
script: |
319318
set -o xtrace
320319
${PREPARE_SHELL}
321-
cd ${DRIVERS_TOOLS}/.evergreen/atlas_data_lake
322-
DRIVERS_TOOLS="${DRIVERS_TOOLS}" sh run-mongohouse-local.sh
320+
sh ${DRIVERS_TOOLS}/.evergreen/atlas_data_lake/run-mongohouse-local.sh
323321
324322
"stop mongo-orchestration":
325323
- command: shell.exec

test/__init__.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,13 @@ def require_connection(self, func):
524524
"Cannot connect to MongoDB on %s" % (self.pair,),
525525
func=func)
526526

527+
def require_data_lake(self, func):
528+
"""Run a test only if we are connected to Atlas Data Lake."""
529+
return self._require(
530+
lambda: self.is_data_lake,
531+
"Not connected to Atlas Data Lake on %s" % (self.pair,),
532+
func=func)
533+
527534
def require_no_mmap(self, func):
528535
"""Run a test only if the server is not using the MMAPv1 storage
529536
engine. Only works for standalone and replica sets; tests are

test/test_data_lake.py

Lines changed: 66 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,86 @@
1919

2020
sys.path[0:0] = [""]
2121

22-
from test import client_context, unittest
22+
from pymongo.auth import MECHANISMS
23+
from test import client_context, unittest, IntegrationTest
2324
from test.crud_v2_format import TestCrudV2
24-
from test.utils import TestCreator
25+
from test.utils import (
26+
rs_client_noauth, rs_or_single_client, OvertCommandListener, TestCreator)
2527

2628

2729
# Location of JSON test specifications.
2830
_TEST_PATH = os.path.join(
2931
os.path.dirname(os.path.realpath(__file__)), "data_lake")
3032

3133

34+
class TestDataLakeMustConnect(IntegrationTest):
35+
def test_connected_to_data_lake(self):
36+
data_lake = os.environ.get('DATA_LAKE')
37+
if not data_lake:
38+
self.skipTest('DATA_LAKE is not set')
39+
40+
self.assertTrue(client_context.is_data_lake,
41+
'client context.is_data_lake must be True when '
42+
'DATA_LAKE is set')
43+
44+
45+
class TestDataLakeProse(IntegrationTest):
46+
# Default test database and collection names.
47+
TEST_DB = 'test'
48+
TEST_COLLECTION = 'driverdata'
49+
50+
@classmethod
51+
@client_context.require_data_lake
52+
def setUpClass(cls):
53+
super(TestDataLakeProse, cls).setUpClass()
54+
55+
# Test killCursors
56+
def test_1(self):
57+
listener = OvertCommandListener()
58+
client = rs_or_single_client(event_listeners=[listener])
59+
cursor = client[self.TEST_DB][self.TEST_COLLECTION].find(
60+
{}, batch_size=2)
61+
next(cursor)
62+
63+
# find command assertions
64+
find_cmd = listener.results["succeeded"][-1]
65+
self.assertEqual(find_cmd.command_name, "find")
66+
cursor_id = find_cmd.reply["cursor"]["id"]
67+
cursor_ns = find_cmd.reply["cursor"]["ns"]
68+
69+
# killCursors command assertions
70+
cursor.close()
71+
started = listener.results["started"][-1]
72+
self.assertEqual(started.command_name, 'killCursors')
73+
succeeded = listener.results["succeeded"][-1]
74+
self.assertEqual(succeeded.command_name, 'killCursors')
75+
76+
self.assertIn(cursor_id, started.command["cursors"])
77+
target_ns = ".".join([started.command['$db'],
78+
started.command['killCursors']])
79+
self.assertEqual(cursor_ns, target_ns)
80+
81+
self.assertIn(cursor_id, succeeded.reply["cursorsKilled"])
82+
83+
# Test no auth
84+
def test_2(self):
85+
client = rs_client_noauth()
86+
client.admin.command('ping')
87+
88+
# Test with auth
89+
def test_3(self):
90+
for mechanism in ['SCRAM-SHA-1', 'SCRAM-SHA-256']:
91+
client = rs_or_single_client(authMechanism=mechanism)
92+
client[self.TEST_DB][self.TEST_COLLECTION].find_one()
93+
94+
3295
class DataLakeTestSpec(TestCrudV2):
3396
# Default test database and collection names.
3497
TEST_DB = 'test'
3598
TEST_COLLECTION = 'driverdata'
3699

37100
@classmethod
38-
@unittest.skipUnless(client_context.is_data_lake,
39-
'Not connected to Atlas Data Lake')
101+
@client_context.require_data_lake
40102
def setUpClass(cls):
41103
super(DataLakeTestSpec, cls).setUpClass()
42104

0 commit comments

Comments
 (0)