Exemple #1
0
def mockConfig(mockDatabase):
    """
    Wrap a fake config object into each test request along with a mock database
    """
    # in tests, we replace the global CONFIG without patching it
    import noms

    try:
        cols = mockDatabase.collection_names()
        for c in cols:  # pragma: nocover
            assert mockDatabase[c].count() == 0, c + " not empty"

        cfg = noms.Config()
        descr = describe.Description()
        descr.public_hostname = ('cli', 'app.nomsbook.com')
        cfg.description = descr
        cfg.staticHash = 'asdfasdfsdaf'

        from noms import secret
        secret.put('auth0', 'abc123', 'ABC!@#')
        secret.put('localapi', 'localapi', '!@#ABC')

        with patch.object(noms, 'CONFIG', cfg):
            yield cfg

    finally:
        # despite dropping the database we have to do this, because it's
        # still an object in memory
        for c in cols:  # pragma: nocover
            col = mockDatabase[c]
            col.remove()
            assert col.count() == 0, "%r not empty" % c
Exemple #2
0
def test_buildDescriptionBadGit(gitRepo):
    """
    Do I bail out if `git describe` is unexpectedly malformatted?
    """
    pRepo = patch.object(describe, 'Repo', gitRepo)
    with raises(ValueError), pRepo:
        descr = describe.Description()
        descr.build()
Exemple #3
0
def description():
    """
    A noms Description with some prefilled details
    """
    return describe.Description(
        NOMS_VERSION=('git describe', 'asdf-10-g0g4v39x'),
        NOMS_DB_HOST=('process environment', 'manga'),
        certbot_flags=('nomstag', '--staging'),
        certbot_email=('nomstag', '*****@*****.**'),
        public_hostname=('local.env', 'hello.world'),
        proxy_hostname=('cli', 'noms-main'),
        proxy_port=('cli', '9090'),
    )
Exemple #4
0
def test_buildDescription(description, nomsTag, gitRepo,
                          readEnvironmentFileFake):
    """
    Do I integrate the 5 sources of information correctly?
    """
    expected = description
    pEnv = patch.dict(os.environ, {
        'TRAVIS_COMMIT_MESSAGE': nomsTag,
        'NOMS_DB_HOST': 'manga',
    },
                      clear=True)
    pRepo = patch.object(describe, 'Repo', gitRepo)
    pReadEnv = patch.object(describe, 'readEnvironmentFile',
                            readEnvironmentFileFake)
    pExists = patch.object(os.path, 'exists', return_value=True)
    with pEnv, pRepo, pReadEnv, pExists:
        descr = describe.Description()
        actual = descr.build({'proxy_port': '9090'})

    assert actual == expected
Exemple #5
0
def test_buildDescriptionBadNomsTag(description, gitRepo,
                                    readEnvironmentFileFake):
    """
    Do I ignore TRAVIS_COMMIT_MESSAGE if it's not a real nomstag?

    (i.e. nomstag:true is not part of the json)
    """
    description.certbot_flags = ('cli', '')
    description.certbot_email = ('cli', '*****@*****.**')
    description.NOMS_DB_HOST = ('cli', 'mongo')
    description.public_hostname = ('local.env', 'hello.world')
    description.proxy_port = ('cli', '8080')
    pRepo = patch.object(describe, 'Repo', gitRepo)
    pEnv = patch.dict(os.environ,
                      {'TRAVIS_COMMIT_MESSAGE': '{"public_hostname": 1}'},
                      clear=True)
    pReadEnv = patch.object(describe, 'readEnvironmentFile',
                            readEnvironmentFileFake)
    with pRepo, pEnv, pReadEnv:
        descr = describe.Description()
        actual = descr.build()

    assert actual == description