forked from GoogleCloudPlatform/cloud-bigtable-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.py
59 lines (47 loc) · 1.79 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/usr/bin/env python
#
# Copyright 2015 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
import random
import requests
import string
# Create a random row key to minimize chances of intersecting with other clients
row_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
# First we build a URL assuming some-table2 exists, using the random
# row key, the column cf:count, and we specify the 'str' type
# so our strings are directly store
url = 'http://localhost:5000/some-table2/%s/cf:count/str' % row_key
r = requests.get(url)
assert r.text == "Not found"
requests.post(url, data='test string')
r = requests.get(url)
assert r.text == 'test string'
requests.delete(url)
r = requests.get(url)
assert r.text == "Not found"
# repeat process for ints
# note that int types are still strings at the HTTP layer, the last section of the URL
# that we want to serialize the data we pass in now as an int
row_key = ''.join(random.choice(string.ascii_uppercase + string.digits) for _ in range(10))
url = 'http://localhost:5000/some-table2/%s/cf:count/int' % row_key
r = requests.get(url)
assert r.text == "Not found"
requests.post(url, data="3")
r = requests.get(url)
assert r.text == "3"
requests.delete(url)
r = requests.get(url)
assert r.text == "Not found"
print "Done testing."