Beispiel #1
0
    def test_check_base_url(self):
        self.settings["base-url"] = "https://example.com"
        CheckSettings.check_base_url()

        self.settings["base-url"] = 65
        with pytest.raises(TypeError):
            CheckSettings.check_base_url()
Beispiel #2
0
    def test_check(self):
        checks = [
            "base_url",
            "root_folder",
            "logs_folder",
            "logging_level",
            "timeout",
            "retries",
            "login_retries",
            "logout_retries",
            "max_logs",
            "exclude_subjects_ids",
            "http_status_port",
            "http_status_tickrate",
            "forum_subfolders",
            "section_indexing_ids",
            "secure_section_filename",
            "email",
        ]

        mocked_checks = []
        for check in checks:
            route = "vcm.settings.CheckSettings.check_" + check
            mocked_check = mock.patch(route).start()
            mocked_checks.append(mocked_check)

        CheckSettings.check()

        for mocked_check in mocked_checks:
            mocked_check.assert_called_once_with()
            mocked_check.reset_mock()
Beispiel #3
0
    def test_check_logs_folder(self, mkdir_m):
        rmtree(self.settings.logs_folder, ignore_errors=True)
        CheckSettings.check_logs_folder()
        mkdir_m.assert_called_once_with(parents=True, exist_ok=True)

        mocked_logs_folder = "vcm.settings.Settings.logs_folder"
        with mock.patch(mocked_logs_folder,
                        new_callable=mock.PropertyMock) as lf_m:
            lf_m.return_value = "invalid"
            with pytest.raises(TypeError, match="Wrapper"):
                CheckSettings.check_logs_folder()
            lf_m.assert_called_once_with()

        assert mkdir_m.call_count == 1
Beispiel #4
0
    def test_check_email(self):
        self.settings["email"] = "*****@*****.**"
        CheckSettings.check_email()

        self.settings["email"] = "insert-email"
        with pytest.raises(ValueError):
            CheckSettings.check_email()

        self.settings["email"] = 5
        with pytest.raises(TypeError):
            CheckSettings.check_email()

        self.settings["email"] = "invalid-email"
        with pytest.raises(ValueError):
            CheckSettings.check_email()
Beispiel #5
0
    def test_check_http_status_tickrate(self):
        self.settings["http_status_tickrate"] = 20
        CheckSettings.check_http_status_tickrate()

        self.settings["http_status_tickrate"] = "30"
        CheckSettings.check_http_status_tickrate()
        assert self.settings["http_status_tickrate"] == 30

        self.settings["http_status_tickrate"] = "hello"
        with pytest.raises(TypeError):
            CheckSettings.check_http_status_tickrate()

        self.settings["http_status_tickrate"] = -5
        with pytest.raises(ValueError):
            CheckSettings.check_http_status_tickrate()
Beispiel #6
0
    def test_check_max_logs(self):
        self.settings["max_logs"] = 20
        CheckSettings.check_max_logs()

        self.settings["max_logs"] = "30"
        CheckSettings.check_max_logs()
        assert self.settings["max_logs"] == 30

        self.settings["max_logs"] = "hello"
        with pytest.raises(TypeError):
            CheckSettings.check_max_logs()

        self.settings["max_logs"] = -5
        with pytest.raises(ValueError):
            CheckSettings.check_max_logs()
Beispiel #7
0
    def test_check_retries(self):
        self.settings["retries"] = 5
        CheckSettings.check_retries()

        self.settings["retries"] = "30"
        CheckSettings.check_retries()
        assert self.settings["retries"] == 30

        self.settings["retries"] = "hello"
        with pytest.raises(TypeError):
            CheckSettings.check_retries()

        self.settings["retries"] = -5
        with pytest.raises(ValueError):
            CheckSettings.check_retries()
Beispiel #8
0
    def test_check_timeout(self):
        self.settings["timeout"] = 20
        CheckSettings.check_timeout()

        self.settings["timeout"] = "30"
        CheckSettings.check_timeout()
        assert self.settings["timeout"] == 30

        self.settings["timeout"] = "hello"
        with pytest.raises(TypeError):
            CheckSettings.check_timeout()

        self.settings["timeout"] = -5
        with pytest.raises(ValueError):
            CheckSettings.check_timeout()
