def test_nenhum_orgao_encontrado_no_mgp(self):
        self.mock_oracle_access.side_effect = [
            self.oracle_return_dados_usuario,
            (),
        ]

        with pytest.raises(exceptions.UserHasNoOfficeInformation):
            services.build_login_response(self.permissoes)
    def test_build_login_response(self):
        response = services.build_login_response(self.permissoes)

        for key in response.keys():
            with self.subTest():
                self.assertEqual(response[key], self.expected_response[key],
                                 key)
    def test_jwt_payload(self):
        self.jwt_patcher.stop()
        response = services.build_login_response(self.permissoes)
        payload = jwt.decode(response["token"],
                             settings.JWT_SECRET,
                             algorithm="HS256")

        self.assertEqual(payload, self.expected_payload)
        self.jwt_patcher.start()
Beispiel #4
0
    def post(self, request, *args, **kwargs):
        username = request.POST.get("username", "")
        password = bytes(request.POST.get("password", ""), "utf-8")

        sca_resp = self.auth_sca(username, password)
        cargo = dao.UsuarioPromotor.get(username=username)
        permissoes = services.permissoes_router(
            sca_resp.info.json(),
            cargo,
        )

        return Response(data=services.build_login_response(permissoes))
    def test_NOT_first_login_today(self):
        with freeze_time("2020-1-1"):  # date of user creation in DB
            user_db = baker.make(Usuario, username=self.username)

        with freeze_time("2020-1-1"):  # date of login
            response = services.build_login_response(self.permissoes)

        self.expected_response["first_login"] = False
        self.expected_response["first_login_today"] = False

        for key in response.keys():
            with self.subTest():
                self.assertEqual(response[key], self.expected_response[key],
                                 key)

        user_db.refresh_from_db(using=self.TEST_DATABASE_NAME)
        self.assertEqual(user_db.last_login, date(2020, 1, 1))