Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123099
D3586.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
13 KB
Subscribers
None
D3586.diff
View Options
diff --git a/swh/storage/tests/storage_data.py b/swh/storage/tests/storage_data.py
--- a/swh/storage/tests/storage_data.py
+++ b/swh/storage/tests/storage_data.py
@@ -18,8 +18,13 @@
MetadataAuthorityType,
MetadataFetcher,
MetadataTargetType,
+ Person,
RawExtrinsicMetadata,
+ Revision,
+ RevisionType,
SkippedContent,
+ Timestamp,
+ TimestampWithTimezone,
)
@@ -204,141 +209,128 @@
minus_offset = datetime.timezone(datetime.timedelta(minutes=-120))
plus_offset = datetime.timezone(datetime.timedelta(minutes=120))
-revision = {
- "id": hash_to_bytes("066b1b62dbfa033362092af468bf6cfabec230e7"),
- "message": b"hello",
- "author": {
- "name": b"Nicolas Dandrimont",
- "email": b"nicolas@example.com",
- "fullname": b"Nicolas Dandrimont <nicolas@example.com> ",
- },
- "date": {
- "timestamp": {"seconds": 1234567890, "microseconds": 0},
- "offset": 120,
- "negative_utc": False,
- },
- "committer": {
- "name": b"St\xc3fano Zacchiroli",
- "email": b"stefano@example.com",
- "fullname": b"St\xc3fano Zacchiroli <stefano@example.com>",
- },
- "committer_date": {
- "timestamp": {"seconds": 1123456789, "microseconds": 0},
- "offset": 0,
- "negative_utc": True,
- },
- "parents": (b"01234567890123456789", b"23434512345123456789"),
- "type": "git",
- "directory": hash_to_bytes("34f335a750111ca0a8b64d8034faec9eedc396be"), # dir
- "metadata": {
+revision = Revision(
+ id=hash_to_bytes("066b1b62dbfa033362092af468bf6cfabec230e7"),
+ message=b"hello",
+ author=Person(
+ name=b"Nicolas Dandrimont",
+ email=b"nicolas@example.com",
+ fullname=b"Nicolas Dandrimont <nicolas@example.com> ",
+ ),
+ date=TimestampWithTimezone(
+ timestamp=Timestamp(seconds=1234567890, microseconds=0),
+ offset=120,
+ negative_utc=False,
+ ),
+ committer=Person(
+ name=b"St\xc3fano Zacchiroli",
+ email=b"stefano@example.com",
+ fullname=b"St\xc3fano Zacchiroli <stefano@example.com>",
+ ),
+ committer_date=TimestampWithTimezone(
+ timestamp=Timestamp(seconds=1123456789, microseconds=0),
+ offset=120,
+ negative_utc=False,
+ ),
+ parents=(),
+ type=RevisionType.GIT,
+ directory=directory.id,
+ metadata={
"checksums": {"sha1": "tarball-sha1", "sha256": "tarball-sha256",},
"signed-off-by": "some-dude",
},
- "extra_headers": (
+ extra_headers=(
(b"gpgsig", b"test123"),
(b"mergetag", b"foo\\bar"),
(b"mergetag", b"\x22\xaf\x89\x80\x01\x00"),
),
- "synthetic": True,
-}
-
-revision2 = {
- "id": hash_to_bytes("df7a6f6a99671fb7f7343641aff983a314ef6161"),
- "message": b"hello again",
- "author": {
- "name": b"Roberto Dicosmo",
- "email": b"roberto@example.com",
- "fullname": b"Roberto Dicosmo <roberto@example.com>",
- },
- "date": {
- "timestamp": {"seconds": 1234567843, "microseconds": 220000,},
- "offset": -720,
- "negative_utc": False,
- },
- "committer": {
- "name": b"tony",
- "email": b"ar@dumont.fr",
- "fullname": b"tony <ar@dumont.fr>",
- },
- "committer_date": {
- "timestamp": {"seconds": 1123456789, "microseconds": 0},
- "offset": 0,
- "negative_utc": False,
- },
- "parents": (b"01234567890123456789",),
- "type": "git",
- "directory": hash_to_bytes("8505808532953da7d2581741f01b29c04b1cb9ab"), # dir2
- "metadata": None,
- "extra_headers": (),
- "synthetic": False,
-}
-
-revision3 = {
- "id": hash_to_bytes("2cbd7bb22c653bbb23a29657852a50a01b591d46"),
- "message": b"a simple revision with no parents this time",
- "author": {
- "name": b"Roberto Dicosmo",
- "email": b"roberto@example.com",
- "fullname": b"Roberto Dicosmo <roberto@example.com>",
- },
- "date": {
- "timestamp": {"seconds": 1234567843, "microseconds": 220000,},
- "offset": -720,
- "negative_utc": False,
- },
- "committer": {
- "name": b"tony",
- "email": b"ar@dumont.fr",
- "fullname": b"tony <ar@dumont.fr>",
- },
- "committer_date": {
- "timestamp": {"seconds": 1127351742, "microseconds": 0},
- "offset": 0,
- "negative_utc": False,
- },
- "parents": (),
- "type": "git",
- "directory": hash_to_bytes("8505808532953da7d2581741f01b29c04b1cb9ab"), # dir2
- "metadata": None,
- "extra_headers": (),
- "synthetic": True,
-}
+ synthetic=True,
+)
-revision4 = {
- "id": hash_to_bytes("88cd5126fc958ed70089d5340441a1c2477bcc20"),
- "message": b"parent of self.revision2",
- "author": {
- "name": b"me",
- "email": b"me@soft.heri",
- "fullname": b"me <me@soft.heri>",
- },
- "date": {
- "timestamp": {"seconds": 1244567843, "microseconds": 220000,},
- "offset": -720,
- "negative_utc": False,
- },
- "committer": {
- "name": b"committer-dude",
- "email": b"committer@dude.com",
- "fullname": b"committer-dude <committer@dude.com>",
- },
- "committer_date": {
- "timestamp": {"seconds": 1244567843, "microseconds": 220000,},
- "offset": -720,
- "negative_utc": False,
- },
- "parents": (
- hash_to_bytes("2cbd7bb22c653bbb23a29657852a50a01b591d46"),
- ), # revision3
- "type": "git",
- "directory": hash_to_bytes("34f335a750111ca0a8b64d8034faec9eedc396be"), # dir
- "metadata": None,
- "extra_headers": (),
- "synthetic": False,
-}
+revision2 = Revision(
+ id=hash_to_bytes("df7a6f6a99671fb7f7343641aff983a314ef6161"),
+ message=b"hello again",
+ author=Person(
+ name=b"Roberto Dicosmo",
+ email=b"roberto@example.com",
+ fullname=b"Roberto Dicosmo <roberto@example.com>",
+ ),
+ date=TimestampWithTimezone(
+ timestamp=Timestamp(seconds=1234567843, microseconds=220000,),
+ offset=-720,
+ negative_utc=False,
+ ),
+ committer=Person(
+ name=b"tony", email=b"ar@dumont.fr", fullname=b"tony <ar@dumont.fr>",
+ ),
+ committer_date=TimestampWithTimezone(
+ timestamp=Timestamp(seconds=1123456789, microseconds=220000,),
+ offset=0,
+ negative_utc=False,
+ ),
+ parents=tuple([revision.id]),
+ type=RevisionType.GIT,
+ directory=directory2.id,
+ metadata=None,
+ extra_headers=(),
+ synthetic=False,
+)
-revisions = (revision, revision2, revision3, revision4)
+revision3 = Revision(
+ id=hash_to_bytes("2cbd7bb22c653bbb23a29657852a50a01b591d46"),
+ message=b"a simple revision with no parents this time",
+ author=Person(
+ name=b"Roberto Dicosmo",
+ email=b"roberto@example.com",
+ fullname=b"Roberto Dicosmo <roberto@example.com>",
+ ),
+ date=TimestampWithTimezone(
+ timestamp=Timestamp(seconds=1234567843, microseconds=220000,),
+ offset=-720,
+ negative_utc=False,
+ ),
+ committer=Person(
+ name=b"tony", email=b"ar@dumont.fr", fullname=b"tony <ar@dumont.fr>",
+ ),
+ committer_date=TimestampWithTimezone(
+ timestamp=Timestamp(seconds=1127351742, microseconds=220000,),
+ offset=0,
+ negative_utc=False,
+ ),
+ parents=tuple([revision.id, revision2.id]),
+ type=RevisionType.GIT,
+ directory=directory2.id,
+ metadata=None,
+ extra_headers=(),
+ synthetic=True,
+)
+revision4 = Revision(
+ id=hash_to_bytes("88cd5126fc958ed70089d5340441a1c2477bcc20"),
+ message=b"parent of self.revision2",
+ author=Person(name=b"me", email=b"me@soft.heri", fullname=b"me <me@soft.heri>",),
+ date=TimestampWithTimezone(
+ timestamp=Timestamp(seconds=1234567843, microseconds=220000,),
+ offset=-720,
+ negative_utc=False,
+ ),
+ committer=Person(
+ name=b"committer-dude",
+ email=b"committer@dude.com",
+ fullname=b"committer-dude <committer@dude.com>",
+ ),
+ committer_date=TimestampWithTimezone(
+ timestamp=Timestamp(seconds=1244567843, microseconds=220000,),
+ offset=-720,
+ negative_utc=False,
+ ),
+ parents=tuple([revision3.id]),
+ type=RevisionType.GIT,
+ directory=directory.id,
+ metadata=None,
+ extra_headers=(),
+ synthetic=False,
+)
origin = {
"url": "file:///dev/null",
@@ -546,7 +538,7 @@
visit=42,
snapshot=parse_swhid(f"swh:1:snp:{hash_to_hex(snapshot['id'])}"),
release=parse_swhid(f"swh:1:rel:{hash_to_hex(release['id'])}"),
- revision=parse_swhid(f"swh:1:rev:{hash_to_hex(revision['id'])}"),
+ revision=parse_swhid(f"swh:1:rev:{hash_to_hex(revision.id)}"),
directory=parse_swhid(f"swh:1:dir:{hash_to_hex(directory.id)}"),
path=b"/foo/bar",
)
diff --git a/swh/storage/tests/test_pytest_plugin.py b/swh/storage/tests/test_pytest_plugin.py
--- a/swh/storage/tests/test_pytest_plugin.py
+++ b/swh/storage/tests/test_pytest_plugin.py
@@ -33,6 +33,7 @@
"content",
"skipped_content",
"directory",
+ "revision",
"fetcher",
"authority",
"origin_metadata",
diff --git a/swh/storage/tests/test_storage.py b/swh/storage/tests/test_storage.py
--- a/swh/storage/tests/test_storage.py
+++ b/swh/storage/tests/test_storage.py
@@ -953,28 +953,23 @@
assert [Revision.from_dict(r) for r in res2] == [revision2, revision]
def test_revision_log(self, swh_storage, sample_data_model):
- revision3, revision4 = sample_data_model["revision"][2:4]
+ revision1, revision2, revision3, revision4 = sample_data_model["revision"][:4]
- # data.revision4 -is-child-of-> data.revision3
- swh_storage.revision_add([revision3, revision4])
+ # rev4 -is-child-of-> rev3 -> rev1, (rev2 -> rev1)
+ swh_storage.revision_add([revision1, revision2, revision3, revision4])
# when
results = list(swh_storage.revision_log([revision4.id]))
# for comparison purposes
actual_results = [Revision.from_dict(r) for r in results]
- assert len(actual_results) == 2 # rev4 -child-> rev3
- assert actual_results == [revision4, revision3]
-
- assert list(swh_storage.journal_writer.journal.objects) == [
- ("revision", revision3),
- ("revision", revision4),
- ]
+ assert len(actual_results) == 4 # rev4 -child-> rev3 -> rev1, (rev2 -> rev1)
+ assert actual_results == [revision4, revision3, revision1, revision2]
def test_revision_log_with_limit(self, swh_storage, sample_data_model):
- revision3, revision4 = sample_data_model["revision"][2:4]
+ revision1, revision2, revision3, revision4 = sample_data_model["revision"][:4]
- # data.revision4 -is-child-of-> data.revision3
+ # revision4 -is-child-of-> revision3
swh_storage.revision_add([revision3, revision4])
results = list(swh_storage.revision_log([revision4.id], 1))
@@ -988,25 +983,27 @@
assert rev_log == []
def test_revision_shortlog(self, swh_storage, sample_data_model):
- revision3, revision4 = sample_data_model["revision"][2:4]
+ revision1, revision2, revision3, revision4 = sample_data_model["revision"][:4]
- # data.revision4 -is-child-of-> data.revision3
- swh_storage.revision_add([revision3, revision4])
+ # rev4 -is-child-of-> rev3 -> (rev1, rev2); rev2 -> rev1
+ swh_storage.revision_add([revision1, revision2, revision3, revision4])
- # when
results = list(swh_storage.revision_shortlog([revision4.id]))
-
actual_results = [[id, tuple(parents)] for (id, parents) in results]
- assert len(actual_results) == 2 # rev4 -child-> rev3
- assert list(actual_results[0]) == [revision4.id, revision4.parents]
- assert list(actual_results[1]) == [revision3.id, revision3.parents]
+ assert len(actual_results) == 4
+ assert actual_results == [
+ [revision4.id, revision4.parents],
+ [revision3.id, revision3.parents],
+ [revision1.id, revision1.parents],
+ [revision2.id, revision2.parents],
+ ]
def test_revision_shortlog_with_limit(self, swh_storage, sample_data_model):
- revision3, revision4 = sample_data_model["revision"][2:4]
+ revision1, revision2, revision3, revision4 = sample_data_model["revision"][:4]
- # data.revision4 -is-child-of-> data.revision3
- swh_storage.revision_add([revision3, revision4])
+ # revision4 -is-child-of-> revision3
+ swh_storage.revision_add([revision1, revision2, revision3, revision4])
results = list(swh_storage.revision_shortlog([revision4.id], 1))
actual_results = [[id, tuple(parents)] for (id, parents) in results]
@@ -1025,12 +1022,13 @@
assert actual_revisions[1] is None
def test_revision_get_no_parents(self, swh_storage, sample_data_model):
- revision = sample_data_model["revision"][2]
+ revision = sample_data_model["revision"][0]
swh_storage.revision_add([revision])
get = list(swh_storage.revision_get([revision.id]))
assert len(get) == 1
+ assert revision.parents == ()
assert tuple(get[0]["parents"]) == () # no parents on this one
def test_revision_get_random(self, swh_storage, sample_data_model):
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 17, 9:24 PM (2 d, 9 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3218720
Attached To
D3586: storage_data: Expose revisions as model objects
Event Timeline
Log In to Comment