|
19 | 19 |
|
20 | 20 | sys.path[0:0] = [""]
|
21 | 21 |
|
22 |
| -from test import client_context, unittest |
| 22 | +from pymongo.auth import MECHANISMS |
| 23 | +from test import client_context, unittest, IntegrationTest |
23 | 24 | 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) |
25 | 27 |
|
26 | 28 |
|
27 | 29 | # Location of JSON test specifications.
|
28 | 30 | _TEST_PATH = os.path.join(
|
29 | 31 | os.path.dirname(os.path.realpath(__file__)), "data_lake")
|
30 | 32 |
|
31 | 33 |
|
| 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 | + |
32 | 95 | class DataLakeTestSpec(TestCrudV2):
|
33 | 96 | # Default test database and collection names.
|
34 | 97 | TEST_DB = 'test'
|
35 | 98 | TEST_COLLECTION = 'driverdata'
|
36 | 99 |
|
37 | 100 | @classmethod
|
38 |
| - @unittest.skipUnless(client_context.is_data_lake, |
39 |
| - 'Not connected to Atlas Data Lake') |
| 101 | + @client_context.require_data_lake |
40 | 102 | def setUpClass(cls):
|
41 | 103 | super(DataLakeTestSpec, cls).setUpClass()
|
42 | 104 |
|
|
0 commit comments