Exemplo n.º 1
0
    def test_file_parse_fail(self):
        c = client(url='path/to/file')

        c.fetch.open_f = o = mock.MagicMock()
        o.return_value.__enter__.return_value.read.return_value = 'not-json'

        c.fetch.stat_f = s = mock.Mock()
        s.return_value.st_mtime = 12

        assert not c.enabled('foo', {})
        assert s.called
        assert o.called
Exemplo n.º 2
0
    def test_file_stat_fail(self):
        c = client(url='path/to/file')

        c.fetch.open_f = o = mock.MagicMock()
        o.return_value.__enter__.return_value.read.return_value = example_json

        c.fetch.stat_f = s = mock.Mock()
        s.return_value.side_effect = FileNotFoundError

        assert not c.enabled('foo', {})
        assert s.called
        assert not o.return_value.__enter__.called
Exemplo n.º 3
0
    def test_file_open_fail(self):
        c = client(url='path/to/file')

        c.fetch.open_f = o = mock.MagicMock()
        o.return_value.side_effect = FileNotFoundError

        c.fetch.stat_f = s = mock.Mock()
        s.return_value.st_mtime = 12

        assert not c.enabled('foo', {})
        assert s.called
        assert o.called
Exemplo n.º 4
0
 def test_fetchable_url(self, requests):
     requests.get.return_value = r = mock.Mock(wraps=Response())
     r.ok = True
     r.status_code = 200
     r.headers = {'ETag': 'e-tag'}
     r.json.return_value = {
         'features': [{
             'name': 'foo',
             'enabled': True,
             'strategies': [{'name': 'default', 'parameters': {}}],
         }],
     }
     c = client(url=self.url)
     assert c.enabled('foo', {})
     assert r.json.called
def main(args):
    ns = argparser.parse_args(args[1:])

    logging.basicConfig()
    logging.getLogger().setLevel(10 * max(1, 3 - ns.verbose))

    un = client(
        url=ns.url,
        refresh_interval=5,
        metrics_interval=2,
    )
    context = dict(kv.split('=') for kv in ns.attrs)

    if ns.demo:
        demo_it(un, ns.feature, context, ns.sleep)
    else:
        result = un.enabled(ns.feature, context)
        print('yes' if result else 'no')
Exemplo n.º 6
0
 def test_file_url(self):
     c = client(url='path/to/file')
     assert isinstance(c.fetch, FileFetcher)
Exemplo n.º 7
0
 def test_url_to_nowhere(self, requests):
     requests.get.side_effect = exceptions.ConnectionError
     assert not client(url=self.url).enabled('foo', {})
Exemplo n.º 8
0
 def test_blank_config(self):
     c = client()
     assert isinstance(c, DummyClient)
     assert not client().enabled('foo', {})