pyramid

How to acceptance test captcha-protected web application functionality?

拈花ヽ惹草 提交于 2019-12-10 14:19:18
问题 I would like to add a captcha, such as reCaptcha, to a certain functionality on my site. How could I adapt my acceptance tests? Is the only solution to disable the captcha's on the staging site? Clarification: Of course I am not speaking of brute-force cracking my own captcha, but e.g. some option to inject a state into the captcha from the server side that my test knows about. PS My server side code uses the Pyramid framework, and my tests are written using Selenium 回答1: The point isn't to

How to unify Python Pyramid views for handling Ajax/html form POSTs

谁都会走 提交于 2019-12-10 13:49:55
问题 I have some HTML forms in my Python Pyramid application. I'd like them to work via AJAX when JavaScript is enabled and when JavaScript is disabled. Now I use different views for AJAX and normal form posts, but the code seems almost the same for these functions, except response. I use view class like this (class body): def ajax_ok(self, msg): return Response(body=msg) def ajax_error(self, msg): return HTTPInternalServerError(body=msg) @action(xhr=True, renderer='json', name='ftp') def ftp_ajax

How to Make view_config decorator work with a Pyramid Unit Test?

扶醉桌前 提交于 2019-12-10 11:53:06
问题 I wrote a login_required decorator for the pyramid web framework. In a pyramid test server it works well. But in the Pyramid unit tests for the @view_config decorator do not work for all configurations (not only the decorator parameter). This is the code: class MyViews(object): @view_config(decorator=login_required(login_url=LOGIN_URL), match_param="action=change_password", request_method="GET", renderer="accounts/change_password.jinja2") def change_password(self): form = ChangePwdForm()

“ResourceClosedError: The transaction is closed” error with celery beat and sqlalchemy + pyramid app

梦想的初衷 提交于 2019-12-10 10:33:26
问题 I have a pyramid app called mainsite . The site works in a pretty asynchronous manner mostly through threads being launched from the view to carry out the backend operations. It connects to mysql with sqlalchemy and uses ZopeTransactionExtension for session management. So far the application has been running great. I need to run periodic jobs on it and it needs to use some of the same asynchronous functions that are being launched from the view. I used apscheduler but ran into issues with

Pyramid 1.3 and Google App Engine 1.7

混江龙づ霸主 提交于 2019-12-10 10:05:24
问题 I managed to make a Pyramid 1.2 WSGI app run on Google App Engine SDK 1.7. However, my current project uses several new Pyramid 1.3 features and I'm stuck on a WebOb version issue. Here's the error message: VersionConflict: (WebOb 1.1.1 (/home/matt/Python/google_appengine/lib/webob_1_1_1), Requirement.parse('WebOb>=1.2dev') Is there something I can do or I must wait for a new GAE release? 回答1: A fairly reliable way to manage your pyramid application and it's dependencies on appengine is via

Pyramid / SQL Alchemy DetachedInstanceError

浪尽此生 提交于 2019-12-10 08:17:47
问题 I'm trying to implement email confirmation using Pyramid framework. Here's the code that confirms the user in the database and redirects them to the home page. user = DbSession.query(User).filter_by(email=email).one() if user.approved: return {'msg': _('Already approved')} if user.check_approve_token(hash): user.approved = True self.request.session.save() self.request.session['user'] = user return HTTPFound(self.request.route_url('home'), headers=remember(self.request, user.guid)) When I try

What version of Pyramid do I have and what's the best way to update?

佐手、 提交于 2019-12-10 03:26:39
问题 I'm using Pyramid and I'm wondering how I can check what version I'm currently using. Also, how can I update my Pyramid? 回答1: To know which version of pyramid you have, you can run this in a python console : >>> import pkg_resources >>> pkg_resources.get_distribution("pyramid").version To update, you could run pip install --upgrade pyramid , but in order to update pyramid and all its dependencies, I advice you to replace your current virtualenv and replace it with a new one, with a fresh

What is the proper way to insert an object with a foreign key in SQLAlchemy?

北城以北 提交于 2019-12-10 02:48:13
问题 When using SQLAlchemy, what is the ideal way to insert an object into a table with a column that is a foreign key and then commit it? Is there anything wrong with inserting objects with a foreign in the code below? def retrieve_objects(): session = DBSession() return session.query(SomeClass).all() def insert_objects(): session = DBSession() for obj in retrieve_objects(): another_obj = AnotherClass(somefield=0) obj.someforeignkey = another_obj session.add(obj) session.flush() transaction

how can i get the ini data in pyramid?

我的梦境 提交于 2019-12-10 01:36:54
问题 There is a development.ini or production.ini in a pyramid project. I add my own config data in the ini files like: [thrift] host = 0.0.0.0 port = 8080 and I want to use the config data in one of py files in the project. How can I get the data without the request object? (I've seen a solution which uses request.) 回答1: You can access the settings at request.registry.settings or pyramid.threadlocal.get_current_registry().settings . It behaves like dictionary. If you want to use the second one,

How to unit test code that runs celery tasks?

好久不见. 提交于 2019-12-08 18:20:36
问题 The app I am working on is heavily asynchronous. The web application runs a lot of tasks through celery depending on user actions. The celery tasks themselves are capable of launching further tasks. Code such as the one shown below occurs in our code base quite frequently. def do_sth(): logic(); if condition: function1.apply_async(*args) else: function2.apply_asynch(*args) Now we want to start unit testing any new code that we write and we are not sure how to do this. What we would like to