Example #1
0
def test_watching():
    # Enable watching
    os.environ['PYCONFIG_ETCD_WATCH'] = 'true'

    pyconfig.Config().clear()
    pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/watching')
    pyconfig.reload()

    # Wait for 20ms before writing to ensure the watcher thread is ready
    time.sleep(0.020)

    # Write a new value directly to etcd
    pyconfig.etcd().client.write('pyconfig_test/watching/it.works', 
            pytool.json.as_json(True))

    # Try to get the value... this is a bit sloppy but good luck doing
    # something better
    retry = 50
    while retry:
        retry -= 1
        if pyconfig.get('it.works', None) is not None:
            break
        # Wait 20ms more for it to show up
        time.sleep(0.020)

    eq_(pyconfig.get('it.works', False), True)
Example #2
0
def test_reload():
    with mock.patch.object(DBTest, '_new_connection') as _new_conn:
        pyconfig.reload()
        _new_conn.assert_called_once()

    # Have to reload again to get real connection instance back
    pyconfig.reload()
Example #3
0
    def reload(self):
        """
        Reloads `pyconfig <https://pypi.org/project/pyconfig/>`_ if it is
        available.

        Override this in your subclass if you wish to implement different
        reloading behavior.

        """
        if pyconfig:
            pyconfig.reload()
Example #4
0
    def reload(self):
        """
        Reloads `pyconfig <https://pypi.org/project/pyconfig/>`_ if it is
        available.

        Override this in your subclass if you wish to implement different
        reloading behavior.

        """
        if pyconfig:
            pyconfig.reload()
Example #5
0
def test_ensure_indexes_reload_hook():
    class Test(Document):
        config_database = database_name()
        config_collection = 'test'
        config_indexes = ['user_name']

        user_name = 'u'

    with DBTest:
        Test.find_one()

    eq_(Test._ensured, True)
    pyconfig.reload()
    eq_(Test._ensured, False)
Example #6
0
def test_ensure_indexes_reload_hook():
    class Test(Document):
        config_database = database_name()
        config_collection = 'test'
        config_indexes = ['user_name']

        user_name = 'u'

    with DBTest:
        Test.find_one()

    eq_(Test._ensured, True)
    pyconfig.reload()
    eq_(Test._ensured, False)
Example #7
0
def test_reload_hook():
    hook = mock.MagicMock()
    pyconfig.reload_hook(hook)
    pyconfig.reload()
    hook.assert_called_with()
Example #8
0
def test_reload_hook():
    hook = mock.MagicMock()
    pyconfig.reload_hook(hook)
    pyconfig.reload()
    hook.assert_called_with()
Example #9
0
def test_case_sensitive():
    pyconfig.set('pyconfig.case_sensitive', True)
    pyconfig.set('CaseSensitive', True)
    eq_(pyconfig.get('CaseSensitive'), True)
    eq_(pyconfig.get('casesensitive'), None)
    pyconfig.reload(clear=True)
Example #10
0
def test_autoloading_etcd_config_works():
    pyconfig.Config().clear()
    pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/test2')
    pyconfig.reload()
    eq_(pyconfig.get('pyconfig.string'), 'Value')
    eq_(pyconfig.get('pyconfig.number'), 2)
Example #11
0
def test_reload_work_with_inheritance():
    pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/test2')
    pyconfig.reload()
Example #12
0
def test_case_sensitive():
    pyconfig.set('pyconfig.case_sensitive', True)
    pyconfig.set('CaseSensitive', True)
    eq_(pyconfig.get('CaseSensitive'), True)
    eq_(pyconfig.get('casesensitive'), None)
    pyconfig.reload(clear=True)
Example #13
0
 def reload(self):
     """ Reloads the command. """
     if pyconfig:
         pyconfig.reload()
Example #14
0
def test_autoloading_etcd_config_works():
    pyconfig.Config().clear()
    pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/test2')
    pyconfig.reload()
    eq_(pyconfig.get('pyconfig.string'), 'Value')
    eq_(pyconfig.get('pyconfig.number'), 2)
Example #15
0
def test_reload_work_with_inheritance():
    pyconfig.set('pyconfig.etcd.prefix', 'pyconfig_test/test2')
    pyconfig.reload()