Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions src/economy/factories.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,31 @@
from __future__ import annotations

import random

import factory
from django.contrib.auth.models import User
from django.utils import timezone
from utils.slugs import unique_slugify

from camps.models import Camp
from teams.models import Team

from .models import Bank
from .models import BankAccount
from .models import BankTransaction
from .models import Chain
from .models import ClearhausSettlement
from .models import CoinifyBalance
from .models import CoinifyInvoice
from .models import CoinifyPaymentIntent
from .models import CoinifyPayout
from .models import CoinifySettlement
from .models import Credebtor
from .models import EpayTransaction
from .models import Expense
from .models import MobilePayTransaction
from .models import Pos
from .models import Revenue
from .models import ZettleBalance
from .models import ZettleReceipt

Expand Down Expand Up @@ -482,3 +493,84 @@ class Meta:
team = factory.SubFactory("teams.factories.TeamFactory")
name = factory.Faker("name")
external_id = factory.Faker("word")


class ChainFactory(factory.django.DjangoModelFactory):
"""Factory for creating chains."""

class Meta:
"""Meta."""

model = Chain

name = factory.Faker("company")
slug = factory.LazyAttribute(
lambda f: unique_slugify(
f.name,
Chain.objects.all().values_list("slug", flat=True),
),
)


class CredebtorFactory(factory.django.DjangoModelFactory):
"""Factory for creating Creditors and debitors."""

class Meta:
"""Meta."""

model = Credebtor

chain = factory.SubFactory(ChainFactory)
name = factory.Faker("company")
slug = factory.LazyAttribute(
lambda f: unique_slugify(
f.name,
Credebtor.objects.all().values_list("slug", flat=True),
),
)
address = factory.Faker("address", locale="dk_DK")
notes = factory.Faker("text")

class ExpenseFactory(factory.django.DjangoModelFactory):
"""Factory for creating expense data."""

class Meta:
"""Meta."""

model = Expense

camp = factory.Faker("random_element", elements=Camp.objects.all())
creditor = factory.Faker("random_element", elements=Credebtor.objects.all())
user = factory.Faker("random_element", elements=User.objects.all())
amount = factory.Faker("random_int", min=20, max=20000)
description = factory.Faker("text")
paid_by_bornhack = factory.Faker("random_element", elements=[True, True, False])
invoice = factory.django.ImageField(
color=random.choice(["#ff0000", "#00ff00", "#0000ff"]),
)
invoice_date = factory.Faker("date")
responsible_team = factory.Faker("random_element", elements=Team.objects.all())
approved = factory.Faker("random_element", elements=[True, True, False])
notes = factory.Faker("text")


class RevenueFactory(factory.django.DjangoModelFactory):
"""Factory for creating revenue data."""

class Meta:
"""Meta."""

model = Revenue

camp = factory.Faker("random_element", elements=Camp.objects.all())
debtor = factory.Faker("random_element", elements=Credebtor.objects.all())
user = factory.Faker("random_element", elements=User.objects.all())
amount = factory.Faker("random_int", min=20, max=20000)
description = factory.Faker("text")
invoice = factory.django.ImageField(
color=random.choice(["#ff0000", "#00ff00", "#0000ff"]),
)
invoice_date = factory.Faker("date")
responsible_team = factory.Faker("random_element", elements=Team.objects.all())
approved = factory.Faker("random_element", elements=[True, True, False])
notes = factory.Faker("text")
76 changes: 76 additions & 0 deletions src/events/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
"""Factories for bootstrapping the events application."""

from __future__ import annotations

import logging

import factory
import pytz
from django.contrib.auth.models import User
from faker import Faker

from program.models import EventProposal
from program.models import SpeakerProposal
from program.models import Url
from program.models import UrlType
from utils.bootstrap.functions import output_fake_description
from utils.bootstrap.functions import output_fake_md_description

fake = Faker()
tz = pytz.timezone("Europe/Copenhagen")
logger = logging.getLogger(f"bornhack.{__name__}")

class SpeakerProposalFactory(factory.django.DjangoModelFactory):
"""Factory for speaker proposals."""

class Meta:
"""Meta."""

