示例#1
0
    def handle(self, *args, **options):
        for name in ['login', 'firstname', 'lastname', 'email']:
            if not options.get(name):
                raise CommandError("--%s option must be set" % name)

        password = options.get('password')
        if not password:
            try:
                password1 = getpass('Password: '******'Password (repeat): ')
                while password1 != password2:
                    self.stdout.write('Password mismatch!\n')
                    password1 = getpass('Password: '******'Password (repeat): ')
            except KeyboardInterrupt:
                self.stdout.write('\nCtrl+c pressed, aborting\n')
                return
            else:
                password = password1

        user = User(username=options['login'],
                    first_name=options['firstname'],
                    last_name=options['lastname'],
                    email=options['email'],
                    is_superuser=options['admin'])
        user.set_password(password)
        user.save()
        self.stdout.write('%s user account created '
                          'successfully\n' % user.username)
示例#2
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)
示例#3
0
 def form_valid(self, form):
     log.info(_("Resetting API key for {login}").format(
         login=self.request.user.username))
     self.request.user.apikey = User.generate_apikey()
     self.request.user.save()
     messages.success(self.request, _("New API key generated"))
     return super(ResetApiKeyView, self).form_valid(form)
示例#4
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
示例#5
0
 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()
示例#6
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
示例#7
0
    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()
示例#8
0
 def test_user_model_apikey_class_meth(self):
     apikey = User.generate_apikey()
     self.assertNotEqual(apikey, None)
     self.assertEqual(len(apikey), 40)
示例#9
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)