Esempio n. 1
0
def test_list_acknowledges_multi_marker_feature_flag(plugin_config, tmpdir, monkeypatch):
    plugin_config.CourseDirectory.course_id = "no_course"
    plugin_config.ExchangeList.inbound = True

    plugin = ExchangeList(coursedir=CourseDirectory(config=plugin_config), config=plugin_config)

    def api_request(*args, **kwargs):
        assert args[0] == ("assignments?course_id=no_course")
        assert "method" not in kwargs or kwargs.get("method").lower() == "get"
        return type(
            "Request",
            (object,),
            {
                "status_code": 200,
                "json": (
                    lambda: {
                        "success": True,
                        "value": [
                            {
                                "assignment_id": "assign_1_1",
                                "student_id": 1,
                                "course_id": "no_course",
                                "status": "released",
                                "path": "",
                                "notebooks": [
                                    {
                                        "notebook_id": "assignment-0.6",
                                        "has_exchange_feedback": False,
                                        "feedback_updated": False,
                                        "feedback_timestamp": None,
                                    }
                                ],
                                "timestamp": "2020-01-01 00:00:00.0 00:00",
                            }
                        ],
                    }
                ),
            },
        )

    with patch.object(Exchange, "api_request", side_effect=api_request):
        plugin.start()
    assert plugin.coursedir.submitted_directory == "collected"

    monkeypatch.setenv("NAAS_FEATURE_MULTI_MARKERS", "True")
    plugin = ExchangeList(coursedir=CourseDirectory(config=plugin_config), config=plugin_config)
    with patch.object(Exchange, "api_request", side_effect=api_request):
        plugin.start()
    assert plugin.coursedir.submitted_directory == "submitted"
Esempio n. 2
0
def test_list_normal(plugin_config, tmpdir):
    plugin_config.CourseDirectory.course_id = "no_course"

    plugin = ExchangeList(coursedir=CourseDirectory(config=plugin_config), config=plugin_config)

    def api_request(*args, **kwargs):
        assert args[0] == ("assignments?course_id=no_course")
        assert "method" not in kwargs or kwargs.get("method").lower() == "get"
        return type(
            "Request",
            (object,),
            {
                "status_code": 200,
                "json": (
                    lambda: {
                        "success": True,
                        "value": [
                            {
                                "assignment_id": "assign_1_1",
                                "student_id": 1,
                                "course_id": "no_course",
                                "status": "released",
                                "path": "",
                                "notebooks": [
                                    {
                                        "notebook_id": "assignment-0.6",
                                        "has_exchange_feedback": False,
                                        "feedback_updated": False,
                                        "feedback_timestamp": None,
                                    }
                                ],
                                "timestamp": "2020-01-01 00:00:00.0 00:00",
                            }
                        ],
                    }
                ),
            },
        )

    with patch.object(Exchange, "api_request", side_effect=api_request):
        called = plugin.start()
        assert called == [
            {
                "assignment_id": "assign_1_1",
                "course_id": "no_course",
                "student_id": 1,
                "status": "released",
                "notebooks": [
                    {
                        "notebook_id": "assignment-0.6",
                        "has_exchange_feedback": False,
                        "feedback_updated": False,
                        "feedback_timestamp": None,
                    }
                ],
                "path": "",
                "timestamp": "2020-01-01 00:00:00.0 00:00",
            }
        ]
Esempio n. 3
0
def test_list_delete(plugin_config, tmpdir):
    plugin_config.CourseDirectory.course_id = "no_course"
    plugin_config.CourseDirectory.assignment_id = "assign_1_1"
    plugin_config.ExchangeList.remove = True

    plugin = ExchangeList(coursedir=CourseDirectory(config=plugin_config),
                          config=plugin_config)

    def api_request(*args, **kwargs):
        assert args[0] == (
            "assignment?course_id=no_course&assignment_id=assign_1_1")
        assert "method" not in kwargs or kwargs.get(
            "method").lower() == "delete"
        return type("Request", (object, ), {"status_code": 200})

    with patch.object(Exchange, "api_request", side_effect=api_request):
        plugin.start()
