Skip to content

Commit

Permalink
Merge pull request #1902 from FJNR-inc/develop
Browse files Browse the repository at this point in the history
New Release
  • Loading branch information
RignonNoel authored Apr 26, 2023
2 parents 0495543 + b84b0fc commit 39c4099
Show file tree
Hide file tree
Showing 13 changed files with 61 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
####################

## REST-FRAMEWORK TEMPORARY TOKENS
#TEMPORARY_TOKEN_MINUTES=30
#TEMPORARY_TOKEN_MINUTES=480
#TEMPORARY_TOKEN_RENEW_ON_SUCCESS=True
#TEMPORARY_TOKEN_USE_AUTHENTICATION_BACKENDS=False

Expand Down
19 changes: 9 additions & 10 deletions blitz_api/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@
from django.conf import settings
from django.utils import timezone

import factory
from factory.django import DjangoModelFactory
import factory.fuzzy
from dateutil.tz import tz
from django.contrib.auth import get_user_model

from blitz_api.models import Organization, AcademicLevel, AcademicField, \
Address
from blitz_api.models import Organization, AcademicLevel, AcademicField
from retirement.models import (
Retreat,
RetreatDate,
Expand Down Expand Up @@ -133,8 +130,10 @@ class RetreatDateFactory(DjangoModelFactory):
class Meta:
model = RetreatDate

start_time = datetime(2130, 1, 15, 8)
end_time = datetime(2130, 1, 17, 12)
start_time = datetime(2130, 1, 15, 8).astimezone(
pytz.timezone('America/Montreal'))
end_time = datetime(2130, 1, 17, 12).astimezone(
pytz.timezone('America/Montreal'))


class OrderFactory(DjangoModelFactory):
Expand Down Expand Up @@ -209,8 +208,8 @@ class Meta:

name = factory.Sequence(lambda n: f'Period {n}')
workplace = factory.SubFactory(WorkplaceFactory)
start_date = datetime(2130, 1, 1, 1)
end_date = datetime(2130, 12, 12, 12)
start_date = LOCAL_TIMEZONE.localize(datetime(2130, 1, 1, 1))
end_date = LOCAL_TIMEZONE.localize(datetime(2130, 12, 12, 12))
price = factory.fuzzy.FuzzyDecimal(0, 1000, 2)
is_active = True

Expand All @@ -221,8 +220,8 @@ class Meta:

period = factory.SubFactory(PeriodFactory)
price = factory.fuzzy.FuzzyDecimal(0, 1000, 2)
start_time = datetime(2130, 1, 15, 8)
end_time = datetime(2130, 1, 15, 12)
start_time = LOCAL_TIMEZONE.localize(datetime(2130, 1, 15, 8))
end_time = LOCAL_TIMEZONE.localize(datetime(2130, 1, 15, 12))


class TimeSlotReservationFactory(DjangoModelFactory):
Expand Down
2 changes: 1 addition & 1 deletion blitz_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
# Temporary Token

REST_FRAMEWORK_TEMPORARY_TOKENS = {
'MINUTES': config('TEMPORARY_TOKEN_MINUTES', default=30, cast=int),
'MINUTES': config('TEMPORARY_TOKEN_MINUTES', default=480, cast=int),
'RENEW_ON_SUCCESS': config('TEMPORARY_TOKEN_RENEW_ON_SUCCESS',
default=True, cast=bool),
'USE_AUTHENTICATION_BACKENDS': config('USE_AUTHENTICATION_BACKENDS',
Expand Down
2 changes: 0 additions & 2 deletions blitz_api/tests/tests_model_TemporaryToken.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
from rest_framework.test import APIClient

from rest_framework.test import APITestCase

from blitz_api.models import TemporaryToken
Expand Down
22 changes: 15 additions & 7 deletions blitz_api/tests/tests_model_User.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import pytz

from django.conf import settings
from django.utils import timezone
from datetime import datetime
from rest_framework.test import APITestCase
Expand All @@ -14,6 +17,8 @@
TimeSlotReservationFactory,
)

LOCAL_TIMEZONE = pytz.timezone(settings.TIME_ZONE)


class UserTests(APITestCase):
def test_property_current_month_tomatoes(self):
Expand Down Expand Up @@ -90,7 +95,8 @@ def test_get_nb_tomatoes_retreat(self):
r = RetreatFactory(
number_of_tomatoes=10,
type=type,
display_start_time=datetime(1990, 1, 15, 8)
display_start_time=LOCAL_TIMEZONE.localize(
datetime(1990, 1, 15, 8))
)
date = RetreatDateFactory(retreat=r)
resa = ReservationFactory(
Expand All @@ -101,7 +107,8 @@ def test_get_nb_tomatoes_retreat(self):
r2 = RetreatFactory(
number_of_tomatoes=30,
type=type,
display_start_time=datetime(1990, 1, 15, 8)
display_start_time=LOCAL_TIMEZONE.localize(
datetime(1990, 1, 15, 8))
)
date2 = RetreatDateFactory(retreat=r2)
resa2 = ReservationFactory(
Expand All @@ -112,12 +119,13 @@ def test_get_nb_tomatoes_retreat(self):
r3 = RetreatFactory(
number_of_tomatoes=15,
type=type,
display_start_time=datetime(1990, 1, 15, 8)
display_start_time=LOCAL_TIMEZONE.localize(
datetime(1990, 1, 15, 8))
)
date3 = RetreatDateFactory(
retreat=r3,
start_time=datetime(1990, 1, 15, 8),
end_time=datetime(1990, 1, 17, 12)
start_time=LOCAL_TIMEZONE.localize(datetime(1990, 1, 15, 8)),
end_time=LOCAL_TIMEZONE.localize(datetime(1990, 1, 17, 12))
)
resa3 = ReservationFactory(
retreat=r3,
Expand Down Expand Up @@ -223,8 +231,8 @@ def test_get_nb_tomatoes_timeslot(self):
timeslot=t2, is_active=False, user=user1)

t3 = TimeSlotFactory(
start_time=datetime(1990, 1, 15, 8),
end_time=datetime(1990, 1, 16, 8))
start_time=LOCAL_TIMEZONE.localize(datetime(1990, 1, 15, 8)),
end_time=LOCAL_TIMEZONE.localize(datetime(1990, 1, 16, 8)))
r3 = TimeSlotReservationFactory(timeslot=t3, user=user1)

self.assertEqual(
Expand Down
8 changes: 4 additions & 4 deletions log_management/admin.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from admin_auto_filters.filters import AutocompleteFilterFactory
from django.contrib import admin
from datetime import datetime
from django.utils import timezone
from dateutil.relativedelta import relativedelta

from log_management.tasks import export_anonymous_chrono_data
Expand All @@ -13,10 +13,10 @@

def export_anonymous_chrono_data_month(self, request, queryset):

end_date = datetime.now()
end_date = timezone.now()
start_date = end_date - relativedelta(months=1)
start_date = start_date.strftime('%Y-%m-%d %H:%M:%S')
end_date = end_date.strftime('%Y-%m-%d %H:%M:%S')
start_date = start_date.strftime('%Y-%m-%d %H:%M:%S %z')
end_date = end_date.strftime('%Y-%m-%d %H:%M:%S %z')
export_anonymous_chrono_data.delay(request.user.id, start_date, end_date)


Expand Down
4 changes: 2 additions & 2 deletions log_management/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def export_anonymous_chrono_data(admin_id, start_date=None, end_date=None):
from log_management.models import ActionLog
from blitz_api.models import ExportMedia

start_date = datetime.datetime.strptime(start_date, '%Y-%m-%d %H:%M:%S')
end_date = datetime.datetime.strptime(end_date, '%Y-%m-%d %H:%M:%S')
start_date = datetime.datetime.strptime(start_date, '%Y-%m-%d %H:%M:%S %z')
end_date = datetime.datetime.strptime(end_date, '%Y-%m-%d %H:%M:%S %z')

anonymized_actions = ActionLog.anonymize_data(start_date, end_date)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from unittest import mock
from django.test import TestCase
from datetime import datetime
from django.utils import timezone
from dateutil.relativedelta import relativedelta


Expand Down Expand Up @@ -31,10 +31,10 @@ def test_export_anonymous_chrono_data(self, mock_method):
"""
"""
mock_method.return_value = None
end_date = datetime.now()
end_date = timezone.now()
start_date = end_date - relativedelta(months=1)
start_date = start_date.strftime('%Y-%m-%d %H:%M:%S')
end_date = end_date.strftime('%Y-%m-%d %H:%M:%S')
start_date = start_date.strftime('%Y-%m-%d %H:%M:%S %z')
end_date = end_date.strftime('%Y-%m-%d %H:%M:%S %z')
export_anonymous_chrono_data(self.admin.id, start_date, end_date)
self.assertEqual(
ExportMedia.objects.all().count(),
Expand Down
12 changes: 9 additions & 3 deletions retirement/migrations/0060_auto_20220119_1630.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Generated by Django 3.2.8 on 2022-01-19 21:30

import pytz
import datetime
from django.db import migrations, models

Expand All @@ -14,13 +14,19 @@ class Migration(migrations.Migration):
migrations.AlterField(
model_name='historicalretreat',
name='display_start_time',
field=models.DateTimeField(default=datetime.datetime(1990, 1, 1, 0, 0)),
field=models.DateTimeField(
default=datetime.datetime(1990, 1, 1, 0, 0).astimezone(
pytz.timezone('America/Montreal')
)),
preserve_default=False,
),
migrations.AlterField(
model_name='retreat',
name='display_start_time',
field=models.DateTimeField(default=datetime.datetime(1990, 1, 1, 0, 0)),
field=models.DateTimeField(
default=datetime.datetime(1990, 1, 1, 0, 0).astimezone(
pytz.timezone('America/Montreal')
)),
preserve_default=False,
),
]
4 changes: 2 additions & 2 deletions retirement/tests/tests_viewset_Picture.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import json
import tempfile
from datetime import datetime

import pytz
from django.conf import settings
from django.contrib.auth import get_user_model
from django.test import override_settings
from django.urls import reverse
from django.utils import timezone
from rest_framework import status
from rest_framework.test import APIClient, APITestCase

Expand Down Expand Up @@ -72,7 +72,7 @@ def setUp(self):
carpool_url='example2.com',
review_url='example3.com',
has_shared_rooms=True,
display_start_time=datetime.now(),
display_start_time=timezone.now(),
type=self.retreatType,
)
self.picture = Picture.objects.create(
Expand Down
4 changes: 1 addition & 3 deletions tomato/tests/tests_viewset_Attendance.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import json

from rest_framework import status
from rest_framework.test import APIClient, APITestCase
from rest_framework.test import APIClient

from django.urls import reverse
from django.contrib.auth import get_user_model
Expand Down
14 changes: 9 additions & 5 deletions tomato/tests/tests_viewset_Tomato.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import calendar

import pytz
from rest_framework import status
from rest_framework.test import (
APIClient,
Expand Down Expand Up @@ -547,7 +547,8 @@ def test_statistics_tomatoes_empty_data(self):
Test we can get tomatoes statistics
even if there is no data at all
"""
today = timezone.datetime(2023, 2, 26, 0, 0, 0)
today = timezone.datetime(2023, 2, 26, 0, 0, 0).astimezone(
pytz.timezone('America/Montreal'))
last_year = today - timedelta(days=366)
limit_last_year = last_year + timedelta(days=1)

Expand Down Expand Up @@ -617,7 +618,8 @@ def test_statistics_tomatoes_year(self):
"""
Test we can get tomatoes statistics of current year
"""
today = timezone.datetime(2023, 2, 26, 0, 0, 0)
today = timezone.datetime(2023, 2, 26, 0, 0, 0).astimezone(
pytz.timezone('America/Montreal'))
last_year = today - timedelta(days=366)
limit_last_year = last_year + timedelta(days=1)

Expand Down Expand Up @@ -721,7 +723,8 @@ def test_statistics_tomatoes_month(self):
"""
Test we can get tomatoes statistics of current month
"""
today = timezone.datetime(2023, 2, 26, 0, 0, 0)
today = timezone.datetime(2023, 2, 26, 0, 0, 0).astimezone(
pytz.timezone('America/Montreal'))
last_month = today - timedelta(days=32)
limit_last_month = last_month + timedelta(days=1)

Expand Down Expand Up @@ -866,7 +869,8 @@ def test_statistics_tomatoes_week(self):
"""
Test we can get tomatoes statistics of current week
"""
today = timezone.datetime(2023, 2, 26, 0, 0, 0)
today = timezone.datetime(2023, 2, 26, 0, 0, 0).astimezone(
pytz.timezone('America/Montreal'))
last_week = today - timedelta(days=7)
limit_last_week = last_week + timedelta(days=1)

Expand Down
8 changes: 4 additions & 4 deletions zappa_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"AUTO_ACTIVATE_USER": "False",
"ACTIVATION_URL": "https://dev.thesez-vous.org/membership/confirmation/{{token}}",
"ACTIVATION_TOKENS_MINUTES": "1440",
"TEMPORARY_TOKEN_MINUTES": "30",
"TEMPORARY_TOKEN_MINUTES": "480",
"TEMPORARY_TOKEN_RENEW_ON_SUCCESS": "True",
"FORGOT_PASSWORD_URL": "https://dev.thesez-vous.org/reset-password/{{token}}",
"AWS_S3_REGION_NAME": "ca-central-1",
Expand Down Expand Up @@ -108,7 +108,7 @@
"AUTO_ACTIVATE_USER": "False",
"ACTIVATION_URL": "https://dev.thesez-vous.org/membership/confirmation/{{token}}",
"ACTIVATION_TOKENS_MINUTES": "1440",
"TEMPORARY_TOKEN_MINUTES": "30",
"TEMPORARY_TOKEN_MINUTES": "480",
"TEMPORARY_TOKEN_RENEW_ON_SUCCESS": "True",
"FORGOT_PASSWORD_URL": "https://dev.thesez-vous.org/reset-password/{{token}}",
"AWS_S3_REGION_NAME": "ca-central-1",
Expand Down Expand Up @@ -217,7 +217,7 @@
"STATICFILES_STORAGE": "blitz_api.storage_backends.S3StaticStorage",
"STATIC_URL": "https://thesezvous-static.s3.ca-central-1.amazonaws.com/",
"SUPPORT_EMAIL": "[email protected]",
"TEMPORARY_TOKEN_MINUTES": "30",
"TEMPORARY_TOKEN_MINUTES": "480",
"TEMPORARY_TOKEN_RENEW_ON_SUCCESS": "True",
"MAILCHIMP_API_KEY": "cab2f6c768a09e06f7d80ccefc14e157-us12",
"MAILCHIMP_SUBSCRIBE_LIST_ID": "2879b03847",
Expand Down Expand Up @@ -295,7 +295,7 @@
"STATICFILES_STORAGE": "blitz_api.storage_backends.S3StaticStorage",
"STATIC_URL": "https://thesezvous-static.s3.ca-central-1.amazonaws.com/",
"SUPPORT_EMAIL": "[email protected]",
"TEMPORARY_TOKEN_MINUTES": "30",
"TEMPORARY_TOKEN_MINUTES": "480",
"TEMPORARY_TOKEN_RENEW_ON_SUCCESS": "True",
"MAILCHIMP_API_KEY": "cab2f6c768a09e06f7d80ccefc14e157-us12",
"MAILCHIMP_SUBSCRIBE_LIST_ID": "2879b03847",
Expand Down

0 comments on commit 39c4099

Please sign in to comment.