示例#1
0
    def setUp(self):
        from base import orm
        config.load_from_yaml(
            os.path.dirname(os.path.realpath(__file__)) +
            f'/../config.singleservice.yaml')

        config.conf['db']['database'] = f"test_{config.conf['db']['database']}"

        importlib.import_module('orm.models')

        registry.test = True

        orm = orm.init_orm(config.conf['db'])

        orm.clear_database()
        orm.create_db_schema()

        importlib.import_module('users.api.users')
        importlib.import_module('contacts.api.contacts')

        config.init_logging()
        self.my_app = app.make_app(debug=True)

        from base import store
        with open(
                os.path.dirname(os.path.realpath(__file__)) +
                '/../users/keys/jwt.public_key') as pubkey:
            store.set('users_service_public_key', pubkey.read())

        config.load_private_key(
            os.path.dirname(os.path.realpath(__file__)) +
            '/../users/keys/jwt.private_key')

        super().setUp()
        registry.test_port = self.get_http_port()
示例#2
0
    def setUp(self):
        config.load_from_yaml(current_file_folder + f'/../config/config.yaml')
        config.conf['db']['database'] = f"test_{config.conf['db']['database']}"
        self.get_new_ioloop().run_sync(reset_test_db)
        registry.test = True
        importlib.import_module('api.app')
        config.init_logging()
        self.my_app = app.make_app(debug=True)

        super().setUp()
        registry.test_port = self.get_http_port()
async def seed_users(args):

    config.load_from_yaml(
        f'{_root}/config/config.{os.getenv("ENVIRONMENT", "local")}.yaml')
    await Tortoise.init(config=config.tortoise_config())

    _exists = await models.users.AuthUser.all().count()
    if _exists:
        # do not add seed
        return

    _file = f'{_current_path}/{args.file}'
    with open(_file) as f:
        csv_reader = csv.reader(f)
        for csv_user in csv_reader:
            print(csv_user)

            auth_user = models.AuthUser()
            auth_user.username = csv_user[0]
            auth_user.password = csv_user[1]
            auth_user.role_flags = int(csv_user[2])
            # on new users platform user's roles are changed ADMIN -> SUPERUSER
            if auth_user.role_flags == user_roles.ADMIN and auth_user.username != 'admin':
                auth_user.role_flags = user_roles.SUPERUSER
            if auth_user.username == '*****@*****.**':
                auth_user.role_flags = user_roles.ADMIN

            auth_user.scopes = {'OPENWASTE': 3, 'OPENLIGHT': 3}
            await auth_user.save()

            user = models.User()
            user.auth_user = auth_user
            user.first_name = csv_user[3]
            user.last_name = csv_user[4]
            user.email = csv_user[5]
            user.alarm_type = int(csv_user[6])
            user.notification_type = int(csv_user[7])
            user.phone = PHONES[
                auth_user.
                username]['number'] if auth_user.username in PHONES else None
            await user.save()
示例#4
0
    def setUp(self):
        from base import registry, orm, app, config

        config.load_from_yaml(current_file_folder + f'/../config/config.{os.getenv("ENVIRONMENT", "local")}.yaml')
        config.conf['db']['database'] = f"test_{config.conf['db']['database']}"

        importlib.import_module('orm.models')
        registry.test = True

        orm = orm.init_orm(config.conf['db'])

        orm.clear_database()
        orm.create_db_schema()

        importlib.import_module('api.contacts')

        config.init_logging()
        self.my_app = app.make_app(debug=True)

        super().setUp()
        registry.test_port = self.get_http_port()
示例#5
0
    def setUp(self):
        self.flush_db_at_the_end = True  # flush db on the tearDown. Set this to False in test not to flush db

        import os
        config.load_from_yaml(
            current_file_folder +
            f'/../config/config.{os.getenv("ENVIRONMENT", "local")}.yaml')
        config.conf['test'] = True

        from base import store
        # store engine has to be patched not to use redis and not to change the config option
        with patch('base.store.Store.engine', store.DictStore()):

            asyncio_current_loop = self.get_new_ioloop()
            asyncio_current_loop.run_sync(app.init_orm)

            _models = config.conf['tortoise']['apps'][
                base.config.conf['name']]['models']
            _db_url = base.config.get_db_url(test=True)

            initializer(_models,
                        app_label=base.config.conf['name'],
                        db_url=_db_url,
                        loop=asyncio_current_loop.asyncio_loop)

            registry.test = True

            self.prefix = config.conf['prefix']

            config.init_logging()
            config.conf['verbose'] = False
            self.my_app = app.make_app(debug=True)

            with open(f'{root_folder}/keys/users.key.pem') as pubkey:
                store.set('users_service_public_key', pubkey.read())

            config.load_private_key(f'{root_folder}/keys/users.key')

            super().setUp()
            registry.test_port = self.get_http_port()
示例#6
0
async def main():

    f = Faker()
    config.load_from_yaml(
        f'{_root}/config/config.{os.getenv("ENVIRONMENT", "local")}.yaml')
    await Tortoise.init(config=config.tortoise_config())

    _exists = await models.users.AuthUser.all().count()
    if _exists:
        # do not add seed
        return

    _roles = [
        (user_roles.USER, 10),
        (user_roles.ADMIN, 5),
        (user_roles.DEVELOPER, 2),
        (user_roles.SUPERUSER, 2),
    ]
    for role in _roles:
        for _ in range(role[1]):
            auth_user = models.AuthUser()
            auth_user.username = f.user_name()
            auth_user.password = format_password(auth_user.username, '123')
            auth_user.role_flags = role[0]
            auth_user.scopes = {'OPENWASTE': 3, 'OPENLIGHT': 3}
            await auth_user.save()

            user = models.User()
            user.auth_user = auth_user
            user.first_name = f.first_name()
            user.last_name = f.last_name()
            user.email = f.email()
            user.alarm_type = 1
            user.notification_type = 1
            user.phone = f.phone_number()
            await user.save()