When looking for FAS user try bugzilla mail as well
Currently only emails field in fasjson is checked for corresponding e-mail, but in case the bugzilla e-mail is set we don't find the user. Let's check the bugzilla mail as second option. Signed-off-by: Michal Konečný <mkonecny@redhat.com>
This commit is contained in:
parent
111062d348
commit
109aed5898
2 changed files with 26 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
from unittest.mock import Mock, patch
|
||||
from unittest.mock import call, Mock, patch
|
||||
|
||||
from fasjson_client.errors import ClientError
|
||||
import pytest
|
||||
|
@ -183,6 +183,28 @@ class TestFedoraAccountFASJSON:
|
|||
output = toddlers.utils.fedora_account.get_user_by_email("scoady@fp.o")
|
||||
assert output == {"username": "scoady", "emails": ["scoady@fp.o"]}
|
||||
|
||||
@patch("toddlers.utils.fedora_account.get_fasjson")
|
||||
def test_get_user_by_bzemail(self, mock_fas):
|
||||
"""
|
||||
Assert that bugzilla e-mail is searched for when there is no result in
|
||||
primary e-mail.
|
||||
"""
|
||||
user = [{"username": "scoady", "rhbzemail": "scoady@fp.o"}]
|
||||
empty_result = Mock()
|
||||
empty_result.result = []
|
||||
result = Mock()
|
||||
result.result = user
|
||||
server = Mock()
|
||||
server.search.side_effect = [empty_result, result]
|
||||
mock_fas.return_value = server
|
||||
|
||||
output = toddlers.utils.fedora_account.get_user_by_email("scoady@fp.o")
|
||||
assert output == {"username": "scoady", "rhbzemail": "scoady@fp.o"}
|
||||
|
||||
server.search.assert_has_calls(
|
||||
[call(email="scoady@fp.o"), call(rhbzemail="scoady@fp.o")]
|
||||
)
|
||||
|
||||
@patch("toddlers.utils.fedora_account.get_fasjson")
|
||||
def test_get_user_by_email_empty(self, mock_fas):
|
||||
user = []
|
||||
|
|
|
@ -99,6 +99,9 @@ def get_user_by_email(email: str) -> Optional[dict]:
|
|||
user = None
|
||||
try:
|
||||
result = fasjson.search(email=email).result or []
|
||||
if not result:
|
||||
# Try the bugzilla email as well
|
||||
result = fasjson.search(rhbzemail=email).result or []
|
||||
if result:
|
||||
user = result[0]
|
||||
except ClientError:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue