forked from konflux-ci/release-service-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_find_signatures.py
74 lines (57 loc) · 1.72 KB
/
test_find_signatures.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
from unittest.mock import patch, MagicMock
from find_signatures import (
find_signatures_for_repository,
)
mock_pyxis_graphql_api = "https://graphql.redhat.com/api"
SIGNATURE_ID = "67033c8d76860bfe6a094ecf"
@patch("pyxis.graphql_query")
def test_signatures_exist(graphql_query):
# Arrange
args = MagicMock()
args.pyxis_graphql_api = mock_pyxis_graphql_api
args.manifest_digest = "some_digest"
args.repository = "scoheb/a"
reference1 = "quay.io/scoheb/a:abc"
# signature exists
signatures1 = generate_signatures(SIGNATURE_ID, reference1)
graphql_query.side_effect = [
generate_pyxis_response("find_signatures", signatures1),
]
# Act
references = find_signatures_for_repository(
args.pyxis_graphql_api, args.repository, args.manifest_digest
)
assert references
assert len(references) == 1
@patch("pyxis.graphql_query")
def test_signatures_notfound(graphql_query):
# Arrange
args = MagicMock()
args.pyxis_graphql_api = mock_pyxis_graphql_api
args.manifest_digest = "some_digest"
args.repository = "scoheb/a"
# signatures do not exist
graphql_query.side_effect = [
generate_pyxis_response("find_signatures", []),
]
# Act
references = find_signatures_for_repository(
args.pyxis_graphql_api, args.repository, args.manifest_digest
)
assert len(references) == 0
def generate_pyxis_response(query_name, data):
response_json = {
query_name: {
"data": data,
"error": None,
}
}
return response_json
def generate_signatures(id, reference):
signatures = [
{
"_id": id,
"reference": reference,
}
]
return signatures