Skip to content

Commit

Permalink
Merge pull request #316 from EvanBldy/master
Browse files Browse the repository at this point in the history
various improvements
  • Loading branch information
EvanBldy authored Feb 20, 2024
2 parents d707956 + 084b69d commit 7df69d3
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/psf/black
rev: 23.9.1
rev: 24.2.0
hooks:
- id: black
25 changes: 8 additions & 17 deletions gazu/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,13 @@ def get_person_by_email(email, client=default):

@cache
def get_person_by_full_name(
full_name,
first_name=None,
last_name=None,
client=default
full_name, first_name=None, last_name=None, client=default
):
"""
Args:
full_name (str): User's full name
first_name (str): User's first name
last_name (str): User's last name
Returns:
dict: Person corresponding to given name.
Expand All @@ -142,19 +141,11 @@ def get_person_by_full_name(
client=client,
)
else:
if " " in full_name:
first_name, last_name = full_name.lower().split(" ")
else:
first_name, last_name = full_name.lower().strip(), ""
for person in all_persons():
is_right_first_name = (
first_name == person["first_name"].lower().strip()
)
is_right_last_name = (
len(last_name) == 0 or last_name == person["last_name"].lower()
)
if is_right_first_name and is_right_last_name:
return person
return raw.fetch_first(
"persons",
{"full_name": full_name},
client=client,
)
return None


Expand Down
8 changes: 4 additions & 4 deletions gazu/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,10 +367,10 @@ def update_metadata_descriptor(project, metadata_descriptor, client=default):
dict: The updated metadata descriptor.
"""
if "departments" in metadata_descriptor:
metadata_descriptor[
"departments"
] = normalize_list_of_models_for_links(
metadata_descriptor["departments"]
metadata_descriptor["departments"] = (
normalize_list_of_models_for_links(
metadata_descriptor["departments"]
)
)

project = normalize_model_parameter(project)
Expand Down
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@ test =
requests_mock

lint =
black==24.1.1; python_version >= '3.8'
pre-commit==3.6.1; python_version >= '3.9'
black==24.2.0; python_version >= '3.8'
pre-commit==3.6.2; python_version >= '3.9'
35 changes: 7 additions & 28 deletions tests/test_person.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,36 @@ def test_all(self):
def test_get_person_by_full_name(self):
with requests_mock.mock() as mock:
mock.get(
gazu.client.get_full_url("data/persons"),
gazu.client.get_full_url("data/persons?full_name=John Doe"),
text=json.dumps(
[
{
"first_name": "John",
"last_name": "Doe",
"id": "person-1",
},
{
"first_name": "Alex",
"last_name": "Doe",
"id": "person-2",
},
{
"first_name": "Ema",
"last_name": "Doe",
"id": "person-3",
},
]
),
)
person = gazu.person.get_person_by_full_name("John Doe")
self.assertEqual(person["id"], "person-1")
with requests_mock.mock() as mock:
mock.get(
gazu.client.get_full_url("data/persons"),
gazu.client.get_full_url(
"data/persons?first_name=John&last_name=Doe"
),
text=json.dumps(
[
{
"first_name": "John",
"last_name": "Doe",
"id": "person-01",
},
{
"first_name": "JohnDid",
"last_name": "",
"id": "person-2",
},
{
"first_name": "Ema",
"last_name": "Doe",
"id": "person-3",
"id": "person-1",
},
]
),
)
person = gazu.person.get_person_by_full_name("JohnDid")
self.assertEqual(person["id"], "person-2")
self.assertEqual(
gazu.person.get_person_by_full_name("Unknown"), None
)
person = gazu.person.get_person_by_full_name("", "John", "Doe")
self.assertEqual(person["id"], "person-1")

def test_get_person_by_desktop_login(self):
with requests_mock.mock() as mock:
Expand Down
1 change: 1 addition & 0 deletions tests/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Contains utility routines to be used in gazu tests
"""

import sys
import binascii
import json
Expand Down

0 comments on commit 7df69d3

Please sign in to comment.