Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/tests/test_git_bare_cooker.py
Show First 20 Lines • Show All 55 Lines • ▼ Show 20 Lines | [ | ||||
), | ), | ||||
param(True, True, True, True, id="snp, updated graph, w/ tag, tree, and blob"), | param(True, True, True, True, id="snp, updated graph, w/ tag, tree, and blob"), | ||||
], | ], | ||||
) | ) | ||||
def test_graph_revisions(swh_storage, up_to_date_graph, snapshot, tag, weird_branches): | def test_graph_revisions(swh_storage, up_to_date_graph, snapshot, tag, weird_branches): | ||||
r""" | r""" | ||||
Build objects:: | Build objects:: | ||||
rel2 <------ snp | snp | ||||
| / | \ | /|||\ | ||||
v / v \ | / ||| \ | ||||
rev1 <------ rev2 <----° dir4 \ | rel2 <----° /|\ \----> rel4 | ||||
| | | \ | | / | \ | | ||||
v v v \ | v / v \ v | ||||
dir1 dir2 dir3 \ | rev1 <------ rev2 <----° dir4 \ rel3 | ||||
| / | | | | | | | \ | | ||||
v / v v v | v v v \ | | ||||
cnt1 <----° cnt2 cnt3 cnt4 | dir1 dir2 dir3 | | | ||||
| / | | | | | |||||
v / v v v v | |||||
cnt1 <----° cnt2 cnt3 cnt4 cnt5 | |||||
If up_to_date_graph is true, then swh-graph contains all objects. | If up_to_date_graph is true, then swh-graph contains all objects. | ||||
Else, cnt4, dir4, rev2, rel2, and snp are missing from the graph. | Else, cnt4, cnt5, dir4, rev2, rel2, rel3, and snp are missing from the graph. | ||||
If tag is False, rel2 is excluded. | If tag is False, rel2 is excluded. | ||||
If weird_branches is False, dir4 and cnt4 are excluded. | If weird_branches is False, dir4, cnt4, rel3, rel4, and cnt5 are excluded. | ||||
""" | """ | ||||
from swh.graph.naive_client import NaiveClient as GraphClient | from swh.graph.naive_client import NaiveClient as GraphClient | ||||
# Create objects: | # Create objects: | ||||
date = TimestampWithTimezone.from_datetime( | date = TimestampWithTimezone.from_datetime( | ||||
datetime.datetime(2021, 5, 7, 8, 43, 59, tzinfo=datetime.timezone.utc) | datetime.datetime(2021, 5, 7, 8, 43, 59, tzinfo=datetime.timezone.utc) | ||||
) | ) | ||||
author = Person.from_fullname(b"Foo <foo@example.org>") | author = Person.from_fullname(b"Foo <foo@example.org>") | ||||
cnt1 = Content.from_data(b"correct") | cnt1 = Content.from_data(b"correct") | ||||
cnt2 = Content.from_data(b"horse") | cnt2 = Content.from_data(b"horse") | ||||
cnt3 = Content.from_data(b"battery") | cnt3 = Content.from_data(b"battery") | ||||
cnt4 = Content.from_data(b"staple") | cnt4 = Content.from_data(b"staple") | ||||
cnt5 = Content.from_data(b"Tr0ub4dor&3") | |||||
dir1 = Directory( | dir1 = Directory( | ||||
entries=( | entries=( | ||||
DirectoryEntry( | DirectoryEntry( | ||||
name=b"file1", | name=b"file1", | ||||
type="file", | type="file", | ||||
perms=DentryPerms.content, | perms=DentryPerms.content, | ||||
target=cnt1.sha1_git, | target=cnt1.sha1_git, | ||||
), | ), | ||||
▲ Show 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | def test_graph_revisions(swh_storage, up_to_date_graph, snapshot, tag, weird_branches): | ||||
rel2 = Release( | rel2 = Release( | ||||
name=b"1.0.0", | name=b"1.0.0", | ||||
message=b"tag2", | message=b"tag2", | ||||
target_type=ObjectType.REVISION, | target_type=ObjectType.REVISION, | ||||
target=rev2.id, | target=rev2.id, | ||||
synthetic=True, | synthetic=True, | ||||
) | ) | ||||
rel3 = Release( | |||||
name=b"1.0.0-blob", | |||||
message=b"tagged-blob", | |||||
target_type=ObjectType.CONTENT, | |||||
target=cnt5.sha1_git, | |||||
synthetic=True, | |||||
) | |||||
rel4 = Release( | |||||
name=b"1.0.0-weird", | |||||
message=b"weird release", | |||||
target_type=ObjectType.RELEASE, | |||||
target=rel3.id, | |||||
synthetic=True, | |||||
) | |||||
# Create snapshot: | # Create snapshot: | ||||
branches = { | branches = { | ||||
b"refs/heads/master": SnapshotBranch( | b"refs/heads/master": SnapshotBranch( | ||||
target=rev2.id, target_type=TargetType.REVISION | target=rev2.id, target_type=TargetType.REVISION | ||||
), | ), | ||||
} | } | ||||
if tag: | if tag: | ||||
branches[b"refs/tags/1.0.0"] = SnapshotBranch( | branches[b"refs/tags/1.0.0"] = SnapshotBranch( | ||||
target=rel2.id, target_type=TargetType.RELEASE | target=rel2.id, target_type=TargetType.RELEASE | ||||
) | ) | ||||
if weird_branches: | if weird_branches: | ||||
branches[b"refs/heads/tree-ref"] = SnapshotBranch( | branches[b"refs/heads/tree-ref"] = SnapshotBranch( | ||||
target=dir4.id, target_type=TargetType.DIRECTORY | target=dir4.id, target_type=TargetType.DIRECTORY | ||||
) | ) | ||||
branches[b"refs/heads/blob-ref"] = SnapshotBranch( | branches[b"refs/heads/blob-ref"] = SnapshotBranch( | ||||
target=cnt4.sha1_git, target_type=TargetType.CONTENT | target=cnt4.sha1_git, target_type=TargetType.CONTENT | ||||
) | ) | ||||
branches[b"refs/tags/1.0.0-weird"] = SnapshotBranch( | |||||
target=rel4.id, target_type=TargetType.RELEASE | |||||
) | |||||
snp = Snapshot(branches=branches) | snp = Snapshot(branches=branches) | ||||
# "Fill" swh-graph | # "Fill" swh-graph | ||||
if up_to_date_graph: | if up_to_date_graph: | ||||
nodes = [cnt1, cnt2, dir1, dir2, rev1, rev2, snp] | nodes = [cnt1, cnt2, dir1, dir2, rev1, rev2, snp] | ||||
edges = [ | edges = [ | ||||
(dir1, cnt1), | (dir1, cnt1), | ||||
(dir2, cnt1), | (dir2, cnt1), | ||||
(dir2, cnt2), | (dir2, cnt2), | ||||
(rev1, dir1), | (rev1, dir1), | ||||
(rev2, dir2), | (rev2, dir2), | ||||
(rev2, rev1), | (rev2, rev1), | ||||
(snp, rev2), | (snp, rev2), | ||||
] | ] | ||||
if tag: | if tag: | ||||
nodes.append(rel2) | nodes.append(rel2) | ||||
edges.append((rel2, rev2)) | edges.append((rel2, rev2)) | ||||
edges.append((snp, rel2)) | edges.append((snp, rel2)) | ||||
if weird_branches: | if weird_branches: | ||||
nodes.extend([cnt3, cnt4, dir3, dir4]) | nodes.extend([cnt3, cnt4, cnt5, dir3, dir4, rel3, rel4]) | ||||
edges.extend([(dir3, cnt3), (dir4, dir3), (snp, dir4), (snp, cnt4)]) | edges.extend( | ||||
[ | |||||
(dir3, cnt3), | |||||
(dir4, dir3), | |||||
(snp, dir4), | |||||
(snp, cnt4), | |||||
(snp, rel4), | |||||
(rel4, rel3), | |||||
(rel3, cnt5), | |||||
] | |||||
) | |||||
else: | else: | ||||
nodes = [cnt1, cnt2, cnt3, dir1, dir2, dir3, rev1] | nodes = [cnt1, cnt2, cnt3, dir1, dir2, dir3, rev1] | ||||
edges = [ | edges = [ | ||||
(dir1, cnt1), | (dir1, cnt1), | ||||
(dir2, cnt1), | (dir2, cnt1), | ||||
(dir2, cnt2), | (dir2, cnt2), | ||||
(dir3, cnt3), | (dir3, cnt3), | ||||
(rev1, dir1), | (rev1, dir1), | ||||
] | ] | ||||
if tag: | if tag: | ||||
nodes.append(rel2) | nodes.append(rel2) | ||||
if weird_branches: | if weird_branches: | ||||
nodes.extend([cnt3, dir3]) | nodes.extend([cnt3, dir3]) | ||||
edges.extend([(dir3, cnt3)]) | edges.extend([(dir3, cnt3)]) | ||||
nodes = [str(n.swhid()) for n in nodes] | nodes = [str(n.swhid()) for n in nodes] | ||||
edges = [(str(s.swhid()), str(d.swhid())) for (s, d) in edges] | edges = [(str(s.swhid()), str(d.swhid())) for (s, d) in edges] | ||||
# Add all objects to storage | # Add all objects to storage | ||||
swh_storage.content_add([cnt1, cnt2, cnt3, cnt4]) | swh_storage.content_add([cnt1, cnt2, cnt3, cnt4, cnt5]) | ||||
swh_storage.directory_add([dir1, dir2, dir3, dir4]) | swh_storage.directory_add([dir1, dir2, dir3, dir4]) | ||||
swh_storage.revision_add([rev1, rev2]) | swh_storage.revision_add([rev1, rev2]) | ||||
swh_storage.release_add([rel2]) | swh_storage.release_add([rel2, rel3, rel4]) | ||||
swh_storage.snapshot_add([snp]) | swh_storage.snapshot_add([snp]) | ||||
# Add spy on swh_storage, to make sure revision_log is not called | # Add spy on swh_storage, to make sure revision_log is not called | ||||
# (the graph must be used instead) | # (the graph must be used instead) | ||||
swh_storage = unittest.mock.MagicMock(wraps=swh_storage) | swh_storage = unittest.mock.MagicMock(wraps=swh_storage) | ||||
# Add all objects to graph | # Add all objects to graph | ||||
swh_graph = unittest.mock.Mock(wraps=GraphClient(nodes=nodes, edges=edges)) | swh_graph = unittest.mock.Mock(wraps=GraphClient(nodes=nodes, edges=edges)) | ||||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |