Browshot 1.12.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ import sys,types,os; p = os.path.join(sys._getframe(1).f_locals['sitedir'], *('browshot',)); ie = os.path.exists(os.path.join(p,'__init__.py')); m = not ie and sys.modules.setdefault('browshot',types.ModuleType('browshot')); mp = (m or []) and m.__dict__.setdefault('__path__',[]); (p not in mp) and mp.append(p)
@@ -0,0 +1,46 @@
1
+ Metadata-Version: 1.0
2
+ Name: Browshot
3
+ Version: 1.12.0
4
+ Summary: Client to interact with Browshot
5
+ Home-page: https://github.com/juliensobrier/browshot-python
6
+ Author: Julien Sobrier
7
+ Author-email: julien@sobrier.net
8
+ License: Apache
9
+ Description: Browshot version 1.12.0
10
+ ================================
11
+
12
+ Browshot (http://www.browshot.com/) is a web service to easily make screenshots of web pages in any screen size, as any device: iPhone, iPad, Android, Nook, PC, etc. Browshot has full Flash, JavaScript, CSS, & HTML5 support.
13
+
14
+ The latest API version is detailed at http://browshot.com/api/documentation. browshot follows the API documentation very closely: the function names are similar to the URLs used (screenshot/create becomes screenshot_create(), instance/list becomes instance_list(), etc.), the request arguments are exactly the same, etc.
15
+
16
+ The library version matches closely the API version it handles: browshot 1.0.0 is the first release for the API 1.0, browshot 1.1.1 is the second release for the API 1.1, etc.
17
+
18
+ browshot can handle most the API updates within the same major version, e.g. browshot 1.0.0 should be compatible with the API 1.1 or 1.2.
19
+
20
+ You can install the library from PyPI: http://pypi.python.org/pypi/Browshot
21
+
22
+ The source code can be found on github at https://github.com/juliensobrier/browshot-python
23
+
24
+
25
+
26
+ INSTALLATION
27
+
28
+ python setup.py install
29
+
30
+
31
+ DEPENDENCIES
32
+
33
+ The following python packages are required to run browshot
34
+
35
+ urllib2
36
+ simplejson
37
+ urlparse
38
+
39
+ Platform: UNKNOWN
40
+ Classifier: Development Status :: 4 - Beta
41
+ Classifier: Environment :: Console
42
+ Classifier: Intended Audience :: Developers
43
+ Classifier: Intended Audience :: Information Technology
44
+ Classifier: License :: OSI Approved :: BSD License
45
+ Classifier: Operating System :: OS Independent
46
+ Classifier: Programming Language :: Python
@@ -0,0 +1,15 @@
1
+ README
2
+ __init__.py
3
+ browshot.py
4
+ browshot.pyc
5
+ build.sh
6
+ example.py
7
+ setup.py
8
+ Browshot.egg-info/PKG-INFO
9
+ Browshot.egg-info/SOURCES.txt
10
+ Browshot.egg-info/dependency_links.txt
11
+ Browshot.egg-info/namespace_packages.txt
12
+ Browshot.egg-info/requires.txt
13
+ Browshot.egg-info/top_level.txt
14
+ tests/__init__.py
15
+ tests/test_browshot.py
@@ -0,0 +1,258 @@
1
+ # -*- coding: utf-8 -*-
2
+ # Copyright 2012 Julien Sobrier
3
+ # All Rights Reserved.
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License"); you may
6
+ # not use this file except in compliance with the License. You may obtain
7
+ # a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13
+ # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14
+ # License for the specific language governing permissions and limitations
15
+ # under the License.
16
+
17
+ """ Version 1.12.0
18
+
19
+ Python module for Browshot (http://www.browshot.com/), a web service to create website screenshots.
20
+
21
+ Browshot (http://www.browshot.com/) is a web service to easily make screenshots of web pages in any screen size, as any device: iPhone, iPad, Android, Nook, PC, etc. Browshot has full Flash, JavaScript, CSS, & HTML5 support.
22
+
23
+ The latest API version is detailed at http://browshot.com/api/documentation. browshot.py follows the API documentation very closely: the function names are similar to the URLs used (screenshot/create becomes screenshot_create(), instance/list becomes instance_list(), etc.), the request arguments are exactly the same, etc.
24
+
25
+ The library version matches closely the API version it handles: browshot.py 1.0.0 is the first release for the API 1.0, browshot.py 1.1.1 is the second release for the API 1.1, etc.
26
+
27
+ browshot.py can handle most the API updates within the same major version, e.g. browshot.py 1.0.0 should be compatible with the API 1.1 or 1.2. """
28
+
29
+
30
+ import urllib
31
+ from urllib2 import Request, urlopen, URLError, HTTPError
32
+ import simplejson
33
+
34
+
35
+ class BrowshotClient(object):
36
+ def __init__(self, key='', base='https://api.browshot.com/api/v1/', debug=0):
37
+ """ Create a new WebService::Browshot object. You must pass your API key (go to you Dashboard to find your API key, https://browshot.com/dashboard).
38
+
39
+ Arguments:
40
+ key: API key.
41
+ base: Base URL for all API requests. You should use the default base provided by the library. Be careful if you decide to use HTTP instead of HTTPS as your API key could be sniffed and your account could be used without your consent.
42
+ debug: Set to 1 to print debug output to the standard output. 0 (disabled) by default.
43
+ """
44
+ self.key = key
45
+ self.base = base
46
+ self.debug = debug
47
+
48
+ def api_version(self):
49
+ """ Return the API version handled by the library. Note that this library can usually handle new arguments in requests without requiring an update. """
50
+ return '1.12'
51
+
52
+ def simple(self, url='', parameters={}):
53
+ """ Retrieve a screenshot in one function.
54
+
55
+ Note: by default, screenshots are cached for 24 hours. You can tune this valu with the cache=X parameter.
56
+
57
+ Arguments:
58
+ See http://browshot.com/api/documentation#simple for the full list of possible arguments.
59
+ url (Required): URL of the screenshot
60
+
61
+ Returns {'code': <code>, 'png': <content>}
62
+ <code>: 200 if successful
63
+ <content>: PNG file
64
+ """
65
+ parameters.update({'url': url})
66
+ uri = self.make_url('simple', parameters)
67
+ if self.debug:
68
+ print uri
69
+
70
+ try:
71
+ response = urlopen(uri)
72
+
73
+ return {'code': 200, 'png': response.read()}
74
+ except HTTPError, e:
75
+ return {'code': e.code, 'png': ''}
76
+ except Exception, e:
77
+ return {'code': 400, 'png': ''}
78
+
79
+
80
+
81
+ def simple_file(self, url='', file='', parameters={}):
82
+ """ Retrieve a screenshot, or a thumbnail, and save it to a fil in one functione.
83
+
84
+ Note: by default, screenshots are cached for 24 hours. You can tune this valu with the cache=X parameter.
85
+
86
+ Returns {'code': <code>, 'file': <file path}
87
+ <code>: 200 if successful
88
+ <file path>: local file where the screenshot was saved, empty string it if failed
89
+
90
+ Arguments:
91
+ See http://browshot.com/api/documentation#simple for the full list of possible arguments.
92
+ url (Required): URL of the screenshot
93
+ file (Required): local file to store the screenshot
94
+ """
95
+ data = self.simple(url, parameters);
96
+ if len(data['png']) > 0:
97
+ image = open(file, mode='wb')
98
+ image.write(data['png'])
99
+ image.close();
100
+ return {'code': data['code'], 'file': file}
101
+
102
+ return {'code': data['code'], 'file': ''}
103
+
104
+
105
+ def instance_list(self):
106
+ """ Return the list of instances as a dictionary. See http://browshot.com/api/documentation#instance_list for the response format. """
107
+ return self.return_reply('instance/list')
108
+
109
+
110
+ def instance_info(self, id=0):
111
+ """ Return the details of an instance. See http://browshot.com/api/documentation#instance_info for the response format.
112
+
113
+ Arguments:
114
+ id (Required): Instance ID
115
+ """
116
+ return self.return_reply('instance/info', { 'id': id })
117
+
118
+ def instance_create(self,parameters={}):
119
+ """ Create a private instance. See http://browshot.com/api/documentation#instance_create for the response format.
120
+
121
+ Arguments:
122
+ See http://browshot.com/api/documentation#instance_create for the full list of possible arguments.
123
+ """
124
+ return self.return_reply('instance/create', parameters)
125
+
126
+
127
+ def browser_list(self):
128
+ """ Return the list of browsers as a hash reference. See http://browshot.com/api/documentation#browser_list for the response format. """
129
+ return self.return_reply('browser/list')
130
+
131
+ def browser_info(self, id=0):
132
+ """ Return the details of a browser. See L<http://browshot.com/api/documentation#browser_info> for the response format.
133
+
134
+ Arguments:
135
+ id (Required: Browser ID
136
+ """
137
+ return self.return_reply('browser/info', { 'id': id })
138
+
139
+ def browser_create(self,parameters={}):
140
+ """ Create a custom browser. See http://browshot.com/api/documentation#browser_create for the response format.
141
+
142
+ Arguments:
143
+ See http://browshot.com/api/documentation#browser_create for the full list of possible arguments.
144
+ """
145
+ return self.return_reply('browser/create', parameters)
146
+
147
+ def screenshot_create(self, url='', parameters={}):
148
+ """ Request a screenshot. See http://browshot.com/api/documentation#screenshot_create for the response format.
149
+
150
+ Note: by default, screenshots are cached for 24 hours. You can tune this valu with the cache=X parameter.
151
+
152
+ Arguments:
153
+ See http://browshot.com/api/documentation#screenshot_create for the full list of possible arguments.
154
+ url(Required): URL of the website to create a screenshot of.
155
+ """
156
+ parameters.update({'url': url})
157
+ return self.return_reply('screenshot/create', parameters)
158
+
159
+ def screenshot_info(self, id=0, parameters={}):
160
+ """ Get information about a screenshot requested previously. See http://browshot.com/api/documentation#screenshot_info for the response format.
161
+
162
+ Arguments:
163
+ id (Required): Screenshot ID.
164
+ """
165
+ parameters.update({'id': id})
166
+ return self.return_reply('screenshot/info', parameters)
167
+
168
+ def screenshot_list(self, parameters={}):
169
+ """ Get details about screenshot requested. See http://browshot.com/api/documentation#screenshot_list for the response format. """
170
+ return self.return_reply('screenshot/list', parameters)
171
+
172
+ def screenshot_host(self, id=0, parameters={}):
173
+ """ Host a screenshot or a thumbnail. See L<http://browshot.com/api/documentation#screenshot_host> for the response format.
174
+
175
+ Arguments:
176
+ See http://browshot.com/api/documentation#screenshot_host for the full list of possible arguments.
177
+ id (Required): screenshot ID
178
+ """
179
+ parameters.update({'id': id})
180
+ return self.return_reply('screenshot/host', parameters)
181
+
182
+ def screenshot_share(self, id=0, parameters={}):
183
+ """ Share a screenshot. See L<http://browshot.com/api/documentation#screenshot_share> for the response format.
184
+
185
+ Arguments:
186
+ See http://browshot.com/api/documentation#screenshot_share for the full list of possible arguments.
187
+ id (Required): screenshot ID
188
+ """
189
+ parameters.update({'id': id})
190
+ return self.return_reply('screenshot/share', parameters)
191
+
192
+ def screenshot_delete(self, id=0, parameters={}):
193
+ """ Deleet details of a screenshot. See L<http://browshot.com/api/documentation#screenshot_delete> for the response format.
194
+
195
+ Arguments:
196
+ See http://browshot.com/api/documentation#screenshot_delete for the full list of possible arguments.
197
+ id (Required): screenshot ID
198
+ """
199
+ parameters.update({'id': id})
200
+ return self.return_reply('screenshot/delete', parameters)
201
+
202
+ def screenshot_thumbnail(self, id=0, parameters={}):
203
+ """ Retrieve the screenshot, or a thumbnail. See L<http://browshot.com/api/documentation#screenshot_thumbnail> for the response format.
204
+
205
+ Arguments:
206
+ See http://browshot.com/api/documentation#screenshot_thumbnail for the full list of possible arguments.
207
+ id (Required): screenshot ID. You will get the full image if no other argument is specified.
208
+ """
209
+ parameters.update({'id': id})
210
+ url = self.make_url('screenshot/thumbnail', parameters)
211
+ response = urllib.urlopen(url)
212
+ return response.read()
213
+
214
+ def screenshot_thumbnail_file(self, url='', id=0, parameters={}):
215
+ """ Retrieve the screenshot, or a thumbnail, and save it to a file. See http://browshot.com/api/documentation#screenshot_thumbnail for the response format.
216
+
217
+ Returns the file name if successful.
218
+
219
+ Arguments:
220
+ See http://browshot.com/api/documentation#screenshot_thumbnail for the full list of possible arguments.
221
+ id (Required): screenshot ID. You will get the full image if no other argument is specified.
222
+ file (Required): local file to store the screenshot
223
+ """
224
+ content = self.screenshot_thumbnail(id, parameters);
225
+
226
+ image = open(file, mode='wb')
227
+ image.write(content)
228
+ image.close();
229
+
230
+ return file
231
+
232
+ def account_info(self, parameters={}):
233
+ """ Get details about the user account. See http://browshot.com/api/documentation#account_info for the response format. """
234
+ return self.return_reply('account/info', parameters)
235
+
236
+
237
+ def make_url(self, action='', parameters={}):
238
+ url = self.base + action + '?key=' + urllib.quote_plus(self.key)
239
+
240
+ for key, value in parameters.items():
241
+ url += '&' + urllib.quote_plus(key) + '=' + urllib.quote_plus(str(value))
242
+
243
+ if self.debug:
244
+ print url
245
+
246
+ return url
247
+
248
+ def return_reply(self, action='', parameters={}):
249
+ try:
250
+ url = self.make_url(action, parameters)
251
+
252
+ response = urllib.urlopen(url)
253
+ json = response.read()
254
+
255
+ json_decode = simplejson.loads(json)
256
+ return json_decode
257
+ except Exception, e:
258
+ raise e
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright (c) 2011, Julien Sobrier
5
+ #
6
+ # This file is part of printio released under MIT license.
7
+ # See the LICENSE for more information.
@@ -0,0 +1,452 @@
1
+ #!/usr/bin/env python
2
+ # -*- coding: utf-8 -*-
3
+ #
4
+ # Copyright (c) Julien Sobrier
5
+ #
6
+ # This file is part of printio released under MIT license.
7
+ # See the LICENSE for more information.
8
+ """
9
+
10
+ Test the library.
11
+
12
+ """
13
+
14
+ import os
15
+ import sys
16
+ import unittest
17
+ #import datetime
18
+
19
+ libpath = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
20
+ if not libpath in sys.path:
21
+ sys.path.insert(1, libpath)
22
+ del libpath
23
+
24
+ from browshot import BrowshotClient
25
+
26
+
27
+ class BrowshotClient_ParseTestCase(unittest.TestCase):
28
+ def setUp(self):
29
+ self.client = BrowshotClient('vPTtKKLBtPUNxVwwfEKlVvekuxHyTXyi')
30
+ #self.client.debug = 1
31
+
32
+
33
+ def test_api_version(self):
34
+ self.assertEquals('1.12', self.client.api_version())
35
+
36
+ def test_simple(self):
37
+ data = self.client.simple('http://mobilito.net/', {'cache': 60 * 60 * 24 * 365})
38
+ #data = self.client.simple({'url': 'http://mobilito.net'})
39
+ self.assertEquals(200, data['code'])
40
+ self.assertEquals(True, len(data['png']) > 0)
41
+
42
+ # Fail
43
+ data = self.client.simple('')
44
+ self.assertEquals(400, data['code'])
45
+ self.assertEquals('', data['png'])
46
+
47
+
48
+ #def test_simple_file(self):
49
+ #data = self.client.simple_file('http://mobilito.net/', '/tmp/mobilito.png', {'cache': 60 * 60 * 24 * 365})
50
+ #self.assertEquals(200, data['code'])
51
+ #self.assertEquals('/tmp/mobilito.png', data['file'])
52
+
53
+
54
+ def test_instance_list(self):
55
+ instances = self.client.instance_list()
56
+
57
+ self.assertEquals(True, 'free' in instances)
58
+ self.assertEquals(True, len(instances['free']) > 0)
59
+
60
+ self.assertEquals(True, 'shared' in instances)
61
+ self.assertEquals(True, len(instances['shared']) > 0)
62
+
63
+ self.assertEquals(True, 'private' in instances)
64
+ self.assertEquals(0, len(instances['private']))
65
+
66
+ free = instances['free'][0]
67
+ self.assertEquals(True, 'id' in free)
68
+ self.assertEquals(True, 'width' in free)
69
+ self.assertEquals(True, 'height' in free)
70
+ self.assertEquals(True, 'load' in free)
71
+ self.assertEquals(True, 'browser' in free)
72
+ self.assertEquals(True, 'id' in free['browser'])
73
+ self.assertEquals(True, 'name' in free['browser'])
74
+ self.assertEquals(True, 'javascript' in free['browser'])
75
+ self.assertEquals(True, 'flash' in free['browser'])
76
+ self.assertEquals(True, 'mobile' in free['browser'])
77
+ self.assertEquals(True, 'type' in free)
78
+ self.assertEquals(True, 'screenshot_cost' in free)
79
+ self.assertEquals(0, int(free['screenshot_cost']))
80
+
81
+
82
+ def test_instance_info(self):
83
+ instances = self.client.instance_list()
84
+ free = instances['free'][0]
85
+
86
+ instance = self.client.instance_info(free['id'])
87
+ self.assertEquals(free['id'], instance['id'])
88
+ self.assertEquals(free['width'], instance['width'])
89
+ self.assertEquals(free['height'], instance['height'])
90
+ self.assertEquals(free['load'], instance['load'])
91
+ self.assertEquals(free['browser']['id'], instance['browser']['id'])
92
+ self.assertEquals(free['browser']['name'], instance['browser']['name'])
93
+ self.assertEquals(free['browser']['javascript'], instance['browser']['javascript'])
94
+ self.assertEquals(free['browser']['flash'], instance['browser']['flash'])
95
+ self.assertEquals(free['browser']['mobile'], instance['browser']['mobile'])
96
+ self.assertEquals(free['type'], instance['type'])
97
+ self.assertEquals(free['screenshot_cost'], instance['screenshot_cost'])
98
+
99
+
100
+ def test_instance_info_wrong(self):
101
+ instance = self.client.instance_info(-1)
102
+
103
+ self.assertEquals(True, 'error' in instance)
104
+ self.assertEquals(True, 'status' in instance)
105
+
106
+
107
+ def test_instance_create_wrong(self):
108
+ instance = self.client.instance_create({'width': 3000})
109
+ self.assertEquals(True, 'error' in instance)
110
+
111
+ instance = self.client.instance_create({'height': 3000})
112
+ self.assertEquals(True, 'error' in instance)
113
+
114
+ instance = self.client.instance_create({'browser_id': -1})
115
+ self.assertEquals(True, 'error' in instance)
116
+
117
+ # Option disabled for most accounts
118
+ def test_instance_create(self):
119
+ instance = self.client.instance_create()
120
+ self.assertEquals(True, 'error' in instance)
121
+ #self.assertEquals(True, 'id' in instance)
122
+ #self.assertEquals(True, 'width' in instance)
123
+ #self.assertEquals(True, 'height' in instance)
124
+ #self.assertEquals(1, int(instance['active']))
125
+ #self.assertEquals(True, 'browser' in instance)
126
+ #self.assertEquals(True, 'id' in instance['browser'])
127
+
128
+
129
+ def test_browser_list(self):
130
+ browsers = self.client.browser_list()
131
+ self.assertEquals(True, len(browsers.keys()) > 0)
132
+
133
+ browser_id = browsers.keys()[0]
134
+ self.assertEquals(True, browser_id > 0)
135
+
136
+ browser = browsers[browser_id]
137
+ self.assertEquals(True, 'name' in browser)
138
+ self.assertEquals(True, 'user_agent' in browser)
139
+ self.assertEquals(True, 'appname' in browser)
140
+ self.assertEquals(True, 'vendorsub' in browser)
141
+ self.assertEquals(True, 'appcodename' in browser)
142
+ self.assertEquals(True, 'platform' in browser)
143
+ self.assertEquals(True, 'vendor' in browser)
144
+ self.assertEquals(True, 'appversion' in browser)
145
+ self.assertEquals(True, 'javascript' in browser)
146
+ self.assertEquals(True, 'mobile' in browser)
147
+ self.assertEquals(True, 'flash' in browser)
148
+
149
+
150
+ # Option disabled for most accounts
151
+ def test_browser_create(self):
152
+ browser = self.client.browser_create({'mobile': 1, 'flash': 1, 'user_agent': 'test'});
153
+ self.assertEquals(True, 'error' in browser)
154
+ #self.assertEquals(True, 'name' in browser)
155
+ #self.assertEquals(True, 'user_agent' in browser)
156
+ #self.assertEquals(True, 'appname' in browser)
157
+ #self.assertEquals(True, 'vendorsub' in browser)
158
+ #self.assertEquals(True, 'appcodename' in browser)
159
+ #self.assertEquals(True, 'platform' in browser)
160
+ #self.assertEquals(True, 'vendor' in browser)
161
+ #self.assertEquals(True, 'appversion' in browser)
162
+ #self.assertEquals(True, 'javascript' in browser)
163
+ #self.assertEquals(True, 'mobile' in browser)
164
+ #self.assertEquals(True, 'flash' in browser)
165
+
166
+ def test_screenshot_create_wrong(self):
167
+ screenshot = self.client.screenshot_create()
168
+ self.assertEquals(True, 'error' in screenshot)
169
+
170
+ screenshot = self.client.screenshot_create('-')
171
+ self.assertEquals(True, 'error' in screenshot)
172
+
173
+
174
+ def test_screenshot_create(self):
175
+ screenshot = self.client.screenshot_create('http://browshot.com/')
176
+
177
+ self.assertEquals(True, 'id' in screenshot)
178
+ self.assertEquals(True, 'status' in screenshot)
179
+ self.assertEquals(True, 'priority' in screenshot)
180
+
181
+ if screenshot['status'] == 'finished':
182
+ self.assertEquals(True, 'screenshot_url' in screenshot)
183
+ self.assertEquals(True, 'url' in screenshot)
184
+ self.assertEquals(True, 'size' in screenshot)
185
+ self.assertEquals(True, 'width' in screenshot)
186
+ self.assertEquals(True, 'height' in screenshot)
187
+ self.assertEquals(True, 'request_time' in screenshot)
188
+ self.assertEquals(True, 'started' in screenshot)
189
+ self.assertEquals(True, 'load' in screenshot)
190
+ self.assertEquals(True, 'content' in screenshot)
191
+ self.assertEquals(True, 'finished' in screenshot)
192
+ self.assertEquals(True, 'instance_id' in screenshot)
193
+ self.assertEquals(True, 'response_code' in screenshot)
194
+ self.assertEquals(True, 'final_url' in screenshot)
195
+ self.assertEquals(True, 'content_type' in screenshot)
196
+ self.assertEquals(True, 'scale' in screenshot)
197
+ self.assertEquals(True, 'cost' in screenshot)
198
+
199
+
200
+ def test_screenshot_info_wrong(self):
201
+ screenshot = self.client.screenshot_info()
202
+ self.assertEquals(True, 'error' in screenshot)
203
+
204
+
205
+ def test_screenshot_info(self):
206
+ screenshot = self.client.screenshot_create('http://browshot.com/')
207
+ info = self.client.screenshot_info(screenshot['id'])
208
+
209
+ self.assertEquals(True, 'id' in info)
210
+ self.assertEquals(True, 'status' in info)
211
+ self.assertEquals(True, 'priority' in info)
212
+
213
+ if info['status'] == 'finished':
214
+ self.assertEquals(True, 'screenshot_url' in info)
215
+ self.assertEquals(True, 'url' in info)
216
+ self.assertEquals(True, 'size' in info)
217
+ self.assertEquals(True, 'width' in info)
218
+ self.assertEquals(True, 'height' in info)
219
+ self.assertEquals(True, 'request_time' in info)
220
+ self.assertEquals(True, 'started' in info)
221
+ self.assertEquals(True, 'load' in info)
222
+ self.assertEquals(True, 'content' in info)
223
+ self.assertEquals(True, 'finished' in info)
224
+ self.assertEquals(True, 'instance_id' in info)
225
+ self.assertEquals(True, 'response_code' in info)
226
+ self.assertEquals(True, 'final_url' in info)
227
+ self.assertEquals(True, 'content_type' in info)
228
+ self.assertEquals(True, 'scale' in info)
229
+ self.assertEquals(True, 'cost' in info)
230
+ self.assertEquals(False, 'images' in info)
231
+ self.assertEquals(False, 'scripts' in info)
232
+
233
+ def test_screenshot_info_0(self):
234
+ screenshot = self.client.screenshot_create('http://browshot.com/')
235
+ info = self.client.screenshot_info(screenshot['id'], { 'details' : 0 })
236
+
237
+ self.assertEquals(True, 'id' in info)
238
+ self.assertEquals(True, 'status' in info)
239
+ self.assertEquals(True, 'priority' in info)
240
+
241
+ if info['status'] == 'finished':
242
+ self.assertEquals(True, 'screenshot_url' in info)
243
+ self.assertEquals(True, 'url' in info)
244
+ self.assertEquals(True, 'size' in info)
245
+ self.assertEquals(True, 'width' in info)
246
+ self.assertEquals(True, 'height' in info)
247
+ self.assertEquals(True, 'instance_id' in info)
248
+ self.assertEquals(True, 'final_url' in info)
249
+ self.assertEquals(True, 'scale' in info)
250
+ self.assertEquals(True, 'cost' in info)
251
+
252
+ self.assertEquals(False, 'response_code' in info)
253
+ self.assertEquals(False, 'content_type' in info)
254
+
255
+ self.assertEquals(False, 'started' in info)
256
+ self.assertEquals(False, 'finished' in info)
257
+ self.assertEquals(False, 'load' in info)
258
+ self.assertEquals(False, 'request_time' in info)
259
+ self.assertEquals(False, 'content' in info)
260
+
261
+ self.assertEquals(False, 'images' in info)
262
+ self.assertEquals(False, 'scripts' in info)
263
+ self.assertEquals(False, 'iframes' in info)
264
+
265
+ def test_screenshot_info_1(self):
266
+ screenshot = self.client.screenshot_create('http://browshot.com/')
267
+ info = self.client.screenshot_info(screenshot['id'], { 'details' : 1 })
268
+
269
+ self.assertEquals(True, 'id' in info)
270
+ self.assertEquals(True, 'status' in info)
271
+ self.assertEquals(True, 'priority' in info)
272
+
273
+ if info['status'] == 'finished':
274
+ self.assertEquals(True, 'screenshot_url' in info)
275
+ self.assertEquals(True, 'url' in info)
276
+ self.assertEquals(True, 'size' in info)
277
+ self.assertEquals(True, 'width' in info)
278
+ self.assertEquals(True, 'height' in info)
279
+ self.assertEquals(True, 'instance_id' in info)
280
+ self.assertEquals(True, 'final_url' in info)
281
+ self.assertEquals(True, 'scale' in info)
282
+ self.assertEquals(True, 'cost' in info)
283
+
284
+ self.assertEquals(True, 'response_code' in info)
285
+ self.assertEquals(True, 'content_type' in info)
286
+
287
+ self.assertEquals(False, 'started' in info)
288
+ self.assertEquals(False, 'finished' in info)
289
+ self.assertEquals(False, 'load' in info)
290
+ self.assertEquals(False, 'request_time' in info)
291
+ self.assertEquals(False, 'content' in info)
292
+
293
+ self.assertEquals(False, 'images' in info)
294
+ self.assertEquals(False, 'scripts' in info)
295
+ self.assertEquals(False, 'iframes' in info)
296
+
297
+ def test_screenshot_info_2(self):
298
+ screenshot = self.client.screenshot_create('http://browshot.com/')
299
+ info = self.client.screenshot_info(screenshot['id'], { 'details' : 2 })
300
+
301
+ self.assertEquals(True, 'id' in info)
302
+ self.assertEquals(True, 'status' in info)
303
+ self.assertEquals(True, 'priority' in info)
304
+
305
+ if info['status'] == 'finished':
306
+ self.assertEquals(True, 'screenshot_url' in info)
307
+ self.assertEquals(True, 'url' in info)
308
+ self.assertEquals(True, 'size' in info)
309
+ self.assertEquals(True, 'width' in info)
310
+ self.assertEquals(True, 'height' in info)
311
+ self.assertEquals(True, 'instance_id' in info)
312
+ self.assertEquals(True, 'final_url' in info)
313
+ self.assertEquals(True, 'scale' in info)
314
+ self.assertEquals(True, 'cost' in info)
315
+
316
+ self.assertEquals(True, 'response_code' in info)
317
+ self.assertEquals(True, 'content_type' in info)
318
+
319
+ self.assertEquals(True, 'started' in info)
320
+ self.assertEquals(True, 'finished' in info)
321
+ self.assertEquals(True, 'load' in info)
322
+ self.assertEquals(True, 'request_time' in info)
323
+ self.assertEquals(True, 'content' in info)
324
+
325
+ self.assertEquals(False, 'images' in info)
326
+ self.assertEquals(False, 'scripts' in info)
327
+ self.assertEquals(False, 'iframes' in info)
328
+
329
+ #def test_screenshot_info_3(self):
330
+ #screenshot = self.client.screenshot_create('http://browshot.com/')
331
+ #info = self.client.screenshot_info(screenshot['id'], { 'details' : 3 })
332
+
333
+ #self.assertEquals(True, 'id' in info)
334
+ #self.assertEquals(True, 'status' in info)
335
+ #self.assertEquals(True, 'priority' in info)
336
+
337
+ #if info['status'] == 'finished':
338
+ #self.assertEquals(True, 'screenshot_url' in info)
339
+ #self.assertEquals(True, 'url' in info)
340
+ #self.assertEquals(True, 'size' in info)
341
+ #self.assertEquals(True, 'width' in info)
342
+ #self.assertEquals(True, 'height' in info)
343
+ #self.assertEquals(True, 'instance_id' in info)
344
+ #self.assertEquals(True, 'final_url' in info)
345
+ #self.assertEquals(True, 'scale' in info)
346
+ #self.assertEquals(True, 'cost' in info)
347
+
348
+ #self.assertEquals(True, 'response_code' in info)
349
+ #self.assertEquals(True, 'content_type' in info)
350
+
351
+ #self.assertEquals(True, 'started' in info)
352
+ #self.assertEquals(True, 'finished' in info)
353
+ #self.assertEquals(True, 'load' in info)
354
+ #self.assertEquals(True, 'request_time' in info)
355
+ #self.assertEquals(True, 'content' in info)
356
+
357
+ #self.assertEquals(True, 'images' in info)
358
+ #self.assertEquals(True, 'scripts' in info)
359
+ #self.assertEquals(True, 'iframes' in info)
360
+
361
+
362
+ def test_screenshot_list(self):
363
+ screenshots = self.client.screenshot_list()
364
+ self.assertEquals(True, len(screenshots.keys()) > 0)
365
+
366
+ screenshot_id = screenshots.keys()[0]
367
+ self.assertEquals(True, screenshot_id > 0)
368
+
369
+ screenshot = screenshots[screenshot_id]
370
+
371
+ self.assertEquals(True, 'id' in screenshot)
372
+ self.assertEquals(True, 'status' in screenshot)
373
+ self.assertEquals(True, 'priority' in screenshot)
374
+
375
+ if screenshot['status'] == 'finished':
376
+ self.assertEquals(True, 'screenshot_url' in screenshot)
377
+ self.assertEquals(True, 'url' in screenshot)
378
+ self.assertEquals(True, 'size' in screenshot)
379
+ self.assertEquals(True, 'width' in screenshot)
380
+ self.assertEquals(True, 'height' in screenshot)
381
+ self.assertEquals(True, 'request_time' in screenshot)
382
+ self.assertEquals(True, 'started' in screenshot)
383
+ self.assertEquals(True, 'load' in screenshot)
384
+ self.assertEquals(True, 'content' in screenshot)
385
+ self.assertEquals(True, 'finished' in screenshot)
386
+ self.assertEquals(True, 'instance_id' in screenshot)
387
+ self.assertEquals(True, 'response_code' in screenshot)
388
+ self.assertEquals(True, 'final_url' in screenshot)
389
+ self.assertEquals(True, 'content_type' in screenshot)
390
+ self.assertEquals(True, 'scale' in screenshot)
391
+ self.assertEquals(True, 'cost' in screenshot)
392
+
393
+
394
+ def test_thumbnail(self):
395
+ screenshots = self.client.screenshot_list()
396
+ self.assertEquals(True, len(screenshots.keys()) > 0)
397
+
398
+ screenshot_id = screenshots.keys()[0]
399
+ self.assertEquals(True, screenshot_id > 0)
400
+
401
+ thumbnail = self.client.screenshot_thumbnail(screenshot_id)
402
+ self.assertEquals(True, thumbnail != '')
403
+ self.assertEquals('PNG', thumbnail[1:4])
404
+
405
+
406
+ def test_screenshot_share(self):
407
+ share = self.client.screenshot_host(0)
408
+ self.assertEquals('error', share['status'])
409
+
410
+
411
+ def test_hosting(self):
412
+ screenshots = self.client.screenshot_list()
413
+ self.assertEquals(True, len(screenshots.keys()) > 0)
414
+
415
+ screenshot_id = screenshots.keys()[0]
416
+ self.assertEquals(True, screenshot_id > 0)
417
+
418
+ hosting = self.client.screenshot_host(screenshot_id)
419
+ self.assertEquals('error', hosting['status'])
420
+
421
+ hosting = self.client.screenshot_host(screenshot_id, { 'hosting' : 'browshot' })
422
+ self.assertEquals('error', hosting['status'])
423
+
424
+ hosting = self.client.screenshot_host(screenshot_id, { 'hosting' : 's3' })
425
+ self.assertEquals('error', hosting['status'])
426
+
427
+ hosting = self.client.screenshot_host(screenshot_id, { 'hosting' : 's3', 'bucket' : 'mine' })
428
+ self.assertEquals('error', hosting['status'])
429
+
430
+ hosting = self.client.screenshot_host(screenshot_id, { 'hosting' : 'cdn' })
431
+ self.assertEquals('error', hosting['status'])
432
+
433
+
434
+ def test_account_info(self):
435
+ account = self.client.account_info()
436
+
437
+ self.assertEquals(True, 'balance' in account)
438
+ self.assertEquals(0, int(account['balance']))
439
+ self.assertEquals(True, 'active' in account)
440
+ self.assertEquals(1, int(account['active']))
441
+ #self.assertEquals(True, 'instances' in account)
442
+
443
+ def test_account_info_wrong(self):
444
+ client = BrowshotClient()
445
+ client.debug = True
446
+ account = client.account_info()
447
+
448
+ self.assertEquals(True, 'error' in account)
449
+
450
+
451
+ if __name__ == "__main__":
452
+ unittest.main()