示例#1
0
    def test_inner_login_server_error(self, cali_m, glt_m, mlr_m, fsauu_m, caplog):
        caplog.set_level(10)
        cali_m.return_value = False
        glt_m.return_value = "<token>"
        response = mock.MagicMock(ok=False, status_code=501, reason="<reason>")
        mlr_m.return_value = response

        conn = Connection()
        with pytest.raises(LoginError, match=r"Server returned 501 \(<reason>\)"):
            conn.inner_login()

        cali_m.assert_called_once_with()
        glt_m.assert_called_once_with()
        mlr_m.assert_called_once_with("<token>")
        mlr_m.cache_clear.assert_not_called()
        fsauu_m.assert_not_called()
        assert caplog.record_tuples == [
            (self.logger_name, 20, "Logging in with user '<username>'")
        ]
示例#2
0
    def test_inner_login_error(self, cali_m, glt_m, mlr_m, caplog):
        caplog.set_level(10)
        cali_m.return_value = False
        glt_m.return_value = "<token>"
        # TODO: put real text
        response = mock.MagicMock(
            ok=True, status_code=200, reason="OK", text="Usted no se ha identificado"
        )
        mlr_m.return_value = response

        conn = Connection()
        with pytest.raises(LoginError, match="Unsuccessfull login"):
            conn.inner_login()

        cali_m.assert_called_once_with()
        glt_m.assert_called_once_with()
        mlr_m.assert_called_once_with("<token>")
        assert caplog.record_tuples == [
            (self.logger_name, 20, "Logging in with user '<username>'")
        ]
示例#3
0
    def test_inner_login_already_logged_in(self, cali_m, glt_m, mlr_m, caplog):
        caplog.set_level(10)
        cali_m.return_value = True

        conn = Connection()
        assert conn.inner_login() is None

        cali_m.assert_called_once_with()
        glt_m.assert_not_called()
        mlr_m.assert_not_called()
        assert caplog.record_tuples == []
示例#4
0
    def test_inner_login_ok(self, cali_m, glt_m, mlr_m, caplog):
        caplog.set_level(10)
        cali_m.return_value = False
        glt_m.return_value = "<token>"
        # TODO: put real text
        response = mock.MagicMock(
            ok=True,
            status_code=200,
            reason="OK",
            text="Usted se ha identificado como FEDERICO GARCÍA LORCA",
        )
        mlr_m.return_value = response

        conn = Connection()
        conn.inner_login()

        cali_m.assert_called_once_with()
        glt_m.assert_called_once_with()
        mlr_m.assert_called_once_with("<token>")
        assert caplog.record_tuples == [
            (self.logger_name, 20, "Logging in with user '<username>'")
        ]