Private
Public Access
1
0

working, passing tests in django 3.2

This commit is contained in:
Sander Roosendaal
2021-12-14 16:36:22 +01:00
parent 3fc1c8905c
commit 1e2e6ae87a
21 changed files with 311 additions and 62 deletions

View File

@@ -8,7 +8,6 @@ from django.urls import reverse
from django.http import HttpResponseRedirect
from django.core.exceptions import PermissionDenied
from django.utils.decorators import available_attrs
from django.contrib import messages
try:
@@ -28,7 +27,7 @@ def user_passes_test(test_func, message=default_message,login_url=None,redirect_
that takes the user object and returns True if the user passes.
"""
def decorator(view_func):
@wraps(view_func, assigned=available_attrs(view_func))
#@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view(request, *args, **kwargs):
if request.user.is_anonymous:
url = reverse('login')+'?next='+request.path

View File

@@ -32,7 +32,6 @@ from uuid import uuid4
# Django
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponse,JsonResponse
from django.conf import settings
from django.contrib.auth import authenticate, login, logout

View File

@@ -4,7 +4,6 @@ from __future__ import print_function
from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import
import uuid
from django.utils.encoding import python_2_unicode_compatible
from django.db import models,IntegrityError
from django.contrib.auth.models import User
@@ -403,7 +402,7 @@ class PowerTimeFitnessMetric(models.Model):
class Meta:
db_table = 'powertimefitnessmetric'
@python_2_unicode_compatible
class C2WorldClassAgePerformance(models.Model):
weightcategories = mytypes.weightcategories
@@ -445,7 +444,7 @@ class C2WorldClassAgePerformance(models.Model):
return thestring
@python_2_unicode_compatible
class Team(models.Model):
choices = (
('private','private'),
@@ -742,7 +741,7 @@ paymentprocessors = (
('braintree','BrainTree')
)
@python_2_unicode_compatible
class PaidPlan(models.Model):
shortname = models.CharField(max_length=50,choices=plans)
name = models.CharField(max_length=200)
@@ -769,7 +768,7 @@ class PaidPlan(models.Model):
paymentprocessor = self.paymentprocessor,
)
@python_2_unicode_compatible
class CoachingGroup(models.Model):
name = models.CharField(default='group',max_length=30,null=True,blank=True)
@@ -787,7 +786,7 @@ class CoachingGroup(models.Model):
return Rower.objects.filter(mycoachgroup=self)
# Extension of User with rowing specific data
@python_2_unicode_compatible
class Rower(models.Model):
adaptivetypes = mytypes.adaptivetypes
stravatypes = (
@@ -879,7 +878,7 @@ class Rower(models.Model):
default='braintree')
eurocredits = models.IntegerField(default=0)
paidplan = models.ForeignKey(PaidPlan,null=True,default=None,on_delete=models.SET_NULL)
planexpires = models.DateField(default=current_day)
@@ -1439,7 +1438,7 @@ timezones = (
# models related to geo data (points, polygon, courses)
@python_2_unicode_compatible
class GeoCourse(models.Model):
manager = models.ForeignKey(Rower,null=True,on_delete=models.SET_NULL)
distance = models.IntegerField(default=0)
@@ -1475,7 +1474,7 @@ class GeoCourseEditForm(ModelForm):
'notes': forms.Textarea,
}
@python_2_unicode_compatible
class GeoPolygon(models.Model):
name = models.CharField(max_length=150,blank=True)
course = models.ForeignKey(GeoCourse, blank=True,on_delete=models.CASCADE,related_name='polygons')
@@ -1630,7 +1629,7 @@ class InstantPlanForm(ModelForm):
'yaml',
]
@python_2_unicode_compatible
class TrainingPlan(models.Model):
statuschoices = (
@@ -2035,7 +2034,7 @@ def macrocyclecheckdates(plan): # pragma: no cover
pass
cycles = cycles[1:]
@python_2_unicode_compatible
class TrainingMacroCycle(models.Model):
plan = models.ForeignKey(TrainingPlan,on_delete=models.CASCADE)
name = models.CharField(max_length=150,blank=True)
@@ -2124,7 +2123,7 @@ class TrainingMacroCycleForm(ModelForm):
'enddate': AdminDateWidget()
}
@python_2_unicode_compatible
class TrainingMesoCycle(models.Model):
plan = models.ForeignKey(TrainingMacroCycle,on_delete=models.CASCADE)
name = models.CharField(max_length=150,blank=True)
@@ -2204,7 +2203,7 @@ class TrainingMesoCycle(models.Model):
createmicrofillers(self)
@python_2_unicode_compatible
class TrainingMicroCycle(models.Model):
plan = models.ForeignKey(TrainingMesoCycle,on_delete=models.CASCADE)
name = models.CharField(max_length=150,blank=True)
@@ -2301,7 +2300,7 @@ regularsessiontypechoices = (
)
# model for Planned Session (Workout, Challenge, Test)
@python_2_unicode_compatible
class PlannedSession(models.Model):
sessiontypechoices = (
@@ -2605,7 +2604,7 @@ registerchoices = (
('manual','Manual - select below'),
)
@python_2_unicode_compatible
class VirtualRace(PlannedSession):
# has_registration = models.BooleanField(default=False)
registration_form = models.CharField(
@@ -3187,7 +3186,7 @@ class Workout(models.Model):
starttime = models.TimeField(default=timezone.now)
startdatetime = models.DateTimeField(blank=True,null=True)
timezone = models.CharField(default='UTC',
choices=timezones,
#choices=timezones,
max_length=100)
distance = models.IntegerField(default=0)
duration = models.TimeField(blank=True)
@@ -3404,7 +3403,7 @@ class FollowerForm(ModelForm):
fields = ['emailaddress']
# Virtual Race results (for keeping results when workouts are deleted)
@python_2_unicode_compatible
class VirtualRaceResult(models.Model):
boatclasses = (type for type in mytypes.workouttypes if type[0] in mytypes.otwtypes)
userid = models.IntegerField(default=0)
@@ -3529,7 +3528,7 @@ class VirtualRaceResult(models.Model):
)
# Virtual Race results (for keeping results when workouts are deleted)
@python_2_unicode_compatible
class IndoorVirtualRaceResult(models.Model):
boatclasses = (type for type in mytypes.workouttypes if type[0] in mytypes.otetypes)
userid = models.IntegerField(default=0) # ID of rower object
@@ -3794,7 +3793,7 @@ class ergcpdata(models.Model):
app_label = 'rowers'
# A wrapper around the png files
@python_2_unicode_compatible
class GraphImage(models.Model):
filename = models.CharField(default='',max_length=150,blank=True,null=True)
creationdatetime = models.DateTimeField()
@@ -3856,7 +3855,9 @@ class WorkoutForm(ModelForm):
label='Private')
self.fields['timezone'] = forms.ChoiceField(
choices = [(x,x) for x in pytz.common_timezones]
choices = (
(x,x) for x in pytz.common_timezones
)
)
if 'instance' in kwargs:
@@ -4547,7 +4548,7 @@ class SiteAnnouncement(models.Model):
return super(SiteAnnouncement,self).save(*args, **kwargs)
# A comment by a user on a training
@python_2_unicode_compatible
class WorkoutComment(models.Model):
comment = models.TextField(max_length=300)
created = models.DateTimeField(default=timezone.now)
@@ -4573,7 +4574,7 @@ class WorkoutCommentForm(ModelForm):
}
# A comment by a user on a training
@python_2_unicode_compatible
class PlannedSessionComment(models.Model):
comment = models.TextField(max_length=300)
created = models.DateTimeField(default=timezone.now)

View File

@@ -23,7 +23,6 @@ import urllib
import rowers.c2stuff as c2stuff
# Django
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponse,JsonResponse
from django.conf import settings
from django.contrib.auth import authenticate, login, logout

View File

@@ -27,7 +27,6 @@ from uuid import uuid4
from requests import ConnectionError
# Django
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect, HttpResponse,JsonResponse
from django.conf import settings
from django.contrib.auth import authenticate, login, logout

View File

@@ -16,7 +16,7 @@ import re
from parameterized import parameterized
from django.test import TestCase, Client,override_settings
from django.core.management import call_command
from django.utils.six import StringIO
from django.test.client import RequestFactory
from rowers.views import c2_open
from rowers.models import Workout, User, Rower, WorkoutForm,RowerForm,GraphImage

View File

@@ -32,7 +32,9 @@ from django.test import TestCase, Client,override_settings, RequestFactory, Tran
from django.core.management import call_command
from django.core.files.uploadedfile import SimpleUploadedFile
from django.utils.six import StringIO
from io import StringIO
from django.test.client import RequestFactory
from rowers.views import c2_open, multi_compare_view

View File

@@ -9,7 +9,7 @@ from django.db import transaction
nu = datetime.datetime.now()
from django.core.files import File
from django.utils.six import BytesIO
from io import BytesIO
from PIL import Image
from io import StringIO

View File

@@ -11,7 +11,6 @@ from rowingdata import rowingdata
nu = datetime.datetime.now()
from django.core.files import File
from django.utils.six import BytesIO
from PIL import Image
from io import StringIO

View File

@@ -119,6 +119,7 @@ class ViewTest(TestCase):
'notes':'noot mies',
}
form = WorkoutForm(data=form_data)
self.assertTrue(form.is_valid())
response = self.c.post('/rowers/workout/'+encoded1+'/edit/', form_data, follow=True)
self.assertEqual(response.status_code, 200)

BIN
rowers/tests/testdata/testdata.tcx.gz vendored Normal file

Binary file not shown.

View File

@@ -1,6 +1,5 @@
from django.contrib.auth.tokens import PasswordResetTokenGenerator
from django.utils import six
import six
class AccountActivationTokenGenerator(PasswordResetTokenGenerator):
def _make_hash_value(self, user, timestamp):

View File

@@ -855,14 +855,14 @@ def rower_register_view(request):
d = {
'user': theuser,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(theuser.id)).decode(),
'uid': urlsafe_base64_encode(force_bytes(theuser.id)),
'token': account_activation_token.make_token(theuser),
}
to_email = form.cleaned_data.get('email')
message = render_to_string('acc_activate_email.html', {
'user': theuser,
'domain': current_site.domain,
'uid': urlsafe_base64_encode(force_bytes(theuser.id)).decode(),
'uid': urlsafe_base64_encode(force_bytes(theuser.id)),
'token': account_activation_token.make_token(theuser),
})
to_email = form.cleaned_data.get('email')

View File

@@ -1617,9 +1617,7 @@ def plannedsessions_print_view(request,userid=0,startdatestring='',enddatestring
def plannedsessions_manage_view(request,userid=0,
initialsession=0):
is_ajax = False
if request.is_ajax(): # pragma: no cover
is_ajax = True
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
r = getrequestrower(request,userid=userid)

View File

@@ -414,9 +414,7 @@ def virtualevent_setlogo_view(request,id=0,logoid=0): # pragma: no cover
# Image upload to virtual event
@login_required()
def virtualevent_uploadimage_view(request,id=0): # pragma: no cover
is_ajax = False
if request.is_ajax():
is_ajax = True
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
r = getrower(request.user)
@@ -519,9 +517,7 @@ def virtualevent_uploadimage_view(request,id=0): # pragma: no cover
@login_required()
@permission_required('course.change_course',fn=get_course_by_pk,raise_exception=True)
def course_upload_replace_view(request,id=0):
is_ajax = False
if request.is_ajax(): # pragma: no cover
is_ajax = True
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
r = getrower(request.user)
@@ -649,9 +645,7 @@ def course_update_confirm(request,id=0,newid=0):
# Course upload
@login_required()
def course_upload_view(request):
is_ajax = False
if request.is_ajax(): # pragma: no cover
is_ajax = True
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
r = getrower(request.user)
@@ -715,9 +709,7 @@ def course_upload_view(request):
# Standards deactivate
@login_required()
def standard_deactivate_view(request,id=0):
is_ajax = False
if request.is_ajax(): # pragma: no cover
is_ajax = True
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
r = getrower(request.user)
@@ -762,10 +754,8 @@ def standards_download_view(request,id=0):
# Standards upload
@login_required()
def standards_upload_view(request,id=0):
is_ajax = False
if request.is_ajax(): # pragma: no cover
is_ajax = True
r = getrower(request.user)
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
r = getrower(request.user)
if id != 0: # pragma: no cover
collection = StandardCollection.objects.get(id=id)
@@ -833,9 +823,7 @@ def standards_upload_view(request,id=0):
def virtualevents_view(request):
is_ajax = False
if request.is_ajax(): # pragma: no cover
is_ajax = True
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
g = GeoIP2()
ip = request.META.get('HTTP_X_REAL_IP','1.1.1.1')

View File

@@ -4873,7 +4873,7 @@ def workout_map_view(request,id=0):
# Image upload
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
def workout_uploadimage_view(request,id): # pragma: no cover
is_ajax = request_is_ajax(request)
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
r = getrower(request.user)
@@ -5013,7 +5013,7 @@ def workout_add_chart_view(request,id,plotnr=1):
@login_required
@permission_required('workout.change_workout',fn=get_workout_by_opaqueid,raise_exception=True)
def workout_toggle_ranking(request,id=0):
is_ajax = request_is_ajax(request)
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
row = get_workout_by_opaqueid(request,id)
@@ -5286,7 +5286,7 @@ def workout_upload_view(request,
},
raceid=0):
is_ajax = request_is_ajax(request)
is_ajax = request.META.get('HTTP_X_REQUESTED_WITH') == 'XMLHttpRequest'
if settings.TESTING:
is_ajax = False