Skip to content

Commit

Permalink
Add a test for the examples so it's easier to test when they break
Browse files Browse the repository at this point in the history
  • Loading branch information
dantheman39 committed Feb 1, 2024
1 parent 797a4b3 commit 0141ca3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Empty file added tests/test_examples/__init__.py
Empty file.
30 changes: 30 additions & 0 deletions tests/test_examples/test_departments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from examples import departments


def test_departments():
result = departments.main()
assert not result.errors

deps = result.data["listDepartments"]
assert len(deps) == 1

employees = deps[0]["employees"]
assert len(employees) == 3

def employee_by_name(employees, name):
return [e for e in employees if e["name"] == name][0]

jason = employee_by_name(employees, "Jason")
carmen = employee_by_name(employees, "Carmen")
derek = employee_by_name(employees, "Derek")

# Jason is a manager
assert jason["teamSize"] == 2
assert carmen.get("teamSize") is None

# some sanity checks on optional fields,
# knowing what the test data is
assert jason.get("hiredOn") is None
assert carmen.get("hiredOn") is not None
assert carmen["salary"]["rating"] == "GS-9"
assert derek["salary"] is None

0 comments on commit 0141ca3

Please sign in to comment.