diff --git a/gazu/person.py b/gazu/person.py index 5ca9e20e..a9841e60 100644 --- a/gazu/person.py +++ b/gazu/person.py @@ -95,15 +95,15 @@ def get_department_by_name(name, client=default): @cache -def get_department(id, client=default): +def get_department(department_id, client=default): """ Args: - id (str): An uuid identifying a department. + department_id (str): An uuid identifying a department. Returns: - dict: Department corresponding to given id. + dict: Department corresponding to given department_id. """ - return raw.fetch_first("departments", {"id": id}, client=client) + return raw.fetch_one("departments", department_id, client=client) @cache diff --git a/tests/test_person.py b/tests/test_person.py index 717bd03d..5bbaad7b 100644 --- a/tests/test_person.py +++ b/tests/test_person.py @@ -53,6 +53,39 @@ def test_get_person_by_full_name(self): person = gazu.person.get_person_by_full_name("", "John", "Doe") self.assertEqual(person["id"], "person-1") + def test_get_department_by_name(self): + with requests_mock.mock() as mock: + mock_route( + mock, + "GET", + "data/departments?name=department-1", + text=[{"name": "department-1"}], + ) + department = gazu.person.get_department_by_name("department-1") + self.assertEqual(department["name"], "department-1") + + def test_get_department(self): + with requests_mock.mock() as mock: + mock_route( + mock, + "GET", + "data/departments/%s" % fakeid("department-1"), + text={"name": "department-1"}, + ) + department = gazu.person.get_department(fakeid("department-1")) + self.assertEqual(department["name"], "department-1") + + def test_new_department(self): + with requests_mock.mock() as mock: + result = {"name": "department-1"} + mock_route( + mock, "GET", "data/departments?name=department-1", text=[] + ) + mock_route(mock, "POST", "data/departments", text=result) + self.assertEqual( + gazu.person.new_department("department-1"), result + ) + def test_get_person_by_desktop_login(self): with requests_mock.mock() as mock: mock.get(