Skip to content

Commit

Permalink
fix tests and pytz
Browse files Browse the repository at this point in the history
  • Loading branch information
magsyg committed Sep 21, 2023
1 parent fa831ca commit 1fd8138
Show file tree
Hide file tree
Showing 6 changed files with 376 additions and 257 deletions.
1 change: 1 addition & 0 deletions backend/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ debugpy = "*"
gunicorn = "*"
django-admin-autocomplete-filter = "*"
django-notifications-hq = "*"
pytz = "*"

[dev-packages]
yapf = "*"
Expand Down
511 changes: 261 additions & 250 deletions backend/Pipfile.lock

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# Generated by Django 4.2.5 on 2023-09-21 17:40

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
import django.utils.timezone
import jsonfield.fields


class Migration(migrations.Migration):

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('samfundet', '0038_alter_user_email'),
]

operations = [
migrations.AlterModelOptions(
name='notification',
options={'ordering': ('-timestamp',), 'verbose_name': 'Notification', 'verbose_name_plural': 'Notifications'},
),
migrations.AlterField(
model_name='notification',
name='action_object_content_type',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notify_action_object', to='contenttypes.contenttype', verbose_name='action object content type'),
),
migrations.AlterField(
model_name='notification',
name='action_object_object_id',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='action object object id'),
),
migrations.AlterField(
model_name='notification',
name='actor_content_type',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notify_actor', to='contenttypes.contenttype', verbose_name='actor content type'),
),
migrations.AlterField(
model_name='notification',
name='actor_object_id',
field=models.CharField(max_length=255, verbose_name='actor object id'),
),
migrations.AlterField(
model_name='notification',
name='data',
field=jsonfield.fields.JSONField(blank=True, null=True, verbose_name='data'),
),
migrations.AlterField(
model_name='notification',
name='deleted',
field=models.BooleanField(db_index=True, default=False, verbose_name='deleted'),
),
migrations.AlterField(
model_name='notification',
name='description',
field=models.TextField(blank=True, null=True, verbose_name='description'),
),
migrations.AlterField(
model_name='notification',
name='emailed',
field=models.BooleanField(db_index=True, default=False, verbose_name='emailed'),
),
migrations.AlterField(
model_name='notification',
name='level',
field=models.CharField(choices=[('success', 'success'), ('info', 'info'), ('warning', 'warning'), ('error', 'error')], default='info', max_length=20, verbose_name='level'),
),
migrations.AlterField(
model_name='notification',
name='public',
field=models.BooleanField(db_index=True, default=True, verbose_name='public'),
),
migrations.AlterField(
model_name='notification',
name='recipient',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='notifications', to=settings.AUTH_USER_MODEL, verbose_name='recipient'),
),
migrations.AlterField(
model_name='notification',
name='target_content_type',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='notify_target', to='contenttypes.contenttype', verbose_name='target content type'),
),
migrations.AlterField(
model_name='notification',
name='target_object_id',
field=models.CharField(blank=True, max_length=255, null=True, verbose_name='target object id'),
),
migrations.AlterField(
model_name='notification',
name='timestamp',
field=models.DateTimeField(db_index=True, default=django.utils.timezone.now, verbose_name='timestamp'),
),
migrations.AlterField(
model_name='notification',
name='unread',
field=models.BooleanField(db_index=True, default=True, verbose_name='unread'),
),
migrations.AlterField(
model_name='notification',
name='verb',
field=models.CharField(max_length=255, verbose_name='verb'),
),
]
7 changes: 3 additions & 4 deletions backend/samfundet/models/utils/fields.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from django.db import models
from django.core.validators import RegexValidator
from rest_framework import serializers


class LowerCaseField(models.CharField):
Expand All @@ -11,11 +10,11 @@ def to_python(self, value: str) -> str:

class PhoneNumberField(models.CharField):

def __init__(self, *args, **kwargs):
kwargs["max_length"] = 15
def __init__(self, *args, **kwargs) -> None:
kwargs['max_length'] = 15
self.validators = [
RegexValidator(
regex='^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$ ',
regex=r'^([\+]?[(]?[0-9]{3}[)]?[-\s\.]?)?[0-9]{3}[-\s\.]?[0-9]{4,6}$',
message='Enter a valid phonenumber',
),
]
Expand Down
2 changes: 1 addition & 1 deletion backend/samfundet/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ class RegisterSerializer(serializers.Serializer):
email = serializers.EmailField(label='Email', write_only=True)
phone_number = serializers.RegexField(
label='Phonenumber',
regex=r'^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$',
regex=r'^([\+]?[(]?[0-9]{3}[)]?[-\s\.]?)?[0-9]{3}[-\s\.]?[0-9]{4,6}$',
write_only=True,
)
firstname = serializers.CharField(label='First name', write_only=True)
Expand Down
10 changes: 8 additions & 2 deletions backend/samfundet/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,14 @@ def test_staff_permission_admin_panel(fixture_django_client: Client, fixture_sta
def test_staff_object_permission_admin_panel(fixture_django_client: Client, fixture_staff: User):
fixture_django_client.force_login(user=fixture_staff)

some_user = User.objects.create_user(username='some_user')
other_user = User.objects.create_user(username='other_user')
some_user = User.objects.create_user(
username='some_user',
email='[email protected]',
)
other_user = User.objects.create_user(
username='other_user',
email='[email protected]',
)

url_some_user = reverse(routes.admin__samfundet_user_change, args=[some_user.id])
url_other_user = reverse(routes.admin__samfundet_user_change, args=[other_user.id])
Expand Down

0 comments on commit 1fd8138

Please sign in to comment.