def test_bookmarklet(self): """ Does api/bookmarklet fetch, save, and return a response for the recipe? """ fromTest = fromdir(__file__) loc = fromTest('recipe_page_source.html') pageSource = open(loc).read() pGet = patch.object(treq, 'get', return_value=defer.succeed(None), autospec=True) pTreqContent = patch.object(treq, 'content', return_value=defer.succeed(pageSource), autospec=True) with pGet, pTreqContent: # normal bookmarketing u = self._users()[0] req = self.requestJSON([], session_user=u) req.args['uri'] = ['http://www.foodandwine.com/recipes/poutine-style-twice-baked-potatoes'] ret = yield self.handler('bookmarklet', req) self.assertEqual(len(recipe.Recipe.objects()), 1) expectedResults = '{"status": "ok", "recipes": [{"name": "Delicious Meatless Meatballs", "urlKey": "weirdo-gmail-com-delicious-meatless-meatballs-"}], "message": ""}' assert ret == expectedResults # # not signed in to noms; bookmarketing should not be allowed req = self.requestJSON([]) req.args['uri'] = ['http://www.foodandwine.com/recipes/poutine-style-twice-baked-potatoes'] ret = yield self.handler('bookmarklet', req) expectedResults = '{"status": "error", "recipes": [], "message": "User was not logged in."}' assert ret == expectedResults
""" Noms Python library - web application """ import re from codado import fromdir, enum from pymongo.uri_parser import parse_uri fromNoms = fromdir(__file__, "..") DBHost = enum(noms={"host": "mongodb://localhost/noms"}, nomsTest={"host": "mongomock://localhost/noms-test"}) # mongomock is broken, we need to maintain our own connection aliases # See https://github.com/vmalloc/mongomock/issues/233 - we must parse # host ourselves and pass in db=, for the benefit of mongomock. DBAlias = enum.fromkeys(DBHost.keys()) def _parseHosts(): """ Build a dict of all of the connections defined by DBHost Doesn't register a default connection yet. """ for k, v in DBHost.items(): parts = parse_uri(v["host"].replace("mongomock", "mongodb")) # hack for a parse_uri restriction DBHost[k]["db"] = parts["database"]
def configGood(): return fromdir(__file__)('test_config.yml')
def configBad(): return fromdir(__file__)('test_config_bad.yml')
def schemaFile(): return fromdir(__file__)('test_config.schema.yml')
def recipePageHTML(): return open(fromdir(__file__)('recipe_page_source.html')).read()
def options(): options = ValidateYAML() options['yamlSchema'] = fromdir(__file__)('test_config.schema.yml') return options
def testdir(): return fromdir(__file__)('test_digester')
""" Noms Python library - web application """ import re import os from codado import fromdir, enum from pymongo.uri_parser import parse_uri fromNoms = fromdir(__file__, '..') NOMS_DB_HOST = os.environ.get('NOMS_DB_HOST', 'localhost') DBHost = enum( noms={'host': 'mongodb://%s/noms' % NOMS_DB_HOST}, nomsTest={'host': 'mongomock://localhost/noms-test'}, ) # mongomock is broken, we need to maintain our own connection aliases # See https://github.com/vmalloc/mongomock/issues/233 - we must parse # host ourselves and pass in db=, for the benefit of mongomock. DBAlias = enum.fromkeys(DBHost.keys()) def _parseHosts(): """ Build a dict of all of the connections defined by DBHost