-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
landing_worker: metadata from Revision rather than HgPatchHelper (bug…
… 1936171) (#200) The ultimate goal of this change is to deprecate the back-and-forth use of the HgPatchHelper. This first change allows to confine the parsing of an Hg patch to the Revision object, which allows exposing cleaned-up attribute to the rest of the system. --- * revision: deprecate patch_string in favour of patch * revision: add individual properties for patch metadata (bug 1936171) * landing_worker: use metadata from Revision rather than HgPatchHelper … * test_transplants: add missing job status assertion
- Loading branch information
Showing
6 changed files
with
194 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,26 @@ | ||
from datetime import datetime | ||
from unittest.mock import MagicMock, patch | ||
|
||
import pytest | ||
from django.conf import settings | ||
from django.core.exceptions import ValidationError | ||
|
||
from lando.main.models import Repo | ||
from lando.main.models.revision import Revision | ||
from lando.main.scm import ( | ||
SCM_TYPE_GIT, | ||
SCM_TYPE_HG, | ||
) | ||
|
||
DIFF_ONLY = """ | ||
diff --git a/test.txt b/test.txt | ||
--- a/test.txt | ||
+++ b/test.txt | ||
@@ -1,1 +1,2 @@ | ||
TEST | ||
+adding another line | ||
""".lstrip() | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"git_returncode,hg_returncode,scm_type", | ||
|
@@ -84,3 +95,64 @@ def test__models__Repo__system_path_validator(path, expected_exception): | |
repo.clean_fields() | ||
else: | ||
repo.clean_fields() # Should not raise any exception | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"author, expected", | ||
[ | ||
( | ||
"A. Uthor <[email protected]>", | ||
("A. Uthor", "[email protected]"), | ||
), | ||
( | ||
"[email protected]", | ||
("", "[email protected]"), | ||
), | ||
( | ||
"<[email protected]>", | ||
("", "[email protected]"), | ||
), | ||
( | ||
"A. Uthor", | ||
("A. Uthor", ""), | ||
), | ||
( | ||
"@ Uthor", | ||
("@ Uthor", ""), | ||
), | ||
( | ||
"<@ Uthor>", | ||
("<@ Uthor>", ""), | ||
), | ||
], | ||
) | ||
def test__models__Revision___parse_author_string(author, expected): | ||
assert Revision._parse_author_string(author) == expected | ||
|
||
|
||
@pytest.mark.django_db() | ||
def test__models__Revision__metadata(): | ||
author = "A. Uthor" | ||
email = "[email protected]" | ||
commit_message = """Multiline Commit Message | ||
More lines | ||
""" | ||
timestamp = datetime.now().strftime("%s") | ||
|
||
r = Revision.new_from_patch( | ||
raw_diff=DIFF_ONLY, | ||
patch_data={ | ||
"author_name": author, | ||
"author_email": email, | ||
"commit_message": commit_message, | ||
"timestamp": timestamp, | ||
}, | ||
) | ||
|
||
assert r.author_name == author | ||
assert r.author_email == email | ||
assert r.author == f"{author} <{email}>" | ||
assert r.commit_message == commit_message | ||
assert r.timestamp == timestamp | ||
assert r.diff == DIFF_ONLY |