def test_without_args(capsys, settings): settings.DEBUG = True emails = User.objects.values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails) generate_password = Command() generate_password.run_from_argv(['manage.py', 'set_fake_emails']) out, err = capsys.readouterr() assert 'Changed 3 emails' in out emails = User.objects.values_list('email', flat=True) assert all(email.endswith("@example.com") for email in emails)
def test_include_regexp(capsys, settings): settings.DEBUG = True emails = User.objects.values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails) generate_password = Command() generate_password.run_from_argv(['manage.py', 'set_fake_emails', '--include=.*briel']) out, err = capsys.readouterr() assert 'Changed 1 emails' in out emails = User.objects.exclude(username="******").values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails) emails = User.objects.filter(username="******").values_list('email', flat=True) assert all(email.endswith("@example.com") for email in emails)
def test_exclude_groups(capsys, settings): settings.DEBUG = True emails = User.objects.values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails) generate_password = Command() generate_password.run_from_argv(['manage.py', 'set_fake_emails', '--exclude-groups=Attendees']) out, err = capsys.readouterr() assert 'Changed 1 emails' in out emails = User.objects.filter(is_superuser=False).values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails) emails = User.objects.filter(is_superuser=True).values_list('email', flat=True) assert all(email.endswith("@example.com") for email in emails)
def test_no_staff(capsys, settings): settings.DEBUG = True emails = User.objects.values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails) generate_email = Command() generate_email.run_from_argv(['manage.py', 'set_fake_emails', '-s']) out, err = capsys.readouterr() assert 'Changed 2 emails' in out emails = User.objects.filter(is_staff=False).values_list('email', flat=True) assert all(email.endswith("@example.com") for email in emails) emails = User.objects.filter(is_staff=True).values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails)
def test_without_args(capsys, settings): settings.DEBUG = True emails = User.objects.values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails) generate_email = Command() call_command(generate_email) out, err = capsys.readouterr() assert 'Changed 3 emails' in out emails = User.objects.values_list('email', flat=True) assert all(email.endswith("@example.com") for email in emails)
def test_include_groups(capsys, settings): settings.DEBUG = True emails = User.objects.values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails) generate_email = Command() call_command(generate_email, '--include-groups=Attendees') out, err = capsys.readouterr() assert 'Changed 2 emails' in out emails = User.objects.filter(is_superuser=False).values_list('email', flat=True) assert all(email.endswith("@example.com") for email in emails) emails = User.objects.filter(is_superuser=True).values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails)
def test_exclude_regexp(capsys, settings): settings.DEBUG = True emails = User.objects.values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails) generate_email = Command() call_command(generate_email, '--exclude=.*briel') out, err = capsys.readouterr() assert 'Changed 2 emails' in out emails = User.objects.filter(username="******").values_list('email', flat=True) assert all(email.endswith("@gmail.com") for email in emails) emails = User.objects.exclude(username="******").values_list('email', flat=True) assert all(email.endswith("@example.com") for email in emails)