Beispiel #9
0
    def test_check_logging_level(self):
        self.settings["logging-level"] = "DEBUG"
        CheckSettings.check_logging_level()

        self.settings["logging-level"] = "critical"
        CheckSettings.check_logging_level()
        assert self.settings.logging_level == "CRITICAL"

        self.settings["logging-level"] = 54
        with pytest.raises(TypeError):
            CheckSettings.check_logging_level()

        self.settings["logging-level"] = "invalid"
        with pytest.raises(ValueError):
            CheckSettings.check_logging_level()
Beispiel #10
0
    def test_check_secure_section_filename(self):
        self.settings["secure_section_filename"] = False
        CheckSettings.check_secure_section_filename()

        self.settings["secure_section_filename"] = "true"
        CheckSettings.check_secure_section_filename()
        assert self.settings["secure_section_filename"] is True

        self.settings["secure_section_filename"] = "hello"
        with pytest.raises(TypeError):
            CheckSettings.check_secure_section_filename()
Beispiel #11
0
    def test_check_forum_subfolders(self):
        self.settings["forum_subfolders"] = False
        CheckSettings.check_forum_subfolders()

        self.settings["forum_subfolders"] = "true"
        CheckSettings.check_forum_subfolders()
        assert self.settings["forum_subfolders"] is True

        self.settings["forum_subfolders"] = "hello"
        with pytest.raises(TypeError):
            CheckSettings.check_forum_subfolders()
Beispiel #12
0
    def test_check_root_folder(self, mkdir_m):
        rmtree(self.settings.root_folder, ignore_errors=True)

        self.settings["root-folder"] = "/path/to/folder"
        CheckSettings.check_root_folder()
        mkdir_m.assert_called_once_with(parents=True, exist_ok=True)

        self.settings["root-folder"] = 65
        with pytest.raises(TypeError):
            CheckSettings.check_root_folder()

        self.settings["root-folder"] = "insert-root-folder"
        with pytest.raises(ValueError):
            CheckSettings.check_root_folder()

        mocked_root_folder = "vcm.settings.Settings.root_folder"
        with mock.patch(mocked_root_folder,
                        new_callable=mock.PropertyMock) as rf_m:
            rf_m.return_value = "invalid"
            with pytest.raises(TypeError, match="Wrapper"):
                CheckSettings.check_root_folder()
            rf_m.assert_called_once_with()
        mkdir_m.assert_called_once_with(parents=True, exist_ok=True)
Beispiel #13
0
    def test_check_section_indexing_ids(self):
        self.settings["section-indexing-ids"] = []
        CheckSettings.check_section_indexing_ids()

        self.settings["section-indexing-ids"] = [500]
        CheckSettings.check_section_indexing_ids()

        self.settings["section-indexing-ids"] = 5 + 2j
        with pytest.raises(TypeError):
            CheckSettings.check_section_indexing_ids()

        self.settings["section-indexing-ids"] = [500, "sdaf"]
        with pytest.raises(TypeError):
            CheckSettings.check_section_indexing_ids()

        self.settings["section-indexing-ids"] = ["500", "sdaf"]
        with pytest.raises(TypeError):
            CheckSettings.check_section_indexing_ids()

        self.settings["section-indexing-ids"] = [5, -7]
        with pytest.raises(ValueError):
            CheckSettings.check_section_indexing_ids()

        self.settings["section-indexing-ids"] = [-5, -7]
        with pytest.raises(ValueError):
            CheckSettings.check_section_indexing_ids()
Beispiel #14
0
    def test_check_exclude_subjects_ids(self):
        self.settings["exclude-subjects-ids"] = []
        CheckSettings.check_exclude_subjects_ids()

        self.settings["exclude-subjects-ids"] = [500]
        CheckSettings.check_exclude_subjects_ids()

        self.settings["exclude-subjects-ids"] = 5 + 2j
        with pytest.raises(TypeError):
            CheckSettings.check_exclude_subjects_ids()

        self.settings["exclude-subjects-ids"] = [500, "sdaf"]
        with pytest.raises(TypeError):
            CheckSettings.check_exclude_subjects_ids()

        self.settings["exclude-subjects-ids"] = ["500", "sdaf"]
        with pytest.raises(TypeError):
            CheckSettings.check_exclude_subjects_ids()

        self.settings["exclude-subjects-ids"] = [5, -7]
        with pytest.raises(ValueError):
            CheckSettings.check_exclude_subjects_ids()

        self.settings["exclude-subjects-ids"] = [-5, -7]
        with pytest.raises(ValueError):
            CheckSettings.check_exclude_subjects_ids()
Beispiel #15
0
def setup_vcm():
    from vcm.settings import CheckSettings

    configure_logging()
    CheckSettings.check()