Ejemplo n.º 1
0
 def test_auth_without_credentials(self):
     from core.auth.custom_auth import auth as wd_auth
     self.push_to_ctx()
     with patch(
         "flask.current_app.database", new=Mock(
             get_user=Mock(return_value=Mock(id=1, is_active=True)))
     ):
         wd_auth.login_required(decorate_this)()
Ejemplo n.º 2
0
 def test_auth_token_only(self):
     from core.auth.custom_auth import auth as wd_auth
     from core.auth.custom_auth import anonymous
     self.set_auth_credentials(token=anonymous.password)
     self.push_to_ctx()
     with patch(
         "flask.current_app.database", new=Mock(
             get_user=Mock(return_value=Mock(id=1, is_active=True)))
     ):
         wd_auth.login_required(decorate_this)()
Ejemplo n.º 3
0
    def test_auth_not_existing_user(self):
        from core.auth.custom_auth import auth as wd_auth
        self.set_auth_credentials(username="******")
        # Token doesn't matter
        self.push_to_ctx()

        with patch("flask.current_app.database",
                   new=Mock(get_user=Mock(return_value=None))):
            resp = wd_auth.login_required(decorate_this)()

        success_data = {
            "status": 1,
            "value": "User not found in service",
            "message": "Please register in service"
        }
        self.assertEqual(resp.status_code, 401)
        self.assertDictEqual(json.loads(resp.data), success_data)
Ejemplo n.º 4
0
    def test_auth_wrong_token(self):
        from core.auth.custom_auth import auth as wd_auth
        from core.auth.custom_auth import anonymous
        existing_user = anonymous.username
        wrong_token = "not" + str(anonymous.password)
        self.set_auth_credentials(username=existing_user, token=wrong_token)
        self.push_to_ctx()

        with patch("flask.current_app.database",
                   new=Mock(get_user=Mock(
                       return_value=Mock(id=1, is_active=True)))):
            resp = wd_auth.login_required(decorate_this)()

        success_data = {
            "status": 1,
            "value": "Authentification was failed",
            "message": "Please try again"
        }
        self.assertEqual(resp.status_code, 401)
        self.assertDictEqual(json.loads(resp.data), success_data)