Beispiel #1
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from c3sadoportal.models import (
         Base,
         MyModel,
     )
     DBSession.configure(bind=engine)
Beispiel #2
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from c3sadoportal.models import (
         Base,
         MyModel,
     )
     DBSession.configure(bind=engine)
Beispiel #3
0
    def setUp(self):
        self.config = testing.setUp()
        from sqlalchemy import create_engine

        engine = create_engine("sqlite://")
        from c3sadoportal.models import Base, MyModel

        DBSession.configure(bind=engine)
        Base.metadata.create_all(engine)
        with transaction.manager:
            model = MyModel(name="one", value=55)
            DBSession.add(model)
Beispiel #4
0
 def setUp(self):
     self.config = testing.setUp()
     from sqlalchemy import create_engine
     engine = create_engine('sqlite://')
     from c3sadoportal.models import (
         Base,
         MyModel,
     )
     DBSession.configure(bind=engine)
     Base.metadata.create_all(engine)
     with transaction.manager:
         model = MyModel(name='one', value=55)
         DBSession.add(model)
Beispiel #5
0
 def setUp(self):
     self.config = testing.setUp()
     self.config.include('pyramid_mailer.testing')
     try:
         DBSession.remove()
         #print("removing old DBSession ==============================")
     except:
         #print("no DBSession to remove ==============================")
         pass
     #engine = create_engine('sqlite:///test_models.db')
     engine = create_engine('sqlite:///:memory:')
     self.session = DBSession
     DBSession.configure(bind=engine)  # XXX does influence self.session!?!
     Base.metadata.create_all(engine)
Beispiel #6
0
def my_view(request):
    try:
        one = DBSession.query(MyModel).filter(MyModel.name == 'one').first()
    except DBAPIError:
        return Response(
            conn_err_msg, content_type='text/plain', status_int=500)
    return {'one': one, 'project': 'c3s.ado.portal'}
Beispiel #7
0
    def setUp(self):
        self.config = testing.setUp()
        self.config.include('pyramid_mailer.testing')
        my_settings = {
            #'sqlalchemy.url': 'sqlite:///test_webtest_accountants.db',
            'sqlalchemy.url': 'sqlite:///:memory:',
            'available_languages': 'de en',
        }
        engine = engine_from_config(my_settings)
        DBSession.configure(bind=engine)
        Base.metadata.create_all(engine)

        self._insert_groups()
        self._insert_members()

        from c3sadoportal import main
        app = main({}, **my_settings)
        from webtest import TestApp
        self.testapp = TestApp(app)
Beispiel #8
0
    def setUp(self):
        self.config = testing.setUp()
        self.config.include('pyramid_mailer.testing')
        my_settings = {
            #'sqlalchemy.url': 'sqlite:///test_webtest_accountants.db',
            'sqlalchemy.url': 'sqlite:///:memory:',
            'available_languages': 'de en',
        }
        engine = engine_from_config(my_settings)
        DBSession.configure(bind=engine)
        Base.metadata.create_all(engine)

        self._insert_groups()
        self._insert_members()

        from c3sadoportal import main
        app = main({}, **my_settings)
        from webtest import TestApp
        self.testapp = TestApp(app)
Beispiel #9
0
 def _insert_members(self):
     with transaction.manager:
         member1 = People(  # german
             email=u'*****@*****.**',
             password=u'arandompassword',
         )
         member2 = People(  # german
             email=u'*****@*****.**',
             password=u'arandompassword2',
         )
         member3 = People(  # german
             email=u'*****@*****.**',
             password=u'arandompassword3',
         )
         DBSession.add(member1)
         DBSession.add(member2)
         DBSession.add(member3)
         DBSession.flush()
Beispiel #10
0
 def _insert_groups(self):
     with transaction.manager:
         login_group = Group(
             name=u'login',
         )
         DBSession.add(login_group)
         staff_group = Group(
             name=u'staff',
         )
         DBSession.add(staff_group)
         DBSession.flush()
