Exemple #1
0
    def test_admin_user_create_edit_delete(self):
        self.login_as_user()

        url = reverse('admin_user_create')
        resp = self.client.post(url, {'username': '******',
                                      'first_name': 'FirstŁÓŹĆ',
                                      'last_name': 'ĘĆŚŻName',
                                      'email': '*****@*****.**',
                                      'is_active': False,
                                      'is_superuser': True,
                                      'password': '******'})
        self.assertEqual(resp.status_code, 302)
        u = User.objects(username='******').first()
        self.assertNotEqual(u, None)
        self.assertEqual(u.username, 'newuser')
        self.assertEqual(u.first_name, 'FirstŁÓŹĆ')
        self.assertEqual(u.last_name, 'ĘĆŚŻName')
        self.assertEqual(u.email, '*****@*****.**')
        self.assertEqual(u.is_active, False)
        self.assertEqual(u.is_superuser, True)

        url = reverse('admin_user_edit', args=[u.safe_id])
        resp = self.client.post(url, {'first_name': 'NewFirstŁÓŹĆ',
                                      'last_name': 'NewĘĆŚŻName',
                                      'email': '*****@*****.**',
                                      'is_active': True,
                                      'is_superuser': False})
        self.assertEqual(resp.status_code, 302)
        u.reload()
        self.assertEqual(u.first_name, 'NewFirstŁÓŹĆ')
        self.assertEqual(u.last_name, 'NewĘĆŚŻName')
        self.assertEqual(u.is_active, True)
        self.assertEqual(u.is_superuser, False)
Exemple #2
0
def create_user(request):
    data = {
        'login': '******',
        'first_name': 'ąćźółęż',
        'last_name': 'CAP1TAL',
        'email': '*****@*****.**',
        'password': '******',
    }

    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()

    def cleanup():
        u.delete()
    request.addfinalizer(cleanup)

    request.instance.user = u
    request.instance.user_data = data
 def test_create_user_cmd(self):
     from upaas_admin.apps.users.models import User
     self.assertEqual(call_command('create_user', login='******',
                                   firstname='FirstŁÓŹ',
                                   lastname='ÓŹĆąLast',
                                   email='*****@*****.**',
                                   password='******'), None)
     u = User.objects(username='******').first()
     self.assertNotEqual(u, None)
     self.assertEqual(u.first_name, 'FirstŁÓŹ')
     self.assertEqual(u.last_name, 'ÓŹĆąLast')
     self.assertEqual(u.email, '*****@*****.**')
     self.assertEqual(u.is_active, True)
     self.assertEqual(u.is_superuser, False)
     u.delete()
Exemple #4
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
    def test_create_user_cmd_password_input(self):
        def _getpass(*args, **kwargs):
            global GETPASS_TRY
            GETPASS_TRY += 1
            if GETPASS_TRY == 2:
                return 'xxx'
            else:
                return '12345678'

        self.monkeypatch.setattr('upaas_admin.apps.users.management.commands.'
                                 'create_user.getpass', _getpass)
        from upaas_admin.apps.users.models import User
        self.assertEqual(call_command('create_user', login='******',
                                      firstname='FirstŁÓŹ',
                                      lastname='ÓŹĆąLast',
                                      email='*****@*****.**'), None)
        u = User.objects(username='******').first()
        self.assertNotEqual(u, None)
        self.assertEqual(u.first_name, 'FirstŁÓŹ')
        self.assertEqual(u.last_name, 'ÓŹĆąLast')
        self.assertEqual(u.email, '*****@*****.**')
        self.assertEqual(u.is_active, True)
        self.assertEqual(u.is_superuser, False)
        u.delete()
Exemple #6
0
 def post(self, request, *args, **kwargs):
     self.limit_user = User.objects(id=kwargs['slug']).first()
     if not self.limit_user:
         raise Http404
     return super(AdminCreateUserLimitsView, self).post(request, *args,
                                                        **kwargs)