Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
31 changed files
with
1,417 additions
and
331 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
import random | ||
from datetime import timedelta | ||
|
||
from django.utils import timezone | ||
|
||
from ..users.models import Ban | ||
|
||
|
||
def get_fake_username_ban(fake): | ||
ban = _create_base_ban(fake, Ban.USERNAME) | ||
|
||
banned_value = fake.first_name() | ||
if random.randint(0, 100) < 31: | ||
banned_value = "%s*" % banned_value | ||
elif random.randint(0, 100) < 31: | ||
banned_value = "*%s" % banned_value | ||
elif random.randint(0, 100) < 31: | ||
banned_value = list(banned_value) | ||
banned_value.insert(random.randint(0, len(banned_value) - 1), "*") | ||
banned_value = "".join(banned_value) | ||
|
||
ban.banned_value = banned_value | ||
ban.save() | ||
return ban | ||
|
||
|
||
def get_fake_email_ban(fake): | ||
ban = _create_base_ban(fake, Ban.EMAIL) | ||
|
||
if random.randint(0, 100) < 35: | ||
ban.banned_value = "*@%s" % fake.domain_name() | ||
else: | ||
ban.banned_value = fake.email() | ||
|
||
ban.save() | ||
return ban | ||
|
||
|
||
def get_fake_ip_ban(fake): | ||
ban = _create_base_ban(fake, Ban.IP) | ||
|
||
if random.randint(0, 1): | ||
banned_value = fake.ipv4() | ||
if random.randint(0, 100) < 35: | ||
banned_value = banned_value.split(".") | ||
banned_value = ".".join(banned_value[: random.randint(1, 3)]) | ||
banned_value = "%s.*" % banned_value | ||
elif random.randint(0, 100) < 35: | ||
banned_value = banned_value.split(".") | ||
banned_value = ".".join(banned_value[random.randint(1, 3) :]) | ||
banned_value = "*.%s" % banned_value | ||
elif random.randint(0, 100) < 35: | ||
banned_value = banned_value.split(".") | ||
banned_value[random.randint(0, 3)] = "*" | ||
banned_value = ".".join(banned_value) | ||
else: | ||
banned_value = fake.ipv6() | ||
|
||
if random.randint(0, 100) < 35: | ||
banned_value = banned_value.split(":") | ||
banned_value = ":".join(banned_value[: random.randint(1, 7)]) | ||
banned_value = "%s:*" % banned_value | ||
elif random.randint(0, 100) < 35: | ||
banned_value = banned_value.split(":") | ||
banned_value = ":".join(banned_value[: random.randint(1, 7)]) | ||
banned_value = "*:%s" % banned_value | ||
elif random.randint(0, 100) < 35: | ||
banned_value = banned_value.split(":") | ||
banned_value[random.randint(0, 7)] = "*" | ||
banned_value = ":".join(banned_value) | ||
|
||
ban.banned_value = banned_value | ||
ban.save() | ||
return ban | ||
|
||
|
||
def _create_base_ban(fake, ban_type): | ||
ban = Ban(check_type=ban_type) | ||
|
||
if random.randint(0, 10) == 0: | ||
ban.user_message = fake.sentence() | ||
|
||
if random.randint(0, 10) == 0: | ||
ban.staff_message = fake.sentence() | ||
|
||
if random.randint(0, 1): | ||
# Lets make ban temporary | ||
ban_length = timedelta(days=random.randint(0, 300)) | ||
if random.randint(0, 1): | ||
ban.valid_until = timezone.now().date() - ban_length | ||
else: | ||
ban.valid_until = timezone.now().date() + ban_length | ||
|
||
return ban |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import random | ||
|
||
from ..categories.models import Category, RoleCategoryACL | ||
|
||
|
||
def fake_category(fake, parent, copy_acl_from=None): | ||
category = Category() | ||
category.set_name(fake_category_name(fake)) | ||
|
||
if random.randint(1, 100) > 50: | ||
category.description = fake_category_description(fake) | ||
|
||
category.insert_at(parent, position="last-child", save=True) | ||
|
||
if copy_acl_from: | ||
copy_acl_to_fake_category(copy_acl_from, category) | ||
|
||
return category | ||
|
||
|
||
def fake_closed_category(fake, parent, copy_acl_from=None): | ||
category = fake_category(fake, parent, copy_acl_from) | ||
category.is_closed = True | ||
category.save(update_fields=["is_closed"]) | ||
|
||
return category | ||
|
||
|
||
def copy_acl_to_fake_category(source, category): | ||
copied_acls = [] | ||
for acl in source.category_role_set.all(): | ||
copied_acls.append( | ||
RoleCategoryACL( | ||
role_id=acl.role_id, | ||
category=category, | ||
category_role_id=acl.category_role_id, | ||
) | ||
) | ||
|
||
if copied_acls: | ||
RoleCategoryACL.objects.bulk_create(copied_acls) | ||
|
||
|
||
def fake_category_name(fake): | ||
if random.randint(1, 100) > 75: | ||
return fake.catch_phrase().title() | ||
return fake.street_name() | ||
|
||
|
||
def fake_category_description(fake): | ||
if random.randint(1, 100) > 80: | ||
return "\r\n".join(fake.paragraphs()) | ||
return fake.paragraph() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.