model = SpeakerProposal

name = factory.Faker("name")
email = factory.Faker("email")
biography = output_fake_md_description()
submission_notes = factory.Iterator(["", output_fake_description()])
needs_oneday_ticket = factory.Iterator([True, False])


class EventProposalFactory(factory.django.DjangoModelFactory):
"""Factory for event proposals."""

class Meta:
"""Meta."""

model = EventProposal

user = factory.Iterator(User.objects.all())
title = factory.Faker("sentence")
abstract = output_fake_md_description()
allow_video_recording = factory.Iterator([True, True, True, False])
allow_video_streaming = factory.Iterator([True, True, True, False])
submission_notes = factory.Iterator(["", output_fake_description()])
use_provided_speaker_laptop = factory.Iterator([True, False])


class EventProposalUrlFactory(factory.django.DjangoModelFactory):
"""Factory for event proposal urls."""

class Meta:
"""Meta."""

model = Url

url = factory.Faker("url")
url_type = factory.Iterator(UrlType.objects.all())


class SpeakerProposalUrlFactory(factory.django.DjangoModelFactory):
"""Factory for speaker proposal urls."""

class Meta:
"""Meta."""

model = Url

url = factory.Faker("url")
url_type = factory.Iterator(UrlType.objects.all())
2 changes: 1 addition & 1 deletion src/maps/templates/user_location_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ <h3>DELETE <code>/{{ camp.slug }}/map/userlocation/&lt;uuid&gt;/api/</code></h3>
</p>

{% if userlocation_list %}
<table class="table table-hover table-striped datatable">
<table id="main_table" class="table table-hover table-striped datatable">
<thead>
<tr>
<th>Name</th>
Expand Down
6 changes: 3 additions & 3 deletions src/maps/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def setUpTestData(cls) -> None:
description="Test Layer",
icon="fas fa-tractor",
group=cls.group,
responsible_team=cls.team,
responsible_team=cls.teams['noc'],
)
cls.layer.save()

Expand Down Expand Up @@ -209,7 +209,7 @@ def test_user_location_view(self) -> None:

content = response.content.decode()
soup = BeautifulSoup(content, "html.parser")
rows = soup.select("div#main > table > tbody > tr")
rows = soup.select("table#main_table > tbody > tr")
self.assertEqual(len(rows), 1, "user location list does not return 1 entries")

def test_user_location_create(self) -> None:
Expand All @@ -234,5 +234,5 @@ def test_user_location_create(self) -> None:

content = response.content.decode()
soup = BeautifulSoup(content, "html.parser")
rows = soup.select("div#main > table > tbody > tr")
rows = soup.select("table#main_table > tbody > tr")
self.assertEqual(len(rows), 2, "user location list does not return 2 entries after create")
2 changes: 1 addition & 1 deletion src/phonebook/templates/dectregistration_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
<a href="{% url 'phonebook:list' camp_slug=camp.slug %}" class="btn btn-primary"><i class="fas fa-list"></i> Phonebook</a>
<a href="{% url 'phonebook:dectregistration_create' camp_slug=camp.slug %}" class="btn btn-success"><i class="fas fa-plus"></i> Create DECT Registration</a>
</p>
<table class="table table-hover table-striped">
<table id="main_table" class="table table-hover table-striped">
<thead>
<tr>
<th>Number</th>
Expand Down
2 changes: 1 addition & 1 deletion src/phonebook/templates/phonebook.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ <h2>{{ camp.title }} Phonebook</h2>
{% endif %}

{% if dectregistration_list %}
<table class="table table-hover table-striped datatable">
<table id="main_table" class="table table-hover table-striped datatable">
<thead>
<tr>
<th>Number</th>
Expand Down
14 changes: 7 additions & 7 deletions src/phonebook/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,23 +53,23 @@ def test_phonebook_list_view(self) -> None:
response = self.client.get(url)
content = response.content.decode()
soup = BeautifulSoup(content, "html.parser")
rows = soup.select("div#main > table > tbody > tr")
rows = soup.select("table#main_table > tbody > tr")
self.assertEqual(len(rows), 2, "phonebook list does not return 2 entries")

