Exemplo n.º 1
0
 def test_returns_none_on_missing_creds(self, args):
     _, key, secret, _, _ = args
     assume(key is None or secret is None)
     with self.mock_auth(succeed=True):
         client = api.EPOClient(*args)
         token = client.authenticate()
         self.assertIsNone(token)
Exemplo n.º 2
0
 def test_returns_token_on_success(self, args):
     token_content = 'success'
     with self.mock_auth(token=token_content):
         client = api.EPOClient(*args)
         token = client.authenticate()
         self.assertIsInstance(token, api.Token)
         self.assertEqual(token.token, token_content)
Exemplo n.º 3
0
    def test_raises_on_failed_auth(self, args, key, secret):
        accept_type, _, _, cache, cache_kwargs = args
        # Omit key and secret to prevent auto-auth.
        client = api.EPOClient(accept_type, None, None, cache, cache_kwargs)

        with self.mock_auth(succeed=False):
            client.key = key
            client.secret = secret
            self.assertRaises(requests.HTTPError, client.authenticate)
Exemplo n.º 4
0
    def test_create_with_cache_calls_requests_cache(self, args):
        api.EPOClient.authenticate = mock.MagicMock()
        api.requests_cache.install_cache = mock.MagicMock()
        accept_type, key, secret, _, cache_kwargs = args
        cache = True

        api.EPOClient(accept_type, key, secret, cache, cache_kwargs)
        kwargs = cache_kwargs or dict()
        self.assertTrue(api.requests_cache.install_cache.called_with(**kwargs))
Exemplo n.º 5
0
    """ Args-tuple builder for `epo_utils.ops.api.EPOClient` """
    data_type = st.sampled_from(
        ('xml', 'json', 'cpc+xml', 'fulltext+xml', 'exchange+xml', 'ops+xml',
         'cpc+xml', 'javascript'))
    stems = st.sampled_from(('application', ''))
    accept_type = st.builds(lambda stem, d_type: '/'.join((stem, d_type)),
                            stems, data_type)

    if must_have_auth:
        key = st.text(alphabet=string.ascii_letters, min_size=1)
        secret = st.text(alphabet=string.ascii_letters, min_size=1)
    else:
        key = st.one_of(st.none(),
                        st.text(alphabet=string.ascii_letters, min_size=1))
        secret = st.one_of(st.none(),
                           st.text(alphabet=string.ascii_letters, min_size=1))
    cache = st.booleans() if enable_cache else st.just(False)
    cache_kwargs = st.one_of(st.none(), st.dictionaries(st.text(), st.text()))
    return st.tuples(accept_type, key, secret, cache, cache_kwargs)


def build_variable_tuples(strategy, max_length=100):
    """ Build variable length tuples of strategy. """
    return st.builds(lambda n: tuple(strategy for i in range(n)),
                     st.integers(min_value=0, max_value=max_length))


APIInputs = st.builds(lambda args: api.APIInput(*args), valid_api_input_args())

Clients = st.builds(lambda args: api.EPOClient(*args), valid_epo_client_args())
Exemplo n.º 6
0
    def make_client(self, args):
        with self.mock_auth(expires_in=1000):
            client = api.EPOClient(*args)

        return client
Exemplo n.º 7
0
 def test_client_auto_auths_with_key_and_secret(self, args, key, secret):
     accept_type, _, _, cache, cache_kwargs = args
     api.EPOClient.authenticate = mock.MagicMock()
     client = api.EPOClient(accept_type, key, secret, cache, cache_kwargs)
     self.assertTrue(api.EPOClient.authenticate.called)
Exemplo n.º 8
0
 def test_creation_doesnt_raise(self, args):
     api.EPOClient.authenticate = mock.MagicMock()
     client = api.EPOClient(*args)
     self.assertIsInstance(client, api.EPOClient)