Exemple #1
0
def test_enqueue_queries():
    sqs_client = boto3.client("sqs", region_name="us-west-2")
    queue_url = sqs_client.create_queue(QueueName="test.fifo",
                                        Attributes={"FifoQueue":
                                                    "true"})["QueueUrl"]
    job_1 = Job(
        name="fooboo",
        description="FooBoo",
        graph_spec=JobGraphSpec(graph_names=["test1"]),
        category=Category.gov,
        severity=Severity.debug,
        query=
        "select ?account_id ?account_name where { ?account a <alti:aws:account> ; <alti:account_id> ?account_id ; <alti:name> ?account_name } order by ?account_name",
        active=True,
        created=datetime(2020, 1, 1),
        query_fields=["account_id", "account_name"],
        max_graph_age_sec=10000,
        result_expiration_sec=100000,
        max_result_age_sec=100000,
        notify_if_results=False,
    )
    job_2 = Job(
        name="boo",
        description="Boo",
        graph_spec=JobGraphSpec(graph_names=["test2"]),
        category=Category.gov,
        severity=Severity.debug,
        query=
        "select ?account_id ?account_name where { ?account a <alti:aws:account> ; <alti:account_id> ?account_id ; <alti:name> ?account_name } order by ?account_name",
        active=True,
        created=datetime(2020, 1, 1),
        query_fields=["account_id", "account_name"],
        max_graph_age_sec=10000,
        result_expiration_sec=100000,
        max_result_age_sec=100000,
        notify_if_results=False,
    )
    jobs: List[Job] = [job_1, job_2]
    enqueue_queries(jobs=jobs,
                    queue_url=queue_url,
                    execution_hash="1234",
                    region="us-west-2")
    msgs = []
    resp = sqs_client.receive_message(QueueUrl=queue_url)
    for raw_msg in resp["Messages"]:
        msgs.append(Job.parse_raw(raw_msg["Body"]))
    resp = sqs_client.receive_message(QueueUrl=queue_url)
    for raw_msg in resp["Messages"]:
        msgs.append(Job.parse_raw(raw_msg["Body"]))
    assert msgs == [job_1, job_2]
 def test_to_csv_returns_csv_str(self):
     result_set = ResultSet(
         job=Job(
             name="foobizz",
             description="FooBizz",
             graph_spec=JobGraphSpec(graph_names=["test"]),
             category=Category.gov,
             severity=Severity.debug,
             query="select ?foo ?fizz where { ?foo ?fizz } order by ?foo",
             active=True,
             created=datetime(2020, 1, 1),
             query_fields=["account_id", "account_name"],
             max_graph_age_sec=10000,
             result_expiration_sec=100000,
             max_result_age_sec=100000,
             notify_if_results=False,
         ),
         graph_spec=ResultSetGraphSpec(
             graph_uris_load_times={"https://alti/alti/1/1234": 1612974818}
         ),
         results=[
             Result(account_id="123456789101", result={"foo": "boo", "fizz": "bizz"}),
             Result(account_id="123456789101", result={"foo": "boo2", "fizz": "bizz2"}),
         ],
     )
     expected_csv = "account_id,foo,fizz\n123456789101,boo,bizz\n123456789101,boo2,bizz2\n"
     self.assertEqual(expected_csv, result_set.to_csv())
 def test_empty_results_to_csv_returns_csv_str(self):
     result_set = ResultSet(
         job=Job(
             name="foobizz",
             description="FooBizz",
             graph_spec=JobGraphSpec(graph_names=["test"]),
             category=Category.gov,
             severity=Severity.debug,
             query="select ?foo ?fizz where { ?foo ?fizz } order by ?foo",
             active=True,
             created=datetime(2020, 1, 1),
             query_fields=["account_id", "account_name"],
             max_graph_age_sec=10000,
             result_expiration_sec=100000,
             max_result_age_sec=100000,
         ),
         graph_spec=ResultSetGraphSpec(
             graph_uris_load_times={"https://alti/alti/1/1234": 1612974818
                                    }),
         results=[],
     )
     expected_csv = ""
     self.assertEqual(expected_csv, result_set.to_csv())