-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: change get_or_create_author() to upsert_author(). track username…
…/name/email changes (#1058)
- Loading branch information
1 parent
f38b28c
commit 8d5485f
Showing
2 changed files
with
99 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,10 +41,10 @@ | |
fetch_and_update_pull_request_information_from_commit, | ||
fetch_appropriate_parent_for_commit, | ||
fetch_commit_yaml_and_possibly_store, | ||
get_or_create_author, | ||
get_repo_provider_service, | ||
get_repo_provider_service_by_id, | ||
update_commit_from_provider_info, | ||
upsert_author, | ||
) | ||
from tasks.notify import get_repo_provider_service_for_specific_commit | ||
|
||
|
@@ -721,13 +721,13 @@ async def test_fetch_appropriate_parent_for_commit_multiple_parents( | |
|
||
|
||
@freeze_time("2024-03-28T00:00:00") | ||
def test_get_or_create_author_doesnt_exist(dbsession): | ||
def test_upsert_author_doesnt_exist(dbsession): | ||
service = "github" | ||
author_id = "123" | ||
username = "username" | ||
email = "email" | ||
name = "name" | ||
author = get_or_create_author(dbsession, service, author_id, username, email, name) | ||
author = upsert_author(dbsession, service, author_id, username, email, name) | ||
dbsession.flush() | ||
assert author.free == 0 | ||
assert author is not None | ||
|
@@ -746,31 +746,71 @@ def test_get_or_create_author_doesnt_exist(dbsession): | |
assert author.createstamp.isoformat() == "2024-03-28T00:00:00" | ||
|
||
|
||
def test_get_or_create_author_already_exists(dbsession): | ||
def test_upsert_author_already_exists(dbsession): | ||
username = "username" | ||
email = "[email protected]" | ||
service = "bitbucket" | ||
service_id = "975" | ||
owner = OwnerFactory.create( | ||
service="bitbucket", | ||
service_id="975", | ||
email="different_email@email.com", | ||
username="whoknew", | ||
service=service, | ||
service_id=service_id, | ||
email=email, | ||
username=username, | ||
yaml=dict(a=["12", "3"]), | ||
) | ||
dbsession.add(owner) | ||
dbsession.flush() | ||
service = "bitbucket" | ||
author_id = "975" | ||
username = "username" | ||
email = "email" | ||
name = "name" | ||
author = get_or_create_author(dbsession, service, author_id, username, email, name) | ||
|
||
author = upsert_author(dbsession, service, service_id, username, None, None) | ||
dbsession.flush() | ||
assert author.ownerid == owner.ownerid | ||
assert author.free == 0 | ||
assert author is not None | ||
assert author.service == "bitbucket" | ||
assert author.service_id == "975" | ||
assert author.service == service | ||
assert author.service_id == service_id | ||
assert author.name == owner.name | ||
assert author.email == "[email protected]" | ||
assert author.username == "whoknew" | ||
assert author.email == email | ||
assert author.username == username | ||
assert author.plan_activated_users == [] | ||
assert author.admins == [] | ||
assert author.permission == [] | ||
assert author.integration_id is None | ||
assert author.yaml == {"a": ["12", "3"]} | ||
assert author.oauth_token == owner.oauth_token | ||
assert author.bot_id == owner.bot_id | ||
|
||
|
||
def test_upsert_author_needs_update(dbsession): | ||
username = "username" | ||
email = "[email protected]" | ||
service = "bitbucket" | ||
service_id = "975" | ||
owner = OwnerFactory.create( | ||
service=service, | ||
service_id=service_id, | ||
email=email, | ||
username=username, | ||
yaml=dict(a=["12", "3"]), | ||
) | ||
dbsession.add(owner) | ||
dbsession.flush() | ||
|
||
new_name = "Newt Namenheim" | ||
new_username = "new_username" | ||
new_email = "[email protected]" | ||
author = upsert_author( | ||
dbsession, service, service_id, new_username, new_email, new_name | ||
) | ||
dbsession.flush() | ||
|
||
assert author is not None | ||
assert author.ownerid == owner.ownerid | ||
assert author.free == 0 | ||
assert author.service == service | ||
assert author.service_id == service_id | ||
assert author.name == new_name | ||
assert author.email == new_email | ||
assert author.username == new_username | ||
assert author.plan_activated_users == [] | ||
assert author.admins == [] | ||
assert author.permission == [] | ||
|