Esempio n. 4
0
def test_list_feedback_available_with_path_includes_course(
        plugin_config, tmpdir):
    try:
        course_code = "no_course"
        assignment_id = "assign_1_1"
        plugin_config.CourseDirectory.course_id = course_code
        plugin_config.CourseDirectory.assignment_id = assignment_id

        plugin_config.ExchangeList.inbound = True
        plugin_config.Exchange.path_includes_course = True

        my_feedback_dir = f"{course_code}/{assignment_id}/feedback/2020-01-01 00:02:00.2 00:00"
        os.makedirs(my_feedback_dir, exist_ok=True)
        copyfile(
            feedback1_filename,
            os.path.join(
                my_feedback_dir,
                basename(feedback1_filename),
            ),
        )

        plugin = ExchangeList(coursedir=CourseDirectory(config=plugin_config),
                              config=plugin_config)

        def api_request(*args, **kwargs):
            assert args[0] == ("assignments?course_id=no_course")
            assert "method" not in kwargs or kwargs.get(
                "method").lower() == "get"
            return type(
                "Request",
                (object, ),
                {
                    "status_code":
                    200,
                    "json": (lambda: {
                        "success":
                        True,
                        "value": [
                            {
                                "assignment_id":
                                assignment_id,
                                "student_id":
                                1,
                                "course_id":
                                course_code,
                                "status":
                                "submitted",
                                "path":
                                "",
                                "notebooks": [{
                                    "notebook_id":
                                    root_notebook_name,
                                    "has_exchange_feedback":
                                    True,
                                    "feedback_updated":
                                    False,
                                    "feedback_timestamp":
                                    "2020-01-01 00:02:00.2 00:00",
                                }],
                                "timestamp":
                                "2020-01-01 00:00:00.2 00:00",
                            },
                        ],
                    }),
                },
            )

        with patch.object(Exchange, "api_request", side_effect=api_request):
            called = plugin.start()
            assert called == [{
                "assignment_id":
                assignment_id,
                "course_id":
                course_code,
                "student_id":
                1,
                "status":
                "submitted",
                "submissions": [{
                    "assignment_id":
                    assignment_id,
                    "course_id":
                    course_code,
                    "path":
                    "",
                    "status":
                    "submitted",
                    "student_id":
                    1,
                    "notebooks": [{
                        "feedback_timestamp": "2020-01-01 00:02:00.2 00:00",
                        "has_exchange_feedback": True,
                        "has_local_feedback": True,
                        "local_feedback_path":
                        f"{course_code}/{assignment_id}/feedback/2020-01-01%2000%3A02%3A00.2%2000%3A00/{root_notebook_name}.html",  # noqa: E501
                        "feedback_updated": False,
                        "notebook_id": root_notebook_name,
                    }],
                    "timestamp":
                    "2020-01-01 00:00:00.2 00:00",
                    "feedback_updated":
                    False,
                    "has_exchange_feedback":
                    True,
                    "has_local_feedback":
                    True,
                    "local_feedback_path":
                    f"{course_code}/{assignment_id}/feedback/2020-01-01%2000%3A02%3A00.2%2000%3A00",  # noqa: E501
                }],
            }]
    finally:
        shutil.rmtree(course_code)
Esempio n. 5
0
def test_list_fetch_without_release_ignored(plugin_config, tmpdir):
    try:
        plugin_config.CourseDirectory.course_id = "no_course"

        os.makedirs("assign_1_3", exist_ok=True)
        copyfile(notebook1_filename, os.path.join("assign_1_3", basename(notebook1_filename)))

        plugin = ExchangeList(coursedir=CourseDirectory(config=plugin_config), config=plugin_config)

        def api_request(*args, **kwargs):
            assert args[0] == ("assignments?course_id=no_course")
            assert "method" not in kwargs or kwargs.get("method").lower() == "get"
            return type(
                "Request",
                (object,),
                {
                    "status_code": 200,
                    "json": (
                        lambda: {
                            "success": True,
                            "value": [
                                {
                                    "assignment_id": "assign_1_1",
                                    "student_id": 1,
                                    "course_id": "no_course",
                                    "status": "released",
                                    "path": "",
                                    "notebooks": [
                                        {
                                            "notebook_id": "assignment-0.6",
                                            "has_exchange_feedback": False,
                                            "feedback_updated": False,
                                            "feedback_timestamp": None,
                                        }
                                    ],
                                    "timestamp": "2020-01-01 00:00:00.0 00:00",
                                },
                                {
                                    "assignment_id": "assign_1_3",
                                    "student_id": 1,
                                    "course_id": "no_course",
                                    "status": "fetched",
                                    "path": "",
                                    "notebooks": [
                                        {
                                            "notebook_id": "assignment-0.6",
                                            "has_exchange_feedback": False,
                                            "feedback_updated": False,
                                            "feedback_timestamp": None,
                                        }
                                    ],
                                    "timestamp": "2020-01-01 00:00:00.0 00:00",
                                },
                            ],
                        }
                    ),
                },
            )

        with patch.object(Exchange, "api_request", side_effect=api_request):
            called = plugin.start()
            assert called == [
                {
                    "assignment_id": "assign_1_1",
                    "course_id": "no_course",
                    "student_id": 1,
                    "status": "released",
                    "notebooks": [
                        {
                            "notebook_id": "assignment-0.6",
                            "has_exchange_feedback": False,
                            "feedback_updated": False,
                            "feedback_timestamp": None,
                        }
                    ],
                    "path": "",
                    "timestamp": "2020-01-01 00:00:00.0 00:00",
                },
            ]
    finally:
        shutil.rmtree("assign_1_3")