示例#1
0
def test_anonymousAlreadyExists():
    """
    Do we return the already-existing anonymous user if it already exists?
    """
    anon = user.USER().anonymous
    new1 = user.USER().anonymous
    assert anon.id == new1.id
示例#2
0
def test_fromMicrodata(mockDatabase, recipeMicrodata, weirdo):
    """
    Does fromMicrodata create a good Recipe?
    """
    ret = recipe.Recipe.fromMicrodata(recipeMicrodata, u'*****@*****.**')
    assert ret.author == u"Cory Dodt"
    assert ret.name == u'Delicious Meatless Meatballs'
    assert ret.urlKey == u'weirdo-gmail-com-delicious-meatless-meatballs-'

    # again, but blank the author
    del recipeMicrodata.props['author']
    ret = recipe.Recipe.fromMicrodata(recipeMicrodata, u'*****@*****.**')
    assert ret.author == user.USER().anonymous.givenName
示例#3
0
def test_fromToken(mockDatabase, localapi):
    """
    Can I construct an auth token from user that returns that same user?
    """
    rq = requestJSON([], user=localapi)
    u = user.User.fromRequest(rq)
    assert u.id == localapi.id

    # Create a deliberately incorrect token and see if it fails to auth
    # (failure == anonymous user)
    rq2 = requestJSON([], requestHeaders=[('x-token', ['asdfasdf'])])
    u2 = user.User.fromRequest(rq2)
    assert u2 is user.USER().anonymous
示例#4
0
    def postOptions(self):
        """
        Connect to the noms database and make sure a config exists
        """
        alias = self['alias']
        assert alias in DBAlias
        connect(**DBHost[alias])

        # compute the current static digest hash
        staticPath = '%s/static' % os.getcwd()
        CONFIG.staticHash = digest(staticPath)

        # get secrets from aws and store them in mongo
        reactor.callWhenRunning(secret.loadFromS3)

        # store an internally-shared secret
        if not secret.get('localapi', None):
            password = secret.randomPassword()
            secret.put('localapi', 'localapi', password)
            print "Stored new localapi password"

        # ensure that at least the special users exist
        user.USER()

        # watch for changes to static files (cache busting)
        watchCL = "watchmedo shell-command --patterns='{pat}' --recursive --command='{cmd}' {where}"
        watchCL = watchCL.format(
            pat=STATIC_FILE_PATTERNS,
            cmd='whisk digester -U %s/api/sethash/ %s' %
            (FIXME_LOCALAPI_URL, staticPath),
            where=staticPath,
        )
        subprocess.Popen(shlex.split(watchCL), stdout=subprocess.PIPE)

        # run Sass
        sassCL = "node-sass -w static/scss/base.scss -o static/css"

        subprocess.Popen(shlex.split(sassCL), stdout=subprocess.PIPE)

        self.opt_class(MAIN_FUNC)

        tap.Options.postOptions(self)
示例#5
0
def specialUsers():
    """
    Preload the special users
    """
    from noms import user
    user.USER()