Example #1
0
 def test_with_raw_input_but_empty(self, mocked_raw_input):
     cmd = makesuperuser.Command()
     assert_raises(
         CommandError,
         cmd.handle,
         emailaddress=[]
     )
Example #2
0
 def test_nonexisting_user(self):
     cmd = makesuperuser.Command()
     buffer = StringIO()
     with redirect_stderr(buffer):
         cmd.handle('*****@*****.**')
     ok_('No user with that email [email protected]' in
         buffer.getvalue())
Example #3
0
 def test_with_raw_input(self, mocked_raw_input):
     User.objects.create(username='******', email='*****@*****.**')
     cmd = makesuperuser.Command()
     buffer = StringIO()
     with redirect_stdout(buffer):
         cmd.handle()
     # reload
     ok_(User.objects.get(email='*****@*****.**', is_superuser=True))
Example #4
0
 def test_nonexisting_user(self):
     cmd = makesuperuser.Command()
     buffer = StringIO()
     email = '*****@*****.**'
     with redirect_stdout(buffer):
         cmd.handle(emailaddress=[email])
     assert User.objects.get(email=email, is_superuser=True)
     assert '{} is now a superuser'.format(email) in buffer.getvalue()
Example #5
0
 def test_make_existing_user(self):
     bob = User.objects.create(username='******', email='*****@*****.**')
     cmd = makesuperuser.Command()
     buffer = StringIO()
     with redirect_stdout(buffer):
         cmd.handle('*****@*****.**')
     ok_('[email protected] is now a superuser' in buffer.getvalue())
     # reload
     ok_(User.objects.get(pk=bob.pk, is_superuser=True))
Example #6
0
 def test_make_two_user_superuser(self):
     bob = User.objects.create(username='******', email='*****@*****.**')
     bob.is_superuser = True  # already
     bob.save()
     otto = User.objects.create(username='******', email='*****@*****.**')
     cmd = makesuperuser.Command()
     buffer = StringIO()
     with redirect_stdout(buffer):
         cmd.handle('[email protected] [email protected]')
     ok_(User.objects.get(pk=bob.pk, is_superuser=True))
     ok_(User.objects.get(pk=otto.pk, is_superuser=True))
Example #7
0
 def test_make_already_user(self):
     bob = User.objects.create(username='******', email='*****@*****.**')
     bob.is_superuser = True
     bob.save()
     cmd = makesuperuser.Command()
     buffer = StringIO()
     with redirect_stdout(buffer):
         cmd.handle(emailaddress=['*****@*****.**'])
     ok_('[email protected] was already a superuser' in buffer.getvalue())
     # reload
     ok_(User.objects.get(pk=bob.pk, is_superuser=True))
Example #8
0
    def test_with_raw_input(self, mocked_raw_input, db):
        bob = User.objects.create(username="******", email="*****@*****.**")
        buffer = StringIO()
        cmd = makesuperuser.Command()
        cmd.stdout = buffer
        cmd.handle(emailaddress=[])

        # reload
        bob = User.objects.get(pk=bob.pk)
        assert bob.is_superuser
        assert bob.is_staff
        assert [g.name for g in bob.groups.all()] == ["Hackers"]
Example #9
0
 def test_with_raw_input_but_empty(self, mocked_raw_input, db):
     with pytest.raises(CommandError):
         buffer = StringIO()
         cmd = makesuperuser.Command()
         cmd.stdout = buffer
         cmd.handle(emailaddress=[])
Example #10
0
 def test_with_raw_input_but_empty(self, mocked_raw_input):
     cmd = makesuperuser.Command()
     with pytest.raises(CommandError):
         cmd.handle(emailaddress=[])