Skip to content

Commit cb58740

Browse files
committed
sync reops
1 parent bf07406 commit cb58740

File tree

4 files changed

+134
-4
lines changed

4 files changed

+134
-4
lines changed

python.pyproj

+9-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<VisualStudioVersion Condition="'$(VisualStudioVersion)' == ''">10.0</VisualStudioVersion>
1313
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
1414
<IsWindowsApplication>False</IsWindowsApplication>
15+
<InterpreterId>{9a7a9026-48c1-4688-9d5d-e5699d47d074}</InterpreterId>
1516
</PropertyGroup>
1617
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
1718
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
@@ -52,6 +53,8 @@
5253
<Compile Include="pydocumentdb\utils.py" />
5354
<Compile Include="setup.py" />
5455
<Compile Include="test\crud_tests.py" />
56+
<Compile Include="test\encoding_tests.py" />
57+
<Compile Include="test\query_tests.py" />
5558
<Compile Include="test\orderby_tests.py" />
5659
<Compile Include="test\aggregate_tests.py" />
5760
<Compile Include="test\globaldb_tests.py" />
@@ -65,7 +68,7 @@
6568
<Compile Include="test\session_container_tests.py" />
6669
<Compile Include="test\test_config.py" />
6770
<Compile Include="test\ttl_tests.py" />
68-
<Compile Include="test\ru_per_min_tests.py" />
71+
<Compile Include="test\ru_per_min_tests.py" />
6972
<Compile Include="pydocumentdb\auth.py" />
7073
<Compile Include="pydocumentdb\base.py" />
7174
<Compile Include="pydocumentdb\documents.py" />
@@ -76,6 +79,7 @@
7679
<Compile Include="test\__init__.py" />
7780
<Content Include="requirements.txt" />
7881
<Content Include="test-requirements.txt" />
82+
<Content Include="test\test-requirements.txt" />
7983
<Content Include="tox.ini" />
8084
<Content Include="test\BaselineTest.PathParser.json" />
8185
</ItemGroup>
@@ -86,6 +90,10 @@
8690
<Folder Include="test" />
8791
<Folder Include="test\routing\" />
8892
</ItemGroup>
93+
<ItemGroup>
94+
<InterpreterReference Include="{9a7a9026-48c1-4688-9d5d-e5699d47d074}\2.7" />
95+
<InterpreterReference Include="{9a7a9026-48c1-4688-9d5d-e5699d47d074}\3.4" />
96+
</ItemGroup>
8997
<Import Project="$(PtvsTargetsFile)" Condition="Exists($(PtvsTargetsFile))" />
9098
<Import Project="$(MSBuildToolsPath)\Microsoft.Common.targets" Condition="!Exists($(PtvsTargetsFile))" />
9199
</Project>

test/encoding_tests.py

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
# -*- coding: utf-8 -*-
2+
3+
import unittest
4+
import pydocumentdb.document_client as document_client
5+
import pydocumentdb.documents as documents
6+
import test.test_config as test_config
7+
8+
class EncodingTest(unittest.TestCase):
9+
"""Test to ensure escaping of non-ascii characters from partition key"""
10+
11+
host = test_config._test_config.host
12+
masterKey = test_config._test_config.masterKey
13+
testDbName = 'testDatabase'
14+
testCollectionName = 'testCollection'
15+
16+
@classmethod
17+
def cleanUpTestDatabase(cls):
18+
global client
19+
client = document_client.DocumentClient(cls.host,
20+
{'masterKey': cls.masterKey})
21+
query_iterable = client.QueryDatabases('SELECT * FROM root r WHERE r.id=\'' + cls.testDbName + '\'')
22+
it = iter(query_iterable)
23+
24+
test_db = next(it, None)
25+
if test_db is not None:
26+
client.DeleteDatabase(test_db['_self'])
27+
28+
@classmethod
29+
def tearDownClass(cls):
30+
EncodingTest.cleanUpTestDatabase()
31+
32+
def setUp(self):
33+
global created_collection
34+
35+
EncodingTest.cleanUpTestDatabase()
36+
created_db = client.CreateDatabase({ 'id': self.testDbName })
37+
38+
collection_definition = { 'id': self.testCollectionName, 'partitionKey': {'paths': ['/pk'],'kind': 'Hash'} }
39+
collection_options = { 'offerThroughput': 10100 }
40+
created_collection = client.CreateCollection(created_db['_self'], collection_definition, collection_options)
41+
42+
def test_unicode_characters_in_partition_key (self):
43+
test_string = u'€€ کلید پارتیشن विभाजन कुंजी 123'
44+
document_definition = {'pk': test_string, 'id':'myid'}
45+
created_doc = client.CreateDocument(created_collection['_self'], document_definition)
46+
47+
read_options = {'partitionKey': test_string }
48+
read_doc = client.ReadDocument(created_doc['_self'], read_options)
49+
self.assertEqual(read_doc['pk'], test_string)
50+
51+
def test_create_document_with_line_separator_para_seperator_next_line_unicodes (self):
52+
53+
test_string = u'Line Separator (
) & Paragraph Separator (
) & Next Line (…) & نیم‌فاصله'
54+
document_definition = {'pk': 'pk', 'id':'myid', 'unicode_content':test_string }
55+
created_doc = client.CreateDocument(created_collection['_self'], document_definition)
56+
57+
read_options = {'partitionKey': 'pk' }
58+
read_doc = client.ReadDocument(created_doc['_self'], read_options)
59+
self.assertEqual(read_doc['unicode_content'], test_string)
60+
61+
def test_create_stored_procedure_with_line_separator_para_seperator_next_line_unicodes (self):
62+
63+
test_string = 'Line Separator (
) & Paragraph Separator (
) & Next Line (…) & نیم‌فاصله'
64+
65+
test_string_unicode = u'Line Separator (
) & Paragraph Separator (
) & Next Line (…) & نیم‌فاصله'
66+
67+
stored_proc_definition = {'id':'myid', 'body': test_string}
68+
created_sp = client.CreateStoredProcedure(created_collection['_self'], stored_proc_definition)
69+
70+
read_sp = client.ReadStoredProcedure(created_sp['_self'], dict())
71+
self.assertEqual(read_sp['body'], test_string_unicode)
72+
if __name__ == '__main__':
73+
unittest.main()

