Exemple #1
0
class GeneralPresenterTester(TestCase):
    # TODO: more unit tests, e.g. with right key etc.
    def setUp(self) -> None:
        self.presenter_handler = PresenterHandler(
            logging=MagicMock(),
            services=MagicMock(),
        )
        self.user_id = 0

    def test_with_bad_key(self) -> None:
        request = MagicMock()
        request.json = [
            PresenterBlob(presenter="non_existing_presenter", data={})
        ]
        with self.assertRaises(PresenterException) as context_manager:
            self.presenter_handler.handle_request(request)
        self.assertEqual(
            context_manager.exception.message,
            "Presenter non_existing_presenter does not exist.",
        )

    def test_with_differing_auth_methods(self) -> None:
        request = MagicMock()
        request.json = [
            PresenterBlob(presenter="get_users", data={}),
            PresenterBlob(presenter="check_mediafile_id", data={}),
        ]
        with self.assertRaises(PresenterException) as context_manager:
            self.presenter_handler.handle_request(request)
        self.assertEqual(
            context_manager.exception.message,
            "You cannot call presenters with different login mechanisms",
        )
Exemple #2
0
class PresenterBaseUnitTester(TestCase):
    def setUp(self) -> None:
        self.presenter_handler = PresenterHandler(
            logging=MagicMock(),
            services=MagicMock(),
        )
        self.user_id = 0

    def test_with_bad_key(self) -> None:
        payload = [PresenterBlob(presenter="non_existing_presenter", data={})]
        with self.assertRaises(PresenterException) as context_manager:
            self.presenter_handler.handle_request(
                payload=payload,
                user_id=self.user_id,
            )
        self.assertEqual(
            context_manager.exception.message,
            f"Presenter non_existing_presenter does not exist.",
        )

    def test_initial_data(self) -> None:
        payload = [PresenterBlob(presenter="initial-data", data={})]
        response = self.presenter_handler.handle_request(
            payload=payload,
            user_id=self.user_id,
        )
        expected = [{
            "privacy_policy": "The PP",
            "legal_notice": "The LN",
            "theme": "openslides-default",
            "logo_web_header_path": None,
            "login_info_text": None,
            "saml_settings": None,
        }]
        self.assertEqual(response, expected)

    def test_whoami(self) -> None:
        payload = [PresenterBlob(presenter="whoami", data={})]
        response = self.presenter_handler.handle_request(
            payload=payload,
            user_id=self.user_id,
        )
        expected = [{
            "auth_type": "default",
            "permissions": [],
            "user_id": 1,
            "guest_enabled": True,
            "groups_id": [2],
            "short_name": "username",
        }]
        self.assertEqual(response, expected)
Exemple #3
0
class GeneralPresenterTester(TestCase):
    # TODO: more unit tests, e.g. with right key etc.
    def setUp(self) -> None:
        self.presenter_handler = PresenterHandler(
            logging=MagicMock(),
            services=MagicMock(),
        )
        self.user_id = 0

    def test_with_bad_key(self) -> None:
        payload = [PresenterBlob(presenter="non_existing_presenter", data={})]
        with self.assertRaises(PresenterException) as context_manager:
            self.presenter_handler.handle_request(
                payload=payload,
                user_id=self.user_id,
            )
        self.assertEqual(
            context_manager.exception.message,
            "Presenter non_existing_presenter does not exist.",
        )
Exemple #4
0
 def setUp(self) -> None:
     self.presenter_handler = PresenterHandler(
         logging=MagicMock(),
         services=MagicMock(),
     )
     self.user_id = 0