コード例 #1
0
 def test_fail(self, mock_course_presistence):
     course_api = CourseApi(mock_course_presistence)
     course = fake_course()
     err = Err(fake.pystr())
     mock_course_presistence.create_course = MagicMock(return_value=err)
     assert course_api.create_course(course.course_code) == err
     mock_course_presistence.create_course.assert_called_once_with(course)
コード例 #2
0
 def test_success(self, mock_course_presistence):
     course_api = CourseApi(mock_course_presistence)
     course = fake_course()
     mock_course_presistence.create_course = MagicMock(
         return_value=Ok(course))
     assert course_api.create_course(course.course_code).unwrap() == course
     mock_course_presistence.create_course.assert_called_once_with(course)
コード例 #3
0
ファイル: test_course_mutations.py プロジェクト: sakshaat/ohs
def test_create_course_fail(schema, mock_context, create_course_query):
    context, course_api, instructor_api = mock_context
    course = fake_course()
    error = fake.pystr()
    course_api.create_course = MagicMock(return_value=Err(error))
    result = schema.execute(
        create_course_query,
        variables={"courseCode": course.course_code},
        context=context,
    )
    assert error in str(result.errors[0])
    course_api.create_course.assert_called_once_with(course.course_code)
コード例 #4
0
ファイル: test_course_mutations.py プロジェクト: sakshaat/ohs
def test_create_course(schema, mock_context, create_course_query):
    context, course_api, instructor_api = mock_context
    course = fake_course()
    course_api.create_course = MagicMock(return_value=Ok(course))
    result = schema.execute(
        create_course_query,
        variables={"courseCode": course.course_code},
        context=context,
    )
    assert not result.errors
    assert result.data == {"createCourse": {"courseCode": course.course_code}}
    course_api.create_course.assert_called_once_with(course.course_code)
コード例 #5
0
 def fake_domain(self):
     return fake_course()
コード例 #6
0
    course_api = CourseApi(mock_course_presistence)
    mock_course_presistence.query_courses = MagicMock(return_value=expected)
    assert course_api.query_courses(filters) == expected
    mock_course_presistence.query_courses.assert_called_once_with(filters)


@pytest.mark.parametrize("filters,expected",
                         [(None, list_fakes(fake_section, 5))])
def test_query_sections(mock_course_presistence, filters, expected):
    course_api = CourseApi(mock_course_presistence)
    mock_course_presistence.query_sections = MagicMock(return_value=expected)
    assert course_api.query_sections(filters) == expected
    mock_course_presistence.query_sections.assert_called_once_with(filters)


@pytest.mark.parametrize("expected", [NONE, Some(fake_course())])
def test_get_course(mock_course_presistence, expected):
    course_api = CourseApi(mock_course_presistence)
    mock_course_presistence.get_course = MagicMock(return_value=expected)
    course_code = expected.map_or(lambda c: c.course_code, None)
    assert course_api.get_course(course_code) == expected
    mock_course_presistence.get_course.assert_called_once_with(course_code)


@pytest.mark.parametrize("expected", [NONE, Some(fake_section())])
def test_get_section(mock_course_presistence, expected):
    course_api = CourseApi(mock_course_presistence)
    expected_identity = expected.map_or(lambda section: section.identity, None)
    mock_course_presistence.get_section = MagicMock(return_value=expected)
    assert course_api.get_section(expected_identity) == expected
    mock_course_presistence.get_section.assert_called_once_with(
コード例 #7
0
 def test_duplicate(self, course_persistence):
     course = fake_course()
     course_persistence.get_course = MagicMock(return_value=Some(course))
     assert (course_persistence.create_course(course).unwrap_err() ==
             f"Course {course} already exists")
コード例 #8
0
 def test_success(self, course_persistence):
     course = fake_course()
     assert course_persistence.create_course(course).unwrap() == course
     assert course_persistence.get_course(
         course.course_code).unwrap() == course
     course_persistence.delete_course(course.course_code)