Beispiel #1
0
def test_creation_of_report_layout_full():
    report = Report(*_transform('grid_checks/fullgrid.json'))
    report.populate_report()

    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)
    assert len(table.columns) == 12
    assert len(table.rows) == 12

    # Check the specific merged cells
    vtable = [
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    ]
    assert get_vtable_merged(table) == vtable

    # Check the page breaks
    assert len(d.element.xpath('//w:pgSz[@w:orient="landscape"]')) == 0

    # Check page size
    page_sz = d.element.xpath('//w:pgSz[@w:w]')
    assert len(page_sz) == 1
    page_sz = page_sz[0]
    width, height = int(page_sz.w.mm), int(page_sz.h.mm)
    expected_width, expected_height = A4_MM_WIDTH.mm, A4_MM_HEIGHT.mm

    # Conversions aren't exact, so we are looking for a close enough difference.
    assert abs(expected_width - width) < 2
    assert abs(expected_height - height) < 2
Beispiel #2
0
def test_items_section_in_report():
    report = Report(*_transform('elements/items_section.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    # Check there are enough itemsSections
    assert len(
        d.element.xpath('//w:tbl//w:tbl[not(*/w:tblStyle) and .//w:sz['
                        '@w:val="18"]]')) == 5

    # Check values
    assert len(d.element.xpath('//w:tbl//w:t[contains(text(), "Bot")]')) == 6
    assert len(d.element.xpath('//w:tbl//w:t[contains(text(), "2019")]')) == 7
    assert len(
        d.element.xpath('//w:tbl//w:t[contains(text(), "' +
                        str(date.today().year) + '")]')) == 1
    assert len(d.element.xpath('//w:tbl//w:t[contains(text(), "week")]')) == 1
    assert len(
        d.element.xpath('//w:tbl//w:t[contains(text(), "Timeline '
                        'Information")]')) == 1
    assert len(
        d.element.xpath('//w:tbl//w:t[contains(text(),'
                        ' "columnheader2")]')) == 1
Beispiel #3
0
def test_number_and_trend_in_report():
    report = Report(*_transform('elements/number_and_trend.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    if SHOULD_HAVE_12_GRID:
        assert len(table.columns) == 12
        assert len(table.rows) == 4
    else:
        assert len(table.columns) == 9
        assert len(table.rows) == 4

    # Check that there is indeed a table within a table
    assert len(d.element.xpath('//w:tbl//w:tbl')) == 3

    # Check that it has the right amount of rows
    assert len(d.element.xpath('//w:tbl//w:tbl//w:t')) == 8

    # Check that there is an extra sign
    assert len(
        d.element.xpath("//w:tbl//w:tbl//w:t[contains(text(),'%')]")) == 3

    # Check that precentage is correct
    assert len(
        d.element.xpath(
            "//w:tbl//w:tbl//w:t[contains(text(),'100.25%')]")) == 1
Beispiel #4
0
def test_table_new_json():
    report = Report(*_transform('elements/table_new_json.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    assert int(d.element.xpath('count(//w:tbl)')) == 7  # grid + 5 tables
Beispiel #5
0
def test_table_63_cols():
    report = Report(*_transform('elements/table_63_cols.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    assert len(d.element.xpath('//w:tbl//w:tbl')) == 1
    assert int(d.element.xpath('count(//w:t)')) == 64  # 63 + title
Beispiel #6
0
def test_table_empty_in_report():
    report = Report(*_transform('elements/table_empty.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    assert len(d.element.xpath('//w:tbl//w:tbl')) == 1

    # Check that it has the right amount of rows
    assert len(d.element.xpath('//w:tbl//w:tbl//w:tr')) == 2
Beispiel #7
0
def test_logo_works_in_regular_report_svg():
    report = Report(*_transform('grid_checks/fullgrid.json'), options={
        'customerLogo': XSOAR_LOGO_BASE64,
        'demistoLogo': "data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIj8+CjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB3aWR0aD0iNDY2IiBoZWlnaHQ9IjQ2NiIgdmlld0JveD0iLTQwIC00MCA4MCA4MCI+Cgk8Y2lyY2xlIHI9IjM5Ii8+Cgk8cGF0aCBkPSJNMCwzOGEzOCwzOCAwIDAgMSAwLC03NmExOSwxOSAwIDAgMSAwLDM4YTE5LDE5IDAgMCAwIDAsMzgiIGZpbGw9IiNmZmYiLz4KCTxjaXJjbGUgY3k9IjE5IiByPSI1IiBmaWxsPSIjZmZmIi8+Cgk8Y2lyY2xlIGN5PSItMTkiIHI9IjUiLz4KPC9zdmc+"
    })
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    # Check headers for 2 images (customer logo)
    assert len(d.sections[0].header._element.xpath('.//w:drawing')) == 2
Beispiel #8
0
def test_logo_works_in_regular_report():
    report = Report(*_transform('grid_checks/fullgrid.json'), options={
        'customerLogo': XSOAR_LOGO_BASE64,
        'demistoLogo': XSOAR_LOGO_BASE64
    })
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    # Check headers for 2 images (customer logo)
    assert len(d.sections[0].header._element.xpath('.//w:drawing')) == 2
Beispiel #9
0
def test_table_in_report_widget():
    report = Report(*_transform('elements/table_widget.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)
    assert len(table.columns) == 12
    assert len(table.rows) == 3

    assert len(d.element.xpath('//w:tbl//w:tbl')) == 1

    # Check that it has the right amount of rows
    assert len(d.element.xpath('//w:t[contains(text(), "Eve listens")]')) == 1
Beispiel #10
0
def test_list_in_report():
    report = Report(*_transform('elements/list.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    assert len(d.element.xpath('//w:tbl//w:tbl')) == 4

    assert len(d.element.xpath('//w:tbl//w:tbl//w:t')) == 16

    # Check that we have a string conversion
    assert len(d.element.xpath('//w:t[contains(text(),\'[]\')]')) == 1
    assert len(d.element.xpath('//w:t[contains(text(),\'0\')]')) == 1
Beispiel #11
0
def test_creation_of_report_layout_basic():
    report = Report(*_transform('basic.json'))
    report.populate_report()

    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)
    assert len(table.columns) == 12
    assert len(table.rows) == 2

    # Check the specific merged cells
    vtable = [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
              [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
    assert get_vtable_merged(table) == vtable
Beispiel #12
0
def test_list_in_report():
    report = Report(*_transform('elements/list.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)
    # assert len(table.columns) == 9
    assert len(table.rows) == 2

    # Check that there is indeed an image
    assert len(d.element.xpath('//w:tbl//w:tbl')) == 1

    # Check that it has the right amount of rows
    assert len(d.element.xpath('//w:tbl//w:tbl//w:t')) == 7
Beispiel #13
0
def test_pie_chart_in_report():
    report = Report(*_transform('elements/pie_chart.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    if SHOULD_HAVE_12_GRID:
        assert len(table.columns) == 12
        assert len(table.rows) == 1
    else:
        assert len(table.columns) == 12
        assert len(table.rows) == 5

    # Check that there is indeed an image
    assert len(d.element.xpath('//pic:pic')) == 3
Beispiel #14
0
def test_items_section_in_report():
    report = Report(*_transform('elements/items_section.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    # Check there are enough itemsSections
    assert len(
        d.element.xpath(
            '//w:tbl//w:tbl[not(*/w:tblStyle) and .//w:sz[@w:val="18"]]')) == 4

    # Check values
    assert len(d.element.xpath('//w:tbl//w:t[contains(text(), "Bot")]')) == 6
    assert len(d.element.xpath('//w:tbl//w:t[contains(text(), "2019")]')) == 8
    assert len(d.element.xpath('//w:tbl//w:t[contains(text(), "week")]')) == 1
Beispiel #15
0
def test_number_and_trend_in_report():
    report = Report(*_transform('elements/number_and_trend.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    if SHOULD_HAVE_12_GRID:
        assert len(table.columns) == 12
        assert len(table.rows) == 4
    else:
        assert len(table.columns) == 9
        assert len(table.rows) == 4

    # Check that there is indeed an image
    assert len(d.element.xpath('//w:tbl//w:tbl')) == 2

    # Check that it has the right amount of rows
    assert len(d.element.xpath('//w:tbl//w:tbl//w:t')) == 5
Beispiel #16
0
def test_duration():
    report = Report(*_transform('elements/duration.json'))
    report.populate_report()
    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)

    if SHOULD_HAVE_12_GRID:
        assert len(table.columns) == 12
        assert len(table.rows) == 1
    else:
        assert len(table.columns) == 12
        assert len(table.rows) == 1

    # Check that there is indeed a duration table
    assert len(d.element.xpath('//w:tbl//w:tbl')) == 1

    # Check that it has the right amount of rows
    assert len(d.element.xpath('//w:tbl//w:tbl//w:t')) == 9

    # Right title
    assert len(
        d.element.xpath(
            "//w:t[contains(text(), 'Mean Time to Resolution (Occurred)')]")
    ) == 1

    # Check duration value
    assert len(d.element.xpath("//w:t[contains(text(), '38')]")) == 1

    # Check that it has the right values of labels
    days = DURATION_DAYS_LABEL.strip()
    hours = DURATION_HOURS_LABEL.strip()
    mins = DURATION_MINUTES_LABEL.strip()
    print(days, hours, mins)
    assert len(d.element.xpath(f"//w:t[contains(text(), '{days}')]")) == 1
    assert len(d.element.xpath(f"//w:t[contains(text(), '{hours}')]")) == 1
    assert len(d.element.xpath(f"//w:t[contains(text(), '{mins}')]")) == 1
Beispiel #17
0
def test_creation_of_report_layout_full_paged():
    report = Report(*_transform('grid_checks/fullgridpaged.json'))
    report.populate_report()

    d = report.document
    table = next(utils.iter_block_items(d))
    assert isinstance(table, Table)
    assert len(table.columns) == 12
    assert len(table.rows) == 11

    # Check the specific merged cells
    vtable = [
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
        [1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
        [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
    ]
    assert get_vtable_merged(table) == vtable

    # Check the page breaks
    assert len(d.element.xpath('//w:br')) == 1