test_material_version_matches()   A
last analyzed

Complexity

Conditions 4

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
c 1
b 0
f 0
dl 0
loc 18
rs 9.2
1
import re
2
3
from flask import Flask
4
from flask_material import Material
5
import flask_material
6
import requests
7
8
import pytest
9
10
11
@pytest.fixture
12
def app():
13
    app = Flask(__name__)
14
    Material(app)
15
    return app
16
17
18
@pytest.fixture
19
def client(app):
20
    return app.test_client()
21
22
23
@pytest.fixture
24
def bsv():
25
    material_version = re.search(r'(\d+\.\d+\.\d+)',
26
                                  str(flask_material.__material_version__)).group(1)
27
    return material_version
28
29
30
def test_material_version_matches(app, client, bsv):
31
    material_vre = re.compile(r'Materialize v(\d+\.\d+\.\d+).*')
32
33
    # find local version
34
    local_version = material_vre.search(
35
        str(client.get('/static/material/css/materialize.css').data)
36
    ).group(1)
37
38
    # find cdn version
39
    cdn = app.extensions['material']['cdns']['material']
40
    with app.app_context():
41
        cdn_url = 'https:' + cdn.get_resource_url('css/materialize.css')
42
    cdn_version = material_vre.search(requests.get(cdn_url).text).group(1)
43
44
    # get package version
45
46
    assert local_version == bsv
47
    assert cdn_version == bsv
48