-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest_application.py
116 lines (89 loc) · 3.2 KB
/
test_application.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
"""CLI based test suite!"""
import json
import random
import subprocess
import time
import pytest
@pytest.fixture(scope="module")
def app_fixture():
port = random.randint(30000, 40000)
process = subprocess.Popen(["python", "app.py", "--port", str(port)])
print("Warming process")
time.sleep(1)
yield f"http://127.0.0.1:{port}"
process.terminate()
def test_subset(app_fixture):
"""Simple test that checks if we constrain our channel can we no longer find a given package
"""
conda_search_command = [
"conda",
"search",
"--override-channels",
"-c",
f"{app_fixture}/conda-forge/python",
"--json",
]
output = subprocess.check_output(
encoding="utf8", args=conda_search_command + ["zlib"]
)
output = json.loads(output)
assert "zlib" in output
assert len(output["zlib"]) > 0
process = subprocess.Popen(
encoding="utf8",
args=conda_search_command + ["flask"],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
stdout, stderr = process.communicate()
assert process.returncode != 0
output = json.loads(stdout)
assert "error" in output
assert output["exception_name"] == "PackagesNotFoundError"
def test_blacklist(app_fixture):
"""Simple test that checks if we constrain our channel can we no longer find a given package
"""
channel = f"{app_fixture}/conda-forge/python"
channel_blacklist = f"{app_fixture}/conda-forge/python,--blacklist=abi"
def conda_search_command(channel, package):
return [
"conda",
"search",
"--override-channels",
"-c",
channel,
"--json",
package,
]
output = subprocess.check_output(
encoding="utf8", args=conda_search_command(channel, "python")
)
output = json.loads(output)
assert len(output["python"]) > 0
stdout = subprocess.check_output(
encoding="utf8", args=conda_search_command(channel_blacklist, "python")
)
output2 = json.loads(stdout)
assert len(output2["python"]) < len(output["python"])
def test_current_repodata(app_fixture):
channel = f"{app_fixture}/conda-forge/python"
import requests
full_repodata = requests.get(f"{channel}/linux-64/repodata.json").json()
current_repodata = requests.get(f"{channel}/linux-64/current_repodata.json").json()
assert len(current_repodata['packages']) < len(full_repodata['packages'])
def test_download_artifact(app_fixture):
package = 'conda-forge-pinning'
channel = f"{app_fixture}/conda-forge/{package}"
import requests
current_repodata = requests.get(f"{channel}/noarch/current_repodata.json").json()
print(current_repodata)
for k, v in sorted(current_repodata['packages'].items()):
if v['name'] == package:
filename = k
resp = requests.get(f"{channel}/noarch/{filename}", allow_redirects=False)
assert resp.ok
assert resp.status_code // 100 == 3
assert resp.headers["Location"] == f"https://conda.anaconda.org/conda-forge/noarch/{filename}"
break
else:
raise LookupError("No file download attempted")