コード例 #1
0
 def test_token(self):
     api = Client(auth={"token": self.token},
                  address=self.uri,
                  config=ClientConfig(stream=False, response="json"))
     result = api.query(query=self.query)
     self.assertIsNotNone(result)
     self.assertTrue(len(json.loads(result)['object']) > 0)
コード例 #2
0
 def test_stream_query(self):
     api = Client(auth={"key": self.key, "secret": self.secret},
                  address=self.uri,
                  config=ClientConfig(response="json/simple"))
     result = api.query(query=self.query)
     self.assertTrue(isinstance(result, types.GeneratorType))
     result = list(result)
     self.assertEqual(len(result), 1)
コード例 #3
0
 def test_query_from_seven_days(self):
     api = Client(auth={"key": self.key, "secret": self.secret},
                  address=self.uri,
                  config=ClientConfig(stream=False, response="json"))
     result = api.query(query=self.query,
                        dates={'from': 'now()-7*day()', 'to': 'now()'})
     self.assertIsNotNone(result)
     self.assertEqual(len(json.loads(result)['object']), 1)
コード例 #4
0
 def test_query_id(self):
     api = Client(auth={"key": self.key, "secret": self.secret},
                  address=self.uri,
                  config=ClientConfig(stream=False, response="json"))
     result = api.query(query_id=self.query_id)
     self.assertIsNotNone(result)
     self.assertNotEqual(result, {})
     self.assertEqual(type(len(json.loads(result)['object'])), type(1))
コード例 #5
0
    def test_query(self):
        config = ClientConfig(stream=False, response="json")

        api = Client(auth={"key": self.key, "secret": self.secret},
                     address=self.uri,
                     config=config)

        result = api.query(query=self.query)
        self.assertIsNotNone(result)
        self.assertTrue(len(json.loads(result)['object']) > 0)
コード例 #6
0
 def test_pragmas(self):
     """Test the api when the pragma comment.free is used"""
     api = Client(auth={"key": self.key, "secret": self.secret},
                  address=self.uri,
                  config=ClientConfig(response="json",
                                      stream=False))
     api.config.set_user(user=self.user)
     api.config.set_app_name(app_name=self.app_name)
     result = api.query(query=self.query, comment=self.comment)
     self.assertIsNotNone(result)
     self.assertEqual(len(json.loads(result)['object']), 1)
コード例 #7
0
 def test_query_from_fixed_dates(self):
     api = Client(auth={"key": self.key, "secret": self.secret},
                  address=self.uri,
                  config=ClientConfig(stream=False, response="json"))
     result = api.query(query=self.query,
                        dates={'from': strftime("%Y-%m-%d", gmtime()),
                               'to': strftime(
                                   "%Y-%m-%d %H:%M:%S",
                                   gmtime())})
     self.assertIsNotNone(result)
     self.assertEqual(len(json.loads(result)['object']), 1)
コード例 #8
0
ファイル: query.py プロジェクト: DevoInc/python-sdk
 def test_stream_query_no_results_bounded_dates(self):
     api = Client(auth={
         "key": self.key,
         "secret": self.secret
     },
                  address=self.uri,
                  config=ClientConfig(response="json/simple"),
                  retries=3)
     result = api.query(query=self.query_no_results,
                        dates={
                            'from': '1h',
                            'to': 'now()'
                        })
     self.assertTrue(isinstance(result, types.GeneratorType))
     result = list(result)
     self.assertEqual(len(result), 0)
コード例 #9
0
ファイル: query.py プロジェクト: DevoInc/python-sdk
 def test_stream_query_no_results_unbounded_dates(self):
     api = Client(auth={
         "key": self.key,
         "secret": self.secret
     },
                  address=self.uri,
                  config=ClientConfig(response="json/simple"),
                  retries=3)
     result = api.query(query=self.query_no_results)
     self.assertTrue(isinstance(result, types.GeneratorType))
     try:
         with stopit.ThreadingTimeout(3) as to_ctx_mgr:
             result = list(result)
     except DevoClientException:
         # This exception is sent because
         # devo.api.client.Client._make_request catches the
         # stopit.TimeoutException, but the latter is not
         # wrapped, so we cannot obtain it from here.
         self.assertEqual(to_ctx_mgr.state, to_ctx_mgr.TIMED_OUT)
コード例 #10
0
ファイル: query.py プロジェクト: DevoInc/python-sdk
    def test_unsecure_http_query(self):
        """
        This test is intended for checking unsecure HTTP requests. Devo will NEVER provide an unsecure HTTP endpoint
        for API REST services. Therefore, you are not going to need to use or test this functionality.
        In order to enable UNSECURE_HTTP environment var should be TRUE.
        The endpoint is served by https://httpbin.org/. You can run with `docker run -p 80:80 kennethreitz/httpbin`. It
        will expose an HTTP service at port 80. The URL `http://localhost:80/anything` will answer with the content of
        the request.
        """
        os.environ["UNSECURE_HTTP"] = "TRUE"
        config = ClientConfig(stream=False, response="json")

        api = Client(auth={
            "key": self.key,
            "secret": self.secret
        },
                     address="localhost:80/anything",
                     config=config,
                     retries=3)

        result = api.query(query=self.query)
        self.assertIsNotNone(result)
        self.assertIn('json', json.loads(result))
        self.assertIn('query', json.loads(result)['json'])
コード例 #11
0
import os
from devo.api import Client, ClientConfig, JSON

key = os.getenv('DEVO_API_KEY', None)
secret = os.getenv('DEVO_API_SECRET', None)

api = Client(auth={
    "key": key,
    "secret": secret
},
             address="https://apiv2-eu.devo.com/search/query",
             config=ClientConfig(response="json", processor=JSON))

response = api.query(query="from demo.ecommerce.data select * limit 20",
                     dates={
                         'from': "today()-1*day()",
                         'to': "today()"
                     })

print(response)
コード例 #12
0
import os
from devo.api import Client, ClientConfig, TO_BYTES

key = os.getenv('DEVO_API_KEY', None)
secret = os.getenv('DEVO_API_SECRET', None)

api = Client(auth={
    "key": key,
    "secret": secret
},
             address="https://apiv2-eu.devo.com/search/query",
             config=ClientConfig(response="csv",
                                 stream=True,
                                 processor=TO_BYTES))

response = api.query(query="from demo.ecommerce.data select * limit 20",
                     dates={
                         'from': "today()-1*day()",
                         'to': "today()"
                     })

with open("example_data/example.csv", "wb") as f:
    try:
        for item in response:
            f.write(item)
            f.write(b"\n")
    except Exception as error:
        print(error)
コード例 #13
0
import os
from devo.api import Client, ClientConfig, SIMPLECOMPACT_TO_OBJ
from devo.sender import Sender, SenderConfigSSL

key = os.getenv('DEVO_API_KEY', None)
secret = os.getenv('DEVO_API_SECRET', None)

api = Client(auth={
    "key": key,
    "secret": secret
},
             address="https://apiv2-eu.devo.com/search/query",
             config=ClientConfig(response="json/simple/compact",
                                 stream=True,
                                 processor=SIMPLECOMPACT_TO_OBJ))

response = api.query(query="from demo.ecommerce.data select *",
                     dates={
                         'from': "today()-1*day()",
                         'to': "today()"
                     })

server = "us.elb.relay.logtrust.net"
port = 443
key = os.getenv('DEVO_SENDER_KEY')
cert = os.getenv('DEVO_SENDER_CERT')
chain = os.getenv('DEVO_SENDER_CHAIN')

engine_config = SenderConfigSSL(address=(server, port),
                                key=key,
                                cert=cert,