|
1 | | - |
2 | 1 | from dash.fingerprint import build_fingerprint, check_fingerprint |
3 | 2 |
|
4 | 3 | version = 1 |
5 | 4 | hash_value = 1 |
6 | 5 |
|
7 | 6 | valid_resources = [ |
8 | | - |
9 | | - { 'path': '[email protected]', 'fingerprint': '[email protected]_1_1m1234567890abcdef.8.6.min.js', 'version': '1.1.1', 'hash': '1234567890abcdef' }, |
10 | | - { 'path': '[email protected]', 'fingerprint': '[email protected]_1_1-alpha_1m1234567890abcdef.8.6.min.js', 'version': '1.1.1-alpha.1', 'hash': '1234567890abcdef' }, |
11 | | - {'path': 'dash.plotly.js', 'fingerprint': 'dash.v1m1.plotly.js'}, |
12 | | - {'path': 'dash.plotly.j_s', 'fingerprint': 'dash.v1m1.plotly.j_s'}, |
13 | | - {'path': 'dash.plotly.css', 'fingerprint': 'dash.v1m1.plotly.css'}, |
14 | | - {'path': 'dash.plotly.xxx.yyy.zzz', 'fingerprint': 'dash.v1m1.plotly.xxx.yyy.zzz'}, |
15 | | - {'path': 'dash~plotly.js', 'fingerprint': 'dash~plotly.v1m1.js'} |
| 7 | + |
| 8 | + { |
| 9 | + |
| 10 | + "fingerprint": "[email protected]_1_1m1234567890abcdef.8.6.min.js", |
| 11 | + "version": "1.1.1", |
| 12 | + "hash": "1234567890abcdef", |
| 13 | + }, |
| 14 | + { |
| 15 | + |
| 16 | + "fingerprint": "[email protected]_1_1-alpha_1m1234567890abcdef.8.6.min.js", |
| 17 | + "version": "1.1.1-alpha.1", |
| 18 | + "hash": "1234567890abcdef", |
| 19 | + }, |
| 20 | + {"path": "dash.plotly.js", "fingerprint": "dash.v1m1.plotly.js"}, |
| 21 | + {"path": "dash.plotly.j_s", "fingerprint": "dash.v1m1.plotly.j_s"}, |
| 22 | + {"path": "dash.plotly.css", "fingerprint": "dash.v1m1.plotly.css"}, |
| 23 | + {"path": "dash.plotly.xxx.yyy.zzz", "fingerprint": "dash.v1m1.plotly.xxx.yyy.zzz"}, |
| 24 | + {"path": "dash~plotly.js", "fingerprint": "dash~plotly.v1m1.js"}, |
| 25 | + {"path": "nested/folder/file.js", "fingerprint": "nested/folder/file.v1m1.js"}, |
| 26 | + { |
| 27 | + # kind of pathological, but we have what looks like a version string |
| 28 | + # in a different place - still works |
| 29 | + "path": "nested.v2m2/folder/file.js", |
| 30 | + "fingerprint": "nested.v2m2/folder/file.v1m1.js" |
| 31 | + }, |
| 32 | + { |
| 33 | + # even works if it gets doubled up in the right place |
| 34 | + "path": "nested/folder/file.v2m2.js", |
| 35 | + "fingerprint": "nested/folder/file.v1m1.v2m2.js" |
| 36 | + }, |
| 37 | + { |
| 38 | + "path": "nested.dotted/folder.structure/file.name.css", |
| 39 | + "fingerprint": "nested.dotted/folder.structure/file.v1m1.name.css", |
| 40 | + }, |
| 41 | + { |
| 42 | + "path": "dash..plotly.js", |
| 43 | + "fingerprint": "dash.v1_1_1m1234567890..plotly.js", |
| 44 | + "version": "1.1.1", |
| 45 | + "hash": "1234567890", |
| 46 | + }, |
| 47 | + { |
| 48 | + "path": "dash.", |
| 49 | + "fingerprint": "dash.v1_1_1m1234567890.", |
| 50 | + "version": "1.1.1", |
| 51 | + "hash": "1234567890", |
| 52 | + }, |
| 53 | + { |
| 54 | + "path": "dash..", |
| 55 | + "fingerprint": "dash.v1_1_1m1234567890..", |
| 56 | + "version": "1.1.1", |
| 57 | + "hash": "1234567890", |
| 58 | + }, |
| 59 | + { |
| 60 | + "path": "dash.js.", |
| 61 | + "fingerprint": "dash.v1_1_1m1234567890.js.", |
| 62 | + "version": "1.1.1", |
| 63 | + "hash": "1234567890", |
| 64 | + }, |
| 65 | + { |
| 66 | + "path": "dash.j-s", |
| 67 | + "fingerprint": "dash.v1_1_1m1234567890.j-s", |
| 68 | + "version": "1.1.1", |
| 69 | + "hash": "1234567890", |
| 70 | + }, |
16 | 71 | ] |
17 | 72 |
|
18 | 73 | valid_fingerprints = [ |
19 | | - '[email protected]_1_2m1571771240.8.6.min.js', |
20 | | - 'dash.plotly.v1_1_1m1234567890.js', |
21 | | - 'dash.plotly.v1_1_1m1234567890.j_s', |
22 | | - 'dash.plotly.v1_1_1m1234567890.css', |
23 | | - 'dash.plotly.v1_1_1m1234567890.xxx.yyy.zzz', |
24 | | - 'dash.plotly.v1_1_1-alpha1m1234567890.js', |
25 | | - 'dash.plotly.v1_1_1-alpha_3m1234567890.js', |
26 | | - 'dash.plotly.v1_1_1m1234567890123.js', |
27 | | - 'dash.plotly.v1_1_1m4bc3.js', |
28 | | - 'dash~plotly.v1m1.js' |
| 74 | + "[email protected]_1_2m1571771240.8.6.min.js", |
| 75 | + "dash.v1_1_1m1234567890.plotly.js", |
| 76 | + "dash.v1_1_1m1234567890.plotly.j_s", |
| 77 | + "dash.v1_1_1m1234567890.plotly.css", |
| 78 | + "dash.v1_1_1m1234567890.plotly.xxx.yyy.zzz", |
| 79 | + "dash.v1_1_1-alpha1m1234567890.plotly.js", |
| 80 | + "dash.v1_1_1-alpha_3m1234567890.plotly.js", |
| 81 | + "dash.v1_1_1m1234567890123.plotly.js", |
| 82 | + "dash.v1_1_1m4bc3.plotly.js", |
| 83 | + "dash~plotly.v1m1.js", |
| 84 | + "nested/folder/file.v1m1.js", |
| 85 | + "nested.dotted/folder.structure/file.v1m1.name.css", |
| 86 | + # this one has a pattern that looks like the version string in the wrong place |
| 87 | + # AND one in the right place. |
| 88 | + "nested.v2m2/folder/file.v1m1.js", |
| 89 | + "nested.v2m2.dotted/folder.structure/file.v1m1.name.css", |
29 | 90 | ] |
30 | 91 |
|
31 | 92 | invalid_fingerprints = [ |
32 | | - 'dash.plotly.v1_1_1m1234567890..js', |
33 | | - 'dash.plotly.v1_1_1m1234567890.', |
34 | | - 'dash.plotly.v1_1_1m1234567890..', |
35 | | - 'dash.plotly.v1_1_1m1234567890.js.', |
36 | | - 'dash.plotly.v1_1_1m1234567890.j-s' |
| 93 | + "dash.plotly.v1_1_1m1234567890.js", |
| 94 | + "folder/dash.plotly.v1_1_1m1234567890.js", |
| 95 | + "nested.v1m1/folder/file.js", |
| 96 | + "nested.v1m1.dotted/folder.structure/file.name.css", |
37 | 97 | ] |
38 | 98 |
|
| 99 | + |
39 | 100 | def test_fingerprint(): |
40 | 101 | for resource in valid_resources: |
41 | 102 | # The fingerprint matches expectations |
42 | | - fingerprint = build_fingerprint(resource.get('path'), resource.get('version', version), resource.get('hash', hash_value)) |
43 | | - assert fingerprint == resource.get('fingerprint') |
| 103 | + fingerprint = build_fingerprint( |
| 104 | + resource.get("path"), |
| 105 | + resource.get("version", version), |
| 106 | + resource.get("hash", hash_value), |
| 107 | + ) |
| 108 | + assert fingerprint == resource.get("fingerprint") |
44 | 109 |
|
45 | 110 | (original_path, has_fingerprint) = check_fingerprint(fingerprint) |
46 | | - # The inverse operation returns that the fingerprint was valid and the original path |
| 111 | + # The inverse operation returns that the fingerprint was valid |
| 112 | + # and the original path |
47 | 113 | assert has_fingerprint |
48 | | - assert original_path == resource.get('path') |
| 114 | + assert original_path == resource.get("path") |
49 | 115 |
|
50 | 116 | for resource in valid_fingerprints: |
51 | 117 | (_, has_fingerprint) = check_fingerprint(resource) |
52 | | - assert has_fingerprint |
| 118 | + assert has_fingerprint, resource |
53 | 119 |
|
54 | 120 | for resource in invalid_fingerprints: |
55 | 121 | (_, has_fingerprint) = check_fingerprint(resource) |
56 | | - assert not has_fingerprint |
| 122 | + assert not has_fingerprint, resource |
0 commit comments