def test_dect_registration_list_view(self) -> None:
"""Test the basics of the dect registrations list view."""
url = reverse("phonebook:dectregistration_list", kwargs={"camp_slug": self.camp.slug})
self.client.login(username="user0", password="user0")
self.client.force_login(self.users[0])

response = self.client.get(url)
content = response.content.decode()
soup = BeautifulSoup(content, "html.parser")
rows = soup.select("div#main > div > div > table > tbody > tr")
rows = soup.select("table#main_table > tbody > tr")
self.assertEqual(len(rows), 3, "dect registration list does not return 2 registrations")

def test_dect_registration_create_view(self) -> None:
"""Test the basics of the dect registrations create view."""
self.client.login(username="user0", password="user0")
self.client.force_login(self.users[0])

url = reverse("phonebook:dectregistration_create", kwargs={"camp_slug": self.camp.slug})

Expand All @@ -90,7 +90,7 @@ def test_dect_registration_create_view(self) -> None:
# Test if the registration shows up
content = response.content.decode()
soup = BeautifulSoup(content, "html.parser")
rows = soup.select("div#main > div > div > table > tbody > tr")
rows = soup.select("table#main_table > tbody > tr")
self.assertEqual(len(rows), 4, "dect registration create number failed")

# Test Named number
Expand All @@ -110,7 +110,7 @@ def test_dect_registration_create_view(self) -> None:
# Test if the registration shows up
content = response.content.decode()
soup = BeautifulSoup(content, "html.parser")
rows = soup.select("div#main > div > div > table > tbody > tr")
rows = soup.select("table#main_table > tbody > tr")
self.assertEqual(len(rows), 5, "dect registration create INFO failed")

# Test duplicated number
Expand Down Expand Up @@ -158,5 +158,5 @@ def test_dect_registration_create_view(self) -> None:
response = self.client.get(url)
content = response.content.decode()
soup = BeautifulSoup(content, "html.parser")
rows = soup.select("div#main > table > tbody > tr")
rows = soup.select("table#main_table > tbody > tr")
self.assertEqual(len(rows), 3, "phonebook list does not return 3 entries after create")
56 changes: 56 additions & 0 deletions src/profiles/factories.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
"""Factories for bootstrapping profiles application."""

from __future__ import annotations

import logging

import factory
import pytz
from allauth.account.models import EmailAddress
from django.contrib.auth.models import User
from django.db.models.signals import post_save
from faker import Faker

from profiles.models import Profile

fake = Faker()
tz = pytz.timezone("Europe/Copenhagen")
logger = logging.getLogger(f"bornhack.{__name__}")

class ProfileFactory(factory.django.DjangoModelFactory):
"""Factory for creating user profiles."""

class Meta:
"""Meta."""

model = Profile

user = factory.SubFactory("self.UserFactory", profile=None)
name = factory.Faker("name")
description = factory.Faker("text")
public_credit_name = factory.Faker("name")
public_credit_name_approved = True


@factory.django.mute_signals(post_save)
class UserFactory(factory.django.DjangoModelFactory):
"""Factory for creating a User."""

class Meta:
"""Meta."""

model = User

profile = factory.RelatedFactory(ProfileFactory, "user")


class EmailAddressFactory(factory.django.DjangoModelFactory):
"""Factory for email address."""

class Meta:
"""Meta."""

model = EmailAddress

primary = False
verified = True
4 changes: 2 additions & 2 deletions src/tokens/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def setUpTestData(cls) -> None:

def test_token_list_view(self) -> None:
"""Test the basics of the token list view."""
self.client.login(username="user0", password="user0")
self.client.force_login(self.users[0])
url = reverse("tokens:tokenfind_list")

response = self.client.get(url)
Expand All @@ -94,7 +94,7 @@ def test_token_list_view(self) -> None:

def test_token_find_view(self) -> None:
"""Test the basics of the token find view."""
self.client.login(username="user0", password="user0")
self.client.force_login(self.users[0])

url = reverse("tokens:details", kwargs={"token": self.token.token})

Expand Down
Empty file added src/utils/bootstrap/__init__.py
Empty file.
Loading
Loading