~andrewjbeach/juju-ci-tools/make-local-patcher

« back to all changes in this revision

Viewing changes to azure-sdk-for-python-master/tests/doctest_tableservice.py

  • Committer: Curtis Hovey
  • Date: 2015-06-11 19:35:22 UTC
  • mto: This revision was merged to the branch mainline in revision 983.
  • Revision ID: curtis@canonical.com-20150611193522-o2nqkqb04o2i75wv
Remove euca_dump_logs because it has not been used this year.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#-------------------------------------------------------------------------
 
2
# Copyright (c) Microsoft.  All rights reserved.
 
3
#
 
4
# Licensed under the Apache License, Version 2.0 (the "License");
 
5
# you may not use this file except in compliance with the License.
 
6
# You may obtain a copy of the License at
 
7
#   http://www.apache.org/licenses/LICENSE-2.0
 
8
#
 
9
# Unless required by applicable law or agreed to in writing, software
 
10
# distributed under the License is distributed on an "AS IS" BASIS,
 
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
12
# See the License for the specific language governing permissions and
 
13
# limitations under the License.
 
14
#--------------------------------------------------------------------------
 
15
 
 
16
"""
 
17
How To: Create a Table
 
18
----------------------
 
19
>>> from azure.storage import *
 
20
>>> table_service = TableService(name, key)
 
21
>>> table_service.create_table('tasktable')
 
22
True
 
23
 
 
24
How to Add an Entity to a Table
 
25
-------------------------------
 
26
>>> task = {'PartitionKey': 'tasksSeattle', 'RowKey': '1', 'description' : 'Take out the trash', 'priority' : 200}
 
27
>>> entity = table_service.insert_entity('tasktable', task)
 
28
 
 
29
>>> task = Entity()
 
30
>>> task.PartitionKey = 'tasksSeattle'
 
31
>>> task.RowKey = '2'
 
32
>>> task.description = 'Wash the car'
 
33
>>> task.priority = 100
 
34
>>> entity = table_service.insert_entity('tasktable', task)
 
35
 
 
36
How to Update an Entity
 
37
-----------------------
 
38
>>> task = {'description' : 'Take out the garbage', 'priority' : 250}
 
39
>>> entity = table_service.update_entity('tasktable', 'tasksSeattle', '1', task)
 
40
 
 
41
>>> task = {'description' : 'Take out the garbage again', 'priority' : 250}
 
42
>>> entity = table_service.insert_or_replace_entity('tasktable', 'tasksSeattle', '1', task)
 
43
 
 
44
>>> task = {'description' : 'Buy detergent', 'priority' : 300}
 
45
>>> entity = table_service.insert_or_replace_entity('tasktable', 'tasksSeattle', '3', task)
 
46
 
 
47
 
 
48
How to Change a Group of Entities
 
49
---------------------------------
 
50
>>> task10 = {'PartitionKey': 'tasksSeattle', 'RowKey': '10', 'description' : 'Go grocery shopping', 'priority' : 400}
 
51
>>> task11 = {'PartitionKey': 'tasksSeattle', 'RowKey': '11', 'description' : 'Clean the bathroom', 'priority' : 100}
 
52
>>> table_service.begin_batch()
 
53
>>> table_service.insert_entity('tasktable', task10)
 
54
>>> table_service.insert_entity('tasktable', task11)
 
55
>>> table_service.commit_batch()
 
56
 
 
57
How to Query for an Entity
 
58
--------------------------
 
59
>>> task = table_service.get_entity('tasktable', 'tasksSeattle', '1')
 
60
>>> print(task.description)
 
61
Take out the garbage again
 
62
>>> print(task.priority)
 
63
250
 
64
 
 
65
>>> task = table_service.get_entity('tasktable', 'tasksSeattle', '10')
 
66
>>> print(task.description)
 
67
Go grocery shopping
 
68
>>> print(task.priority)
 
69
400
 
70
 
 
71
How to Query a Set of Entities
 
72
------------------------------
 
73
>>> tasks = table_service.query_entities('tasktable', "PartitionKey eq 'tasksSeattle'")
 
74
>>> for task in tasks:
 
75
...     print(task.description)
 
76
...     print(task.priority)
 
77
Take out the garbage again
 
78
250
 
79
Go grocery shopping
 
80
400
 
81
Clean the bathroom
 
82
100
 
83
Wash the car
 
84
100
 
85
Buy detergent
 
86
300
 
87
 
 
88
How to Query a Subset of Entity Properties
 
89
------------------------------------------
 
90
>>> tasks = table_service.query_entities('tasktable', "PartitionKey eq 'tasksSeattle'", 'description')
 
91
>>> for task in tasks:
 
92
...     print(task.description)
 
93
Take out the garbage again
 
94
Go grocery shopping
 
95
Clean the bathroom
 
96
Wash the car
 
97
Buy detergent
 
98
 
 
99
How to Delete an Entity
 
100
-----------------------
 
101
>>> table_service.delete_entity('tasktable', 'tasksSeattle', '1')
 
102
 
 
103
How to Delete a Table
 
104
---------------------
 
105
>>> table_service.delete_table('tasktable')
 
106
True
 
107
 
 
108
"""
 
109
from util import credentials
 
110
 
 
111
name = credentials.getStorageServicesName()
 
112
key = credentials.getStorageServicesKey()
 
113
 
 
114
if __name__ == "__main__":
 
115
    import doctest
 
116
    doctest.testmod()