我在python中使用Google App Engine设置项目.
目前它看起来像这样
class MainPage(webapp2.RequestHandler):
def get(self):
self.response.headers['Content-Type'] = 'text/plain'
self.response.write('Hello World!')
application = webapp2.WSGIApplication([
('/', MainPage),
], debug=True)
Run Code Online (Sandbox Code Playgroud)
我试图学习如何使用TDD方式,所以我通过Google 测试了get以下这个例子.
它有这个测试用例
def test_MainPage_get(self):
response = self.testapp.get('/')
self.assertEqual(response.status_int, 200)
Run Code Online (Sandbox Code Playgroud)
效果很好,按预期返回200.然后我想我也应该测试post一下.我试着像这样测试它
def test_MainPage_post(self):
response = self.testapp.post('/')
self.assertEqual(response.status_int, 405)
Run Code Online (Sandbox Code Playgroud)
因为post没有实现,我希望它返回状态405和测试用例来报告成功.然而,控制台显示此并退出
The method POST is not allowed for this resouce.
------------------------------------------------
Ran 2 tests in 0.003s
FAILED (errors=1)
Run Code Online (Sandbox Code Playgroud)
为什么它停在那里而不是将405返回到我的测试用例?我做错了吗?是否有其他(更好)的方法来测试method not allowed代码?
拥有App Engine项目的其他人将我添加为编辑.我们已经不再联系了,我仍然得到了许可.有没有办法从列表中删除自己?
我正在尝试创建测试以验证我的实体是否正在保存在数据库中.当我在post函数中放置断点时,我可以看到保存记录后客户计数发生了变化.我阅读了https://cloud.google.com/appengine/docs/python/tools/localunittesting#Python_Writing_High_Replication_Datastore_tests
根据我的理解,由于最终的一致性,测试失败了,解决这个问题的方法是改变PseudoRandomHRConsistencyPolicy设置.
policy = datastore_stub_util.PseudoRandomHRConsistencyPolicy(probability=1)
Run Code Online (Sandbox Code Playgroud)
当我再次运行测试时,我得到了同样的错误.
创建这些测试我做错了什么?
> /Users/Bryan/work/GoogleAppEngine/dermalfillersecrets/main.py(137)post()
-> customer.put()
(Pdb) l
134 query = Customer.query()
135 orig_customer_count = query.count()
136 import pdb; pdb.set_trace()
137 -> customer.put()
138 import pdb; pdb.set_trace()
139 query_params = {'leadbook_name': leadbook_name}
140 self.redirect('/?' + urllib.urlencode(query_params))
141
142 config = {}
(Pdb) orig_customer_count
5
(Pdb) c
> /Users/Bryan/work/GoogleAppEngine/dermalfillersecrets/main.py(139)post()
-> query_params = {'leadbook_name': leadbook_name}
(Pdb) l
134 query = Customer.query()
135 orig_customer_count = query.count()
136 import pdb; pdb.set_trace()
137 customer.put()
138 import pdb; pdb.set_trace()
139 …Run Code Online (Sandbox Code Playgroud) python google-app-engine selenium-webdriver google-cloud-datastore nose-gae
我的申请流程如下: -
我认为这是因为数据存储区需要进行一些数据复制,因此在返回Put(..)函数后,新插入的数据不会立即可用.我该怎么办这个问题或者我需要使用交易?
好吧,我试过并得到服务器500错误.
我的应用有时必须保存超过500个字符.有什么建议吗?
使用Go btw.
PS:我之前总是使用MySQL.所以这个App Engine数据存储区对我来说非常新.
我正在进入云计算领域,但我真的很困惑它是什么意思。
在编程中,您可以在调用对象时调用实例,对于 Machine 来说,它是一个服务器,但在这里我可以说它不同,这就是我感到困惑的地方。
所以基本上我需要了解的是: - 每小时一个实例是多少?- 它是如何工作的?- 如果我有一个应用程序(网络应用程序),我如何衡量一个实例,以计算每小时定价?
有人可以尽可能简单地向我解释这一点吗?谷歌上的教程太多了,但仍然没有得到
谢谢, ;)
更新:我发现这篇文章“实例”在云计算方面意味着什么? 这很有用,因为有人回答了我需要理解的内容:
Run Code Online (Sandbox Code Playgroud)For App Engine it's not a VM; it's a process. – Guido van Rossum Aug 21 '12 at 3:38
那么如何按流程计算呢?
我想问一下,我试着打电话webapp.RequestHandler,但这个处理程序没有调用:这是compress.py页面:
from __future__ import with_statement
from google.appengine.api import files
import cgi, cgitb ; cgitb.enable()
import StringIO
import zipfile
from google.appengine.ext import blobstore
from google.appengine.ext import webapp
from google.appengine.ext.webapp import blobstore_handlers
from google.appengine.ext.webapp.util import run_wsgi_app
class zip(webapp.RequestHandler):
def z(self):
form = cgi.FieldStorage()
zipstream=StringIO.StringIO()
zfile = zipfile.ZipFile(file=zipstream,mode="w",compression=zipfile.ZIP_DEFLATED)
file_upload = form['file[]']
data=file_upload.file.read()
filename2 = file_upload.filename
zfile.writestr(filename2,data)
zfile.close()
zipstream.seek(0)
zip_file = files.blobstore.create(mime_type='application/zip',_blobinfo_uploaded_filename='test.zip')
with files.open(zip_file, 'a') as f:
f.write(zipstream.getvalue())
files.finalize(zip_file)
blob_key = files.blobstore.get_blob_key(zip_file)
self.response.out.write('<a href="download.py?key=%s">get zip</a>' %blob_key)
def main():
application = webapp.WSGIApplication( [(r'/compress.py', …Run Code Online (Sandbox Code Playgroud)