Esempio n. 1
0
def create_user_list_with_apps(request):

    with open(os.path.join(os.path.dirname(__file__), 'meta/redmine.yml'),
              'rb') as meta:
        metadata = meta.read()

    users = []
    users_data = {}
    users_apps = {}
    for i in range(0, 10):
        data = {
            'login': '******' % i,
            'first_name': 'FirstName%d' % i,
            'last_name': 'LastName%d' % i,
            'email': 'email%d@domain%d.com' % (i, i),
            'password': '******' % i,
        }

        u = User.objects(username=data['login']).first()
        if u:
            u.delete()

        u = User(username=data['login'], first_name=data['first_name'],
                 last_name=data['last_name'], email=data['email'],
                 is_superuser=False)
        u.set_password(data['password'])
        u.save()
        users.append(u)
        users_data[u.safe_id] = u

        app = Application(name='userApp', owner=u, metadata=metadata)
        app.save()
        users_apps[u] = app

    def cleanup():
        for us in users:
            us.delete()
        for ap in users_apps.values():
            ap.delete()
    request.addfinalizer(cleanup)

    request.instance.user_list = users
    request.instance.user_list_data = users_data
    request.instance.user_list_apps = users_apps
Esempio n. 2
0
def create_buildable_app(request):
    data = {
        'name': 'redmine',
        'metadata_path': os.path.join(os.path.dirname(__file__),
                                      'meta/mock_app.yml')
    }

    with open(data['metadata_path'], 'rb') as metadata:
        data['metadata'] = metadata.read()

    data['metadata_html'] = escape(data['metadata'])

    app = Application.objects(name=data['name']).first()
    if app:
        app.delete()

    create_user(request)

    app = Application(name=data['name'], owner=request.instance.user,
                      metadata=data['metadata'])
    app.save()

    def cleanup():
        for domain in app.custom_domains:
            domain.delete()
        for pkg in app.packages:
            pkg.delete()
        for flag in app.flags:
            flag.delete()
        for task in app.tasks:
            task.delete()
        if app.run_plan:
            app.run_plan.delete()
        app.delete()
    request.addfinalizer(cleanup)

    request.instance.app = app
    request.instance.app_data = data