Comments (5)
You should be able to use the API as-is in a unit test. (See the tests included with it) Are you looking for something more?
from appengine-gcs-client.
Whenever I run unit tests I get the following error:
WARNING:root:suspended generator urlfetch(context.py:1276) raised AttributeError('NoneType' object has no attribute 'storage')
WARNING:root:suspended generator urlfetch_async(rest_api.py:275) raised AttributeError('NoneType' object has no attribute 'storage')
WARNING:root:suspended generator run(api_utils.py:164) raised AttributeError('NoneType' object has no attribute 'storage')
WARNING:root:suspended generator do_request_async(rest_api.py:198) raised AttributeError('NoneType' object has no attribute 'storage')
WARNING:root:suspended generator do_request_async(storage_api.py:128) raised AttributeError('NoneType' object has no attribute 'storage')
I have set up stub for the URL fetch API:
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_urlfetch_stub()
Is there something I'm not doing that I should be?
from appengine-gcs-client.
Actually, looks like I needed to add a stub for blobstore as well:
self.testbed.init_blobstore_stub()
That fixed it.
from appengine-gcs-client.
Its possible that this issue should be closed. Unfortunately, commit 19f0768 broke this, at least for me.
When I run the tests locally using the previous commit (8f196d4), they all pass. When I run the unit tests with the current master (19f0768), I get authentication errors that seem to imply it is trying to access the real Google Cloud Storage:
$ PYTHONPATH=src python test/cloudstorage_test.py
[... lots of omitted output ...]
======================================================================
ERROR: testWriteRead (__main__.CloudStorageTest)
----------------------------------------------------------------------
Traceback (most recent call last):
File "test/cloudstorage_test.py", line 344, in testWriteRead
f = cloudstorage.open(TESTFILE, 'w')
File "/Users/evanjones/appengine-gcs-client/python/src/cloudstorage/cloudstorage_api.py", line 97, in open
return storage_api.StreamingBuffer(api, filename, content_type, options)
File "/Users/evanjones/appengine-gcs-client/python/src/cloudstorage/storage_api.py", line 705, in __init__
body=content)
File "/Users/evanjones/appengine-gcs-client/python/src/cloudstorage/errors.py", line 128, in check_status
raise AuthorizationError(msg)
AuthorizationError: Expect status [201] from Google Storage. But got status 401.
Path: '/bucket/testfile'.
Request headers: {'x-goog-resumable': 'start', 'x-goog-api-version': '2', 'accept-encoding': 'gzip, *'}.
Response headers: {'content-length': '131', 'vary': 'Origin', 'server': 'UploadServer', 'x-guploader-uploadid': 'AEnB2UpfGiScxYITfyhCg2fa5zeqqjUF7NXGAjqUFBHivErTlc_qMAWYY692o91UXeISmpvrI3RwT5aJkz6W6FLh6fDP-m8LgA', 'date': 'Wed, 05 Oct 2016 17:13:13 GMT', 'alt-svc': 'quic=":443"; ma=2592000; v="36,35,34,33,32"', 'content-type': 'application/xml; charset=UTF-8', 'www-authenticate': 'Bearer realm="https://accounts.google.com/", error="invalid_token"'}.
Body: "<?xml version='1.0' encoding='UTF-8'?><Error><Code>AuthenticationRequired</Code><Message>Authentication required.</Message></Error>".
Extra info: None.
from appengine-gcs-client.
For anyone stumbling on this, the testbed approach works fine. However, I ended up using init_all_stubs
because the test server began asking for other [unexpected] stubs, like memcache, besides the urlfetch and blobstore stubs.
Below are the relevant portions of my test:
import pickle
import cloudstorage as gcs
..
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.activate()
self.testbed.init_all_stubs()
def tearDown(self):
self.testbed.deactivate()
def testFoo(self):
xs = [('spam', 0), ('ham', 1)]
# write some sample data to the GCS stub
gcs_file = gcs.open(GCS_PATH, 'w', content_type='text/plain')
gcs_file.write(pickle.dumps(xs))
gcs_file.close()
from appengine-gcs-client.
Related Issues (20)
- Cannot import cloudstorage with demo in Pycharm?
- NOT COMPATIBLE WITH gcloud SDK maven plugin HOT 4
- Differences between appengine-gcs-client and google-cloud-storage HOT 2
- Unable to upload to download large files HOT 2
- Google cloud Storage 308 Error while writing file HOT 1
- GcsServiceOptions.java missing copyright
- Readme should point to java as well as python
- Java: cannot depend on repackaged classes form appengine API jar HOT 1
- Avoid using dependency version ranges HOT 2
- Pin specific versions in pom.xml HOT 3
- Update build instructions for Java
- Set up continuous integration
- Release 1.0 version for Java HOT 2
- Support for pip install for Python3 HOT 4
- Is there any ways to delete GCS directory in Python ? HOT 2
- README should reflect that project is no longer maintaned
- NullPointerException HOT 3
- Does Google test framework support JAVA ? or does it support only C++. If yes, what is the alternative for JAVA for testing application hosted on Google Cloud.
- Examples in GcsExampleServlet causes AppEngine standard app to crash
- Archive this project? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from appengine-gcs-client.