class RestApiTest(tornado.testing.AsyncHTTPTestCase): nete_db = MongoDbStore('127.0.0.1', 27017, 'nete_test', 'notes') app = RestApplication(nete_db) def setUp(self): super(RestApiTest, self).setUp() self.client = tornado.httpclient.AsyncHTTPClient(self.io_loop) def tearDown(self): super(RestApiTest, self).tearDown() def get_app(self): return self.app def test_http_get_returns_saved_document(self): put_request = tornado.httpclient.HTTPRequest(self.get_url('/'), method='PUT', body='{"foo": "bar"}') self.client.fetch(put_request, self.stop) response = self.wait() json_response = json.loads(response.body) self.client.fetch(self.get_url('/%s' % json_response['_id']), self.stop) response = self.wait() json_response = json.loads(response.body) self.assertEquals({ 'foo': 'bar', '_id': json_response['_id'] }, json_response) def test_http_get_non_existing_document_returns_failure(self): self.client.fetch(self.get_url('/bar'), self.stop) response = self.wait() json_response = json.loads(response.body) self.assertEquals(False, json_response.get('success'))
def setUp(self): connection_mock = mock.MagicMock() with mock.patch('pymongo.Connection', connection_mock): self.mongodb_store = MongoDbStore('localhost', 27017, 'nete', 'documents') self.collection_mock = self.mongodb_store.collection
from nete.db.mongodb_store import MongoDbStore import logging import nete.rest.app import tornado.httpserver import tornado.ioloop import tornado.options API_PORT = 8888 WEB_PORT = 8080 if __name__ == '__main__': logging.basicConfig() logging.getLogger().setLevel(logging.DEBUG) logger = logging.getLogger(__name__) tornado.options.parse_command_line() nete_db = MongoDbStore('127.0.0.1', 27017, 'nete', 'notes') logging.info('Starting nete API server on port %d' % API_PORT) api_application = nete.rest.app.RestApplication(nete_db, debug=True) api_server = tornado.httpserver.HTTPServer(api_application) api_server.listen(API_PORT, 'localhost') #logging.info('Starting nete web server on port %d' % WEB_PORT) #web_application = nete.web.app.WebApplication(nete_db, debug=True) #web_server = tornado.httpserver.HTTPServer(web_application) #web_server.listen(WEB_PORT, '0.0.0.0') tornado.ioloop.IOLoop.instance().start()
def setUp(self): self.mongodb_store = MongoDbStore('localhost', 27017, 'nete_integration_test', 'documents')