def test_course_params(db, course_strange): # confirm named arguments work even when reversed found_by_code = Course.find_by_code(org_id=course_strange.org_id, db=db, code=course_strange.course_code) assert found_by_code.course_code == course_strange.course_code # confirm that putting the positional values the wrong way round will [probably] fail with pytest.raises(ValueError): found_by_code = Course.find_by_code(db, course_strange.org_id, course_strange.course_code) # test for unbexpected param with pytest.raises(TypeError): Course.find_by_pk(primary_key=course_strange.id, db=db) with pytest.raises(TypeError): found_by_code = Course.find_by_code(course_code=course_strange.course_code, org_id=course_strange.org_id, db=db) with pytest.raises(TypeError): found_by_code = Course.find_by_code(code=course_strange.course_code, id=course_strange.org_id, db=db) with pytest.raises(TypeError): Course.find_by_org(id=course_strange.org_id, db=db)
def test_course(db, course_strange): assert course_strange.course_code == "Strange" assert course_strange.course_title == "Damnation Alley" with pytest.raises(TypeError): found_by_pk = Course.find_by_pk() with pytest.raises(TypeError): found_by_pk = Course.find_by_pk(db) with pytest.raises(ValueError): found_by_pk = Course.find_by_pk(db, None) with pytest.raises(TypeError): found_by_pk = Course.find_by_pk(db, "abc") found_by_pk = Course.find_by_pk(db, course_strange.id) assert found_by_pk.id == course_strange.id found_by_pk = Course.find_by_pk(db, course_strange.id + 10) assert found_by_pk is None with pytest.raises(TypeError): found_by_code = Course.find_by_code(db, course_strange.course_code) with pytest.raises(ValueError): found_by_code = Course.find_by_code(db, None, course_strange.org_id) with pytest.raises(ValueError): found_by_code = Course.find_by_code(db, course_strange.course_code, None) found_by_code = Course.find_by_code(db, course_strange.course_code, course_strange.org_id) assert found_by_code.course_code == course_strange.course_code assert str(found_by_code) == f"Course/{course_strange.course_code} {course_strange.course_title}" # in real code, org_id is probably a string, so lets confirm that works found_by_code = Course.find_by_code(db, course_strange.course_code, "1") assert found_by_code.course_code == course_strange.course_code found_by_code = Course.find_by_code(db, "SANE", course_strange.org_id) assert found_by_code is None found_by_code = Course.find_by_code(db, course_strange.course_code, course_strange.org_id + 10) assert found_by_code is None