Exemplo n.º 1
0
def test_handles_auth_errors(logging_ow, logging_reports):
    wrapper = OrderlyWebClientWrapper({})
    success = {}
    error = {}

    def success_callback(report, version):
        success["called"] = True

    def error_callback(report, version=None):
        error["called"] = True

    mock_running_reports = MockRunningReportRepository()
    versions = run_reports(wrapper, group, disease, touchstone, MockConfig(),
                           reports, success_callback, error_callback,
                           mock_running_reports)

    # the wrapper will have an auth failure because no auth config
    # supplied
    expected_error = AttributeError(
        "'dict' object has no attribute 'montagu_url'")
    logging_ow.exception.assert_called_once_with(
        ExceptionMatching(expected_error))

    logging_reports.error.assert_called_once_with(
        "Orderlyweb authentication failed; could not begin task")

    assert len(success) == 0
    assert len(versions) == 0
    assert error["called"] is True
Exemplo n.º 2
0
def test_retries_when_token_expired(logging):
    auth = MockReturnAuthorisedClient().auth
    wrapper = OrderlyWebClientWrapper(None, auth)
    success = {}
    error = {}

    def success_callback(report, version):
        success["called"] = True

    def error_callback(report, version=None):
        error["called"] = True

    mock_running_reports = MockRunningReportRepository()
    versions = run_reports(wrapper, group, disease, touchstone, MockConfig(),
                           reports, success_callback, error_callback,
                           mock_running_reports)

    assert versions == {"r1-version": {"published": True, "report": "r1"}}
    logging.info.assert_has_calls([
        call("Running report: r1 with parameters touchstone=2021test-1,"
             " touchstone_name=2021test. "
             "Key is r1-key. Timeout is 1000s."),
        call("Success for key r1-key. New version is r1-version"),
        call("Publishing report version r1-r1-version"),
        call("Successfully published report version r1-r1-version")
    ], any_order=False)

    assert success["called"] is True
    assert len(error) == 0
Exemplo n.º 3
0
def test_tags_not_created_if_exists():
    report = ReportConfig("TEST", {}, ["*****@*****.**"], "Hi", 100,
                          "a.ssignee")
    mock_config: Config = MockConfig()
    mock_client = Mock(spec=YTClient("", ""))
    mock_client.create_issue = Mock(return_value="ISSUE")
    mock_client.get_issues = Mock(return_value=[])
    mock_client.get_tags = Mock(return_value=fake_tags)
    create_ticket("g1", "d1", "t1", "s1", report, "1234", None, mock_client,
                  mock_config)
    mock_client.create_tag.assert_has_calls([])
Exemplo n.º 4
0
def test_create_ticket_logs_errors(logging):
    report = ReportConfig("TEST", {}, ["*****@*****.**"], "Hi", 100,
                          "a.ssignee")
    mock_config: Config = MockConfig()
    mock_client = Mock(spec=YTClient("", ""))
    mock_client.get_issues = Mock(return_value=[])
    mock_client.get_tags = Mock(return_value=fake_tags)
    test_ex = Exception("TEST EX")
    mock_client.create_issue = Mock(side_effect=test_ex)
    create_ticket("g1", "d1", "t1", "s1", report, "1234", None, mock_client,
                  mock_config)
    logging.exception.assert_has_calls([call(test_ex)])
Exemplo n.º 5
0
def test_update_ticket():
    report = ReportConfig("TEST", {}, ["*****@*****.**"], "Hi", 100,
                          "a.ssignee")
    mock_config: Config = MockConfig()
    mock_client = Mock(spec=YTClient("", ""))
    mock_client.get_issues = Mock(return_value=["ISSUE"])
    mock_client.get_tags = Mock(return_value=fake_tags)
    create_ticket("g1", "d1", "t1", "s1", report, "1234", None, mock_client,
                  mock_config)
    expected_command = call(
        "ISSUE", "Check & share diag report with g1 (d1) t1",
        "Report run triggered by upload to scenario: s1. "
        "http://orderly-web/report/TEST/1234/")
    mock_client.update_issue.assert_has_calls([expected_command])
def test_additional_recipients_not_used(send_email):
    name = "r1"
    report = ReportConfig(name, {}, ["*****@*****.**"], "Hi", 1000,
                          "a.ssignee")
    fake_emailer = {}
    mock_config = MockConfig(use_additional_recipients=False)
    send_diagnostic_report_email(fake_emailer, report, "1234-abcd", "groupId",
                                 "diseaseId", "touchstoneId",
                                 "2020-11-04T12:22:53", "no_vaccination",
                                 mock_config, "*****@*****.**")
    url = "http://orderly-web/report/{}/1234-abcd/".format(name)
    send_email.assert_has_calls([
        call(fake_emailer, report, "diagnostic_report",
             get_test_template_values(url), mock_config, list())
    ])
def test_url_encodes_url_in_email(send_email):
    name = "'A silly, report"
    encoded = "%27A%20silly%2C%20report"
    report = ReportConfig(name, {}, ["*****@*****.**"], "Hi", 100, "a.ssignee")
    fake_emailer = {}
    mock_config = MockConfig()
    send_diagnostic_report_email(fake_emailer, report, "1234-abcd", "groupId",
                                 "diseaseId", "touchstoneId",
                                 "2020-11-04T12:22:53", "no_vaccination",
                                 mock_config)
    url = "http://orderly-web/report/{}/1234-abcd/".format(encoded, encoded)
    send_email.assert_has_calls([
        call(fake_emailer, report, "diagnostic_report",
             get_test_template_values(url), mock_config, list())
    ])
Exemplo n.º 8
0
def test_create_ticket_with_version():
    report = ReportConfig("TEST", {}, ["*****@*****.**"], "Hi", 100,
                          "a.ssignee")
    mock_config: Config = MockConfig()
    mock_client = Mock(spec=YTClient("", ""))
    mock_client.create_issue = Mock(return_value="ISSUE")
    mock_client.get_issues = Mock(return_value=[])
    mock_client.get_tags = Mock(return_value=fake_tags)
    create_ticket("g1", "d1", "t1", "s1", report, "1234", None, mock_client,
                  mock_config)
    expected_create = call(
        Project(id="78-0"), "Check & share diag report with g1 (d1) t1",
        "Report run triggered by upload to scenario: s1. "
        "http://orderly-web/report/TEST/1234/")
    mock_client.create_issue.assert_has_calls([expected_create])
    expected_command_query = \
        "for a.ssignee implementer a.ssignee tag g1 tag d1 tag t1 tag TEST"
    expected_command = call(
        Command(issues=["ISSUE"], query=expected_command_query))
    mock_client.run_command.assert_has_calls([expected_command])