Beispiel #11
0
 def _insert_groups(self):
     with transaction.manager:
         login_group = Group(
             name=u'login',
         )
         DBSession.add(login_group)
         staff_group = Group(
             name=u'staff',
         )
         DBSession.add(staff_group)
         DBSession.flush()
Beispiel #12
0
    def setUp(self):
        self.config = testing.setUp()
        self.config.include('pyramid_mailer.testing')
        try:
            DBSession.remove()
        except:
            pass
        #engine = create_engine('sqlite:///test_model_staff.db')
        engine = create_engine('sqlite://')
        self.session = DBSession
        self.session.configure(bind=engine)
        Base.metadata.create_all(engine)

        with transaction.manager:
            group1 = Group(name=u'staff')
            group2 = Group(name=u'staff2')
            DBSession.add(group1, group2)
            DBSession.flush()
Beispiel #13
0
 def tearDown(self):
     DBSession.remove()
     testing.tearDown()
Beispiel #14
0
 def tearDown(self):
     DBSession.remove()
     testing.tearDown()
Beispiel #15
0
    def setUp(self):
        self.config = testing.setUp()
        from sqlalchemy import create_engine

        engine = create_engine("sqlite://")
        DBSession.configure(bind=engine)
Beispiel #16
0
def register(request):
    """
    This view lets people register.
    if a person is already logged in, she is forwarded to the logged_in view
    """
    logged_in = authenticated_userid(request)

    if logged_in is not None:  # if user is already authenticated
        return HTTPFound(  # redirect her to the dashboard
            request.route_url('logout'))

    # roll your own captcha
    #_c1 = random.range(10)
    #_c2 = random.range(10)

    class AccountRegistration(colander.MappingSchema):
        """
        colander schema for registration form
        """
        login = colander.SchemaNode(
            colander.String(),
            title=_(u"login"),
            oid="login",
        )
        password = colander.SchemaNode(
            colander.String(),
            validator=colander.Length(min=5, max=100),
            widget=deform.widget.PasswordWidget(size=20),
            title=_(u"password"),
            oid="password",
        )
        email = colander.SchemaNode(
            colander.String(),
            validator=colander.Email(),
            title=_(u"email"),
            oid="email",
        )
        #captcha = colander.SchemaNode(
        #    colander.String(),
        #    title=_(u"captcha: what is foo + bar?"),
        #    oid="captcha",
        #)

    schema = AccountRegistration()

    form = deform.Form(
        schema,
        buttons=[
            deform.Button('submit', _(u'Submit')),
        ],
        #use_ajax=True,
        #renderer=zpt_renderer
    )

    # if the form has been used and SUBMITTED, check contents
    if 'submit' in request.POST:
        #print("the form was submitted")
        controls = request.POST.items()
        try:
            appstruct = form.validate(controls)
        except ValidationFailure, e:
            print(e)

            request.session.flash(
                _(u"Please note: There were errors, "
                  "please check the form below."),
                'message_above_form',
                allow_duplicate=False)
            return{'form': e.render()}

        # get user and check pw...
        _login = appstruct['login']
        _password = appstruct['password']
        _email = appstruct['email']

        try:
            # check if data is valid
            # * no duplicate accounts...
            #print '*'*60
            login_unique = False if People.get_by_login(_login) else True
            #print "login_unique: {}".format(login_unique)
            email_unique = False if People.get_by_email(_email) else True
            #print "email_unique: {}".format(email_unique)
            #print '*'*60
        except:  # pragma: no cover
            pass
        if login_unique and email_unique:
            # persist user
            _new = People(
                login=_login,
                password=_password,
                email=_email
            )
            _new.groups = [Group.get_login_group()]
            DBSession.add(_new)
            headers = remember(request, _login)

            return HTTPFound(  # redirect to accountants dashboard
                location=request.route_url(  # after successful login
                    'logged_in',
                    request=request),
                headers=headers
            )
        else:
            log.info(
                "login or email already known: {}, {}".format(_login, _email))
            request.session.flash(
                'login or email already known',
                'message_sign_up',
            )