MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / run_test_cases

Method run_test_cases

test/test_encryption.py:2818–2942  ·  view source on GitHub ↗
(self, name, range_opts, cast_func)

Source from the content-addressed store, hash-verified

2816 self.assertEqual(elem[f"encrypted{name}"], expected)
2817
2818 def run_test_cases(self, name, range_opts, cast_func):
2819 encrypted_fields = json_data("etc", "data", f"range-encryptedFields-{name}.json")
2820 self.db.drop_collection("explicit_encryption", encrypted_fields=encrypted_fields)
2821 self.db.create_collection("explicit_encryption", encryptedFields=encrypted_fields)
2822
2823 def encrypt_and_cast(i):
2824 return self.client_encryption.encrypt(
2825 cast_func(i),
2826 key_id=self.key1_id,
2827 algorithm=Algorithm.RANGE,
2828 contention_factor=0,
2829 range_opts=range_opts,
2830 )
2831
2832 for elem in [{f"encrypted{name}": encrypt_and_cast(i)} for i in [0, 6, 30, 200]]:
2833 self.encrypted_client.db.explicit_encryption.insert_one(elem)
2834
2835 # Case 1.
2836 insert_payload = self.client_encryption.encrypt(
2837 cast_func(6),
2838 key_id=self.key1_id,
2839 algorithm=Algorithm.RANGE,
2840 contention_factor=0,
2841 range_opts=range_opts,
2842 )
2843 self.assertEqual(self.client_encryption.decrypt(insert_payload), cast_func(6))
2844
2845 # Case 2.
2846 expression = {
2847 "$and": [
2848 {f"encrypted{name}": {"$gte": cast_func(6)}},
2849 {f"encrypted{name}": {"$lte": cast_func(200)}},
2850 ]
2851 }
2852 self.run_expression_find(name, expression, [cast_func(i) for i in [6, 30, 200]], range_opts)
2853 # Case 2, with UUID key_id
2854 self.run_expression_find(
2855 name,
2856 expression,
2857 [cast_func(i) for i in [6, 30, 200]],
2858 range_opts,
2859 key_id=self.key1_id.as_uuid(),
2860 )
2861
2862 # Case 3.
2863 self.run_expression_find(
2864 name,
2865 {
2866 "$and": [
2867 {f"encrypted{name}": {"$gte": cast_func(0)}},
2868 {f"encrypted{name}": {"$lte": cast_func(6)}},
2869 ]
2870 },
2871 [cast_func(i) for i in [0, 6]],
2872 range_opts,
2873 )
2874
2875 # Case 4.

Callers 6

test_double_precisionMethod · 0.95
test_datetimeMethod · 0.95
test_intMethod · 0.95

Calls 9

run_expression_findMethod · 0.95
RangeOptsClass · 0.90
as_uuidMethod · 0.80
json_dataFunction · 0.70
drop_collectionMethod · 0.45
create_collectionMethod · 0.45
insert_oneMethod · 0.45
encryptMethod · 0.45
decryptMethod · 0.45

Tested by

no test coverage detected