I'm creating an API using Tipfy. I have an existing suite that tests some methods I will expose via URL, but what I'd like to do is see exactly how these functions will work once they're exposed. I'd like to test the URL params directly, for example.
I think what I need is something like wsgi_intercept. It uses a function that
returns a WSGI app to run its tests so you don't have to run a web server in parallel; it bootstraps it for you in the setUp function. There's an example at http://ivory.idyll.org/articles/twill-and-wsgi_intercept.html, but I'm not sure how to do it with Tipfy.
What call to the Tipfy library will return the WSGI application itself? Tipfy.wsgi_app?
If there is another testing strategy or tool that you can suggest, I'd also appreciate that.
Thanks!
Use easy_install to install wsgi_intercept, then get hold of the Tipfy app via make_wsgi_app.
import config
import tipfy
app = tipfy.make_wsgi_app(config.config)
# Enable the interception of HTTP calls.
from wsgi_intercept.urllib2_intercept import install_opener
install_opener()
wsgi_intercept.add_wsgi_intercept('localhost', 8000, lambda: app)
Related
I have a pretty standard express app, built using the express-generator. Now, I would like to automate some of the things in the app with hubot and I have managed to successfully perform testing and run hubot with slack adapter. However, I would like to have the bot be a part of a regular app.
How can I change the structure of the app (I have a pretty standard import of routes.js which has all of the routes for the app) to allow for the two to run together?
This is running on azure as a WebApp and I have set up a continuous integration with GitHub, so I pretty much just push code and it gets deployed, I don't run anything manually on the actual server. I would be able to run the hubot and server it on a different subdomain or path on the app if it was a regular VPS, but since the azure is taking care of those things, I would need the hubot somehow baked-in the actual express app.
As I know, Hubot has a build-in express web framework that can serve HTTP requests. So theoretically you can integrate hubot with your express webapp thru the router dispatch different urls between express app and hubot.
As references, there is a experimental package project hubot-express shows that hubot as a express app startup. you can try to refer to the code https://github.com/hubot-scripts/hubot-express/blob/master/src/hubot-express.coffee to implement the integration.
The key code: robot.express = app = express();
And the article "Automation and Monitoring with Hubot" show the code that how to serving http requests, please move to https://leanpub.com/automation-and-monitoring-with-hubot/read#leanpub-auto-serving-http-requests to review it.
The key code: robot.router.post('/hubot/notify/:room', function(req, res) {...});
To add to this, in the end I moved to botkit library that provides way easier and integrated way to have both the server and the actual app.
I'm playing with combining a couple flask apis that I have into one application that can be a little easier to deploy and set up for devs instead of needing three separate applications running. Currently each api resides on a separate port. I'm trying to use the DispatcherMiddleware to run all three applications but so far it seems like you can only use prefixes like
from frontend import app as frontend
from TestApi import app as test
from DevApi import app as dev
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware
app = DispatcherMiddleware(frontend, {
'/test': test,
'/dev': dev
})
run_simple('localhost', 4000, app, use_reloader=True)
now all my services run on 4000 but what id like to have is something like this
from frontend import app as frontend
from TestApi import app as test
from DevApi import app as dev
from werkzeug.serving import run_simple
from werkzeug.wsgi import DispatcherMiddleware
app = DispatcherMiddleware(frontend, {
':5000': test,
':6000': dev
})
#frontend runs on 4000, test runs on 5000, dev runs on 6000
run_simple('localhost', 4000, app, use_reloader=True)
Am I just asking for something that makes no sense or is there a way to accomplish using this or another setup.
I've come to the conclusion that this is a stupid idea that is very fragile and requires a lot of unnecessary complexity. I've instead just opted to write a bash script that starts all the apps as separate wsgi instances on their own port.
The Flask documentation on application dispatching contains no hint on port based dispatching. As you mentioned you can simply start separate wsgi instances, as far as I know this is the only possible way using Werkzeug.
Reference: http://flask.pocoo.org/docs/latest/patterns/appdispatch/
I'm using ember-cli with Firebase for my data. I also have a simple server file I created with http-mock that handles some processes for Twilio. Is there a way to use that http-mock as an actual server on Heroku? I have found an embercli stack for heroku but I'm not sure how to make that use the server file I have:
https://github.com/tonycoco/heroku-buildpack-ember-cli
Thank you in advance for the help.
I believe that build pack just deploys your app's static files to Heroku.
The http-mock file you're working with within Ember CLI is a Node Express app. So, you'd need to host it on a server that can serve node apps somewhere.
In theory you could write a script that does that (deploys it separately) while keeping it within your main repo, but like others have said that's probably not a good idea.
In the future, though, you probably will be able to use http-mocks both for clicking around your app with ember serve, and for use in your tests.
I'm starting to introduce Selenium tests to my website that is written in Django. The browser that is controlled by Selenium needs some server to connect. So far I just run my full application in a separate process, but this is painful.
I'd like to run some mock HTTP server, make it serve all the necessary static files and render Django templates and return mock responses to some specific requests.
How would you do that?
Can you not run Selenium over django dev server http://localhost:8000/ .
If not perhaps worth looking at http://harry.pythonanywhere.com/ .where there are some good resources
The best thing is to integrate selenium tests into your unit test suite. When Django 1.4 comes out this will be a supported feature, where the Django test runner will run a development HTTP server for you while the tests run, and load all of your test fixtures for you:
support-for-in-browser-testing-frameworks
LiveServerTestCase
Likely you can't wait until the 1.4 release. In the meantime, you can use something called django-nose-selenium to do this:
https://github.com/weluse/django-nose-selenium
There's a good comprehensive guide on how to do this here:
http://timescapers.com/2011/08/27/django-nose-selenium-a-concise-tutorial/
If I may plug-plug my own tutorial, which will allow you to do full selenium testing against the django test server
http://www.tdd-django-tutorial.com/
I would like to build a new application using node.js but it requires quite a bit of backend management that I would rather not have to build. I have some existing code in django and really like the built in Admin interface for handling the backend management.
Is it possible for me to use something like nginx to direct all traffic to my node.js application except when the url path starts with /admin in which case it would direct the traffic to django?
Alternatively is there something like the admin interface for any of the node.js frameworks for certain databases?
Thanks.
Yes, you can do that.
It might be easier to just put your django admin app on a subdomain, django.example.com.
I'm using Django admin interface with a legacy PHP application. I found out I could build a nicer admin in just a few hours, than the special built one. The frontend is still obviously using PHP and the old code, but I just swapped out the entire admin backend which is now run on django against the database.
It's very nice indeed.
If you are already using Node.js, you might want to look into node-http-proxy which can redirect requests to different places based on the route. It's very easy to setup and runs very fast from my experience.