예제 #1
0
    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
예제 #2
0
파일: __init__.py 프로젝트: corydodt/Noms
"""
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"]
예제 #3
0
def configGood():
    return fromdir(__file__)('test_config.yml')
예제 #4
0
def configBad():
    return fromdir(__file__)('test_config_bad.yml')
예제 #5
0
def schemaFile():
    return fromdir(__file__)('test_config.schema.yml')
예제 #6
0
def recipePageHTML():
    return open(fromdir(__file__)('recipe_page_source.html')).read()
예제 #7
0
def options():
    options = ValidateYAML()
    options['yamlSchema'] = fromdir(__file__)('test_config.schema.yml')
    return options
예제 #8
0
def testdir():
    return fromdir(__file__)('test_digester')
예제 #9
0
"""
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