test/query_tests.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import unittest
2+
import pydocumentdb.document_client as document_client
3+
import pydocumentdb.documents as documents
4+
import test.test_config as test_config
5+
6+
class QueryTest(unittest.TestCase):
7+
"""Test to ensure escaping of non-ascii characters from partition key"""
8+
9+
host = test_config._test_config.host
10+
masterKey = test_config._test_config.masterKey
11+
testDbName = 'testDatabase'
12+
testCollectionName = 'testCollection'
13+
14+
@classmethod
15+
def cleanUpTestDatabase(cls):
16+
global client
17+
client = document_client.DocumentClient(cls.host,
18+
{'masterKey': cls.masterKey})
19+
query_iterable = client.QueryDatabases('SELECT * FROM root r WHERE r.id=\'' + cls.testDbName + '\'')
20+
it = iter(query_iterable)
21+
22+
test_db = next(it, None)
23+
if test_db is not None:
24+
client.DeleteDatabase("/dbs/" + cls.testDbName + "/")
25+
""" change """
26+
27+
@classmethod
28+
def tearDownClass(cls):
29+
QueryTest.cleanUpTestDatabase()
30+
31+
def setUp(self):
32+
global created_collection
33+
34+
QueryTest.cleanUpTestDatabase()
35+
created_db = client.CreateDatabase({ 'id': self.testDbName })
36+
37+
collection_definition = { 'id': self.testCollectionName, 'partitionKey': {'paths': ['/pk'],'kind': 'Hash'} }
38+
collection_options = { 'offerThroughput': 10100 }
39+
created_collection = client.CreateCollection(created_db['_self'], collection_definition, collection_options)
40+
41+
def test_first_and_last_slashes_trimmed_for_query_string (self):
42+
document_definition = {'pk': 'pk', 'id':'myId'}
43+
created_doc = client.CreateDocument(created_collection['_self'], document_definition)
44+
45+
query_options = {'partitionKey': 'pk'}
46+
collectionLink = '/dbs/' + self.testDbName + '/colls/' + self.testCollectionName + '/'
47+
query = 'SELECT * from ' + self.testCollectionName
48+
query_iterable = client.QueryDocuments(collectionLink, query, query_options)
49+
50+
iter_list = list(query_iterable)
51+
self.assertEqual(iter_list[0]['id'], 'myId')
52+

test/ru_per_min_tests.py

-3
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def test_create_collection_with_ru_pm(self):
107107
self.assertIsNotNone(offer)
108108
self.assertEqual(offer['offerType'], "Invalid")
109109
self.assertIsNotNone(offer['content'])
110-
self.assertEqual(offer['content']['offerIsRUPerMinuteThroughputEnabled'], True)
111110

112111
def test_create_collection_without_ru_pm(self):
113112
# create a non ru pm collection
@@ -130,8 +129,6 @@ def test_create_collection_without_ru_pm(self):
130129
self.assertIsNotNone(offer)
131130
self.assertEqual(offer['offerType'], "Invalid")
132131
self.assertIsNotNone(offer['content'])
133-
self.assertEqual(offer['content']['offerIsRUPerMinuteThroughputEnabled'], True)
134-
135132

136133
def test_create_collection_disable_ru_pm_on_request(self):
137134
# create a non ru pm collection

0 commit comments

Comments
 (0)