Exemple #1
0
def test_crud_update_email(client):
    user = client.login('*****@*****.**')

    response = client.post_json(
        '/api/crud', {
            'token': client.__token__,
            'actions': {
                'action': 'update',
                'model': 'user',
                'uid': user.get_uid(),
                'data': {
                    'name': 'new_name',
                    'email': '*****@*****.**'
                }
            }
        })
    assert response.status_code == 200
    assert response.json['success']

    with DbSessionContext(config.get('mongo_database_name')) as session:
        user_query = session.query(User) \
            .filter(User.email == '*****@*****.**')
        assert user_query.count()

        user = user_query.one()

        assert user.name == 'new_name'
        assert not user.email_confirmed

        last_notification = session.query(Notification)\
            .filter(Notification.user_uid == user.get_uid())\
            .descending(Notification.created_ts)\
            .first()

        assert last_notification.message == \
            'notification.PleaseConfirmYourEmail'
Exemple #2
0
from server.settings import config  # noqa
from server.model.notification import Notification  # noqa
from server.utils import DbSessionContext  # noqa

config.configure()
loop = asyncio.get_event_loop()
asyncio.set_event_loop(loop)

if config.get('env', 'production') != 'development':
    print('The "env" variable is not set to development')
    sys.exit(1)

DB_NAME = config.get('mongo_database_name')
drop_database(DB_NAME, config.get('redis_database'))

with DbSessionContext(DB_NAME) as session:
    # INSERT DUMMY DATA
    users = [
        {
            'name': 'test',
            'email': '*****@*****.**',
            'email_validation_token': '123456',
            'password': '******'
        }, {
            'name': 'to.disable',
            'email': '*****@*****.**',
            'email_validation_token': '1337',
            'password': '******'
        }, {
            'name': 'admin',
            'email': '*****@*****.**',
Exemple #3
0
def client():
    loop = asyncio.get_event_loop()
    asyncio.set_event_loop(loop)

    config = {
        "env": "test",
        "mongo_database_name": "webbase_test",
        "redis_database": 13,
        "mongo_host": "127.0.0.1",
        "server_port": 1337,
        "server_host": "localhost"
    }

    drop_database(config.get('mongo_database_name'),
                  config.get('redis_database'))

    _, _, app = loop.run_until_complete(init(loop, config))

    with DbSessionContext(config.get('mongo_database_name')) as session:

        # INSERT DUMMY DATA
        users = [{
            'name': 'test',
            'email': '*****@*****.**',
            'email_validation_token': '123456',
            'password': '******'
        }, {
            'name': 'to.disable',
            'email': '*****@*****.**',
            'email_validation_token': '1337',
            'password': '******'
        }, {
            'name': 'admin',
            'email': '*****@*****.**',
            'password': '******',
            'role': 'admin'
        }, {
            'name': 'disabled',
            'email': '*****@*****.**',
            'password': '******',
            'enable': False
        }]

        notifications = [{
            'user_uid': None,
            'message': 'Test 1'
        }, {
            'user_uid': None,
            'message': 'Test 2'
        }, {
            'user_uid': None,
            'message': 'Test 3'
        }, {
            'user_uid': None,
            'message': 'Test 4',
            'seen': True
        }]

        for user_data in users:
            user = User()
            context = {
                'db_session': session,
                'method': 'create',
                'data': user_data
            }

            loop.run_until_complete(user.validate_and_save(context))

            context = {
                'db_session': session,
                'method': 'create',
                'data': {
                    'user_uid': user.get_uid()
                }
            }
            resetpasswordtoken = Resetpasswordtoken()
            loop.run_until_complete(
                resetpasswordtoken.validate_and_save(context))
            for notification_data in notifications:
                notification = Notification()
                notification_data['user_uid'] = user.get_uid()

                context = {
                    'db_session': session,
                    'method': 'create',
                    'data': notification_data
                }

                loop.run_until_complete(
                    notification.validate_and_save(context))

    def login(self, email, password='******'):
        self.post_json('/api/login', {
            'email': email,
            'password': password,
            'token': self.__token__
        })
        with DbSessionContext(
                self.config.get('mongo_database_name')) as session:
            user = session.query(User)\
                .filter(User.email == email).one()

        return user

    client = TestApp(app)
    client.config = config
    client.login = types.MethodType(login, client)

    # NOTE Always do an /api/get_session to init the session correctly
    data = {'user_timezone': 'Australia/Sydney'}
    response = client.post_json('/api/get_session', data)
    client.__token__ = response.json['token']

    return client