Repository: plotly/dash
File: tests/integration/test_integration.py (Python)

Code before:
    for i in range(3, len(meta)):
        meta_tag = meta[i]
        meta_info = metas[i - 3]
        assert meta_tag.get_attribute("name") == meta_info["name"]
        assert meta_tag.get_attribute("content") == meta_info["content"]


def test_inin007b_change_viewport_meta_tag(dash_duo):
    """
    As of dash 2.5 the default viewport meta tag is:
        [{"name": "viewport", "content": "width=device-width, initial-scale=1"}]
    Test verifies that this feature can be disabled by using an empty viewport tag.
    """

    app = Dash(meta_tags=[{"name": "viewport"}])

    app.layout = html.Div(id="content")

    dash_duo.start_server(app)

    meta = dash_duo.find_elements("meta")

    # -3 for the meta charset, http-equiv and viewport.
    assert len(meta) == 3, "Should have 3 meta tags"

    viewport_meta = meta[2]
    assert viewport_meta.get_attribute("name") == "viewport"
    assert viewport_meta.get_attribute("content") == ""


def test_inin008_index_customization(dash_duo):
    app = Dash()

    app.index_string = """<!DOCTYPE html>
    <html>
        <head>
            {%metas%}
            <title>{%title%}</title>
            {%favicon%}
            {%css%}
        </head>
        <body>
            <div id="custom-header">My custom header</div>
            <div id="add"></div>
            {%app_entry%}
            <footer>
                {%config%}
                {%scripts%}
                {%renderer%}
            </footer>
            <div id="custom-footer">My custom footer</div>

Review comment (suggestion):
Better not to depend on the order of the returned meta elements. Also if we add more default meta tags in the future this test would need to change. Instead, find just the viewport tags and ensure there's exactly one:
```
meta = dash_duo.find_elements('meta[name="viewport"]')
```

Code after:
    for i in range(3, len(meta)):
        meta_tag = meta[i]
        meta_info = metas[i - 3]
        assert meta_tag.get_attribute("name") == meta_info["name"]
        assert meta_tag.get_attribute("content") == meta_info["content"]


def test_inin007_change_viewport_meta_tag(dash_duo):
    """
    As of dash 2.5 the default viewport meta tag is:
        [{"name": "viewport", "content": "width=device-width, initial-scale=1"}]
    Test verifies that this feature can be disabled by using an empty viewport tag.
    """

    app = Dash(meta_tags=[{"name": "viewport"}])

    app.layout = html.Div(id="content")

    dash_duo.start_server(app)

    viewport_meta = dash_duo.find_elements('meta[name="viewport"]')

    assert len(viewport_meta) == 1, "Should have 1 viewport meta tags"
    assert viewport_meta[0].get_attribute("content") == ""


def test_inin008_index_customization(dash_duo):
    app = Dash()

    app.index_string = """<!DOCTYPE html>
    <html>
        <head>
            {%metas%}
            <title>{%title%}</title>
            {%favicon%}
            {%css%}
        </head>
        <body>
            <div id="custom-header">My custom header</div>
            <div id="add"></div>
            {%app_entry%}
            <footer>
                {%config%}
                {%scripts%}
                {%renderer%}
            </footer>
            <div id="custom-footer">My custom footer</div>
            <script>
            // Test the formatting doesn't mess up script tags.
            var elem = document.getElementById('add');
            if (!elem) {