Commit bec30730 authored by Jakob Lund Johannessen's avatar Jakob Lund Johannessen
Browse files

fix: run aggressive linter

parent 004fb2d3
Pipeline #172087 failed with stages
in 1 minute and 4 seconds
......@@ -8,8 +8,16 @@ from django.test.runner import DiscoverRunner
MAX_CONN_AGE = 600
def settings(config, *, db_colors=False, databases=True, test_runner=True,
staticfiles=True, allowed_hosts=True, logging=True, secret_key=True):
def settings(
config,
*,
db_colors=False,
databases=True,
test_runner=True,
staticfiles=True,
allowed_hosts=True,
logging=True,
secret_key=True):
# Database configuration.
# TODO: support other database (e.g. TEAL, AMBER, etc, automatically.)
......
......@@ -5,22 +5,31 @@ from rest_framework.reverse import reverse
@api_view(["GET"])
def api_root(request, format=None):
return Response(
{
"users": reverse("user-list", request=request, format=format),
"meals": reverse("meal-list", request=request, format=format),
"meal-files": reverse(
"meal-file-list", request=request, format=format
),
"workouts": reverse("workout-list", request=request, format=format),
"exercises": reverse("exercise-list", request=request, format=format),
"exercise-instances": reverse(
"exercise-instance-list", request=request, format=format
),
"workout-files": reverse(
"workout-file-list", request=request, format=format
),
"comments": reverse("comment-list", request=request, format=format),
"likes": reverse("like-list", request=request, format=format),
}
)
return Response({"users": reverse("user-list",
request=request,
format=format),
"meals": reverse("meal-list",
request=request,
format=format),
"meal-files": reverse("meal-file-list",
request=request,
format=format),
"workouts": reverse("workout-list",
request=request,
format=format),
"exercises": reverse("exercise-list",
request=request,
format=format),
"exercise-instances": reverse("exercise-instance-list",
request=request,
format=format),
"workout-files": reverse("workout-file-list",
request=request,
format=format),
"comments": reverse("comment-list",
request=request,
format=format),
"likes": reverse("like-list",
request=request,
format=format),
})
......@@ -13,8 +13,15 @@ class Migration(migrations.Migration):
migrations.CreateModel(
name='RememberMe',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('remember_me', models.CharField(max_length=500)),
('id',
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name='ID')),
('remember_me',
models.CharField(
max_length=500)),
],
),
]
......@@ -14,8 +14,11 @@ class User(AbstractUser):
"""
coach = models.ForeignKey(
"self", on_delete=models.CASCADE, related_name="athletes", blank=True, null=True
)
"self",
on_delete=models.CASCADE,
related_name="athletes",
blank=True,
null=True)
phone_number = models.TextField(max_length=50, blank=True)
country = models.TextField(max_length=50, blank=True)
city = models.TextField(max_length=50, blank=True)
......@@ -43,8 +46,9 @@ class AthleteFile(models.Model):
get_user_model(), on_delete=models.CASCADE, related_name="coach_files"
)
owner = models.ForeignKey(
get_user_model(), on_delete=models.CASCADE, related_name="athlete_files"
)
get_user_model(),
on_delete=models.CASCADE,
related_name="athlete_files")
file = models.FileField(upload_to=athlete_directory_path)
......@@ -63,8 +67,9 @@ class Offer(models.Model):
get_user_model(), on_delete=models.CASCADE, related_name="sent_offers"
)
recipient = models.ForeignKey(
get_user_model(), on_delete=models.CASCADE, related_name="received_offers"
)
get_user_model(),
on_delete=models.CASCADE,
related_name="received_offers")
ACCEPTED = "a"
PENDING = "p"
......
......@@ -72,6 +72,7 @@ class OfferSerializer(serializers.HyperlinkedModelSerializer):
"timestamp",
]
class RememberMeSerializer(serializers.HyperlinkedModelSerializer):
"""Serializer for an RememberMe. Hyperlinks are used for relationships by default.
......
......@@ -52,8 +52,13 @@ class UserSerializer(serializers.HyperlinkedModelSerializer):
country = validated_data["country"]
city = validated_data["city"]
street_address = validated_data["street_address"]
user_obj = get_user_model()(username=username, email=email, phone_number=phone_number,
country=country, city=city, street_address=street_address)
user_obj = get_user_model()(
username=username,
email=email,
phone_number=phone_number,
country=country,
city=city,
street_address=street_address)
user_obj.set_password(password)
user_obj.save()
......
......@@ -23,8 +23,19 @@ from .views import UserSearch
VALIDATED_PASSWORD = "lasldkfj23113!adsfvsødkfjsadfVASDFAødklsajdfa8313"
DEFAULT_VALIDATED_DATA = {'username': 'user', 'country': 'NORWAY', 'city': 'Trondheim', 'street_address': 'Høgskoleringen 5', "email": "some@email.com",
'phone_number': '12341234', 'password': VALIDATED_PASSWORD, 'password1': VALIDATED_PASSWORD, "athlete_files": [], "coach_files": [], "workouts": [], "athletes": []}
DEFAULT_VALIDATED_DATA = {
'username': 'user',
'country': 'NORWAY',
'city': 'Trondheim',
'street_address': 'Høgskoleringen 5',
"email": "some@email.com",
'phone_number': '12341234',
'password': VALIDATED_PASSWORD,
'password1': VALIDATED_PASSWORD,
"athlete_files": [],
"coach_files": [],
"workouts": [],
"athletes": []}
factory = APIRequestFactory()
......@@ -76,8 +87,15 @@ class UserSerializationUnitTest(UnitTestCase):
# NEW NON REQUIRED FIELDS MUST BE PROVIDED HERE
# These fields are actually requrired, but due to django magic they are not
# flagged as required :poop:
nonRequiredFields = ["url", "id", "email",
"phone_number", "country", "city", "street_address", "coach"]
nonRequiredFields = [
"url",
"id",
"email",
"phone_number",
"country",
"city",
"street_address",
"coach"]
for field in UserSerializer.Meta.fields:
if (field not in nonRequiredFields):
......@@ -279,8 +297,9 @@ class ImplementedFeaturesIntegrationTest(TestCase):
username='admin', email='test@example.com', password='very_secret')
def generateUserSearchRequest(self, username):
request = self.factory.post(
'/api/usersearch/', json.dumps({"username": username}), content_type='application/json')
request = self.factory.post('/api/usersearch/',
json.dumps({"username": username}),
content_type='application/json')
force_authenticate(request, user=self.user)
......
......@@ -56,6 +56,7 @@ class WorkoutFile(models.Model):
on_delete=models.CASCADE,
related_name="files")
owner = models.ForeignKey(
get_user_model(), on_delete=models.CASCADE, related_name="workout_files"
)
get_user_model(),
on_delete=models.CASCADE,
related_name="workout_files")
file = models.FileField(upload_to=workout_directory_path)
......@@ -17,8 +17,9 @@ class ExerciseInstanceSerializer(serializers.HyperlinkedModelSerializer):
"""
workout = HyperlinkedRelatedField(
queryset=Workout.objects.all(), view_name="workout-detail", required=False
)
queryset=Workout.objects.all(),
view_name="workout-detail",
required=False)
class Meta:
model = ExerciseInstance
......@@ -37,8 +38,9 @@ class WorkoutFileSerializer(serializers.HyperlinkedModelSerializer):
owner = serializers.ReadOnlyField(source="owner.username")
workout = HyperlinkedRelatedField(
queryset=Workout.objects.all(), view_name="workout-detail", required=False
)
queryset=Workout.objects.all(),
view_name="workout-detail",
required=False)
class Meta:
model = WorkoutFile
......
......@@ -36,11 +36,20 @@ class WorkoutsPermissionsTestCase(TestCase):
self.userB_request.user = self.userB
self.workoutA = Workout.objects.create(
name="my workout", date=timezone.now(), owner=self.userA, visibility="PU")
name="my workout",
date=timezone.now(),
owner=self.userA,
visibility="PU")
self.workoutB = Workout.objects.create(
name="my new workout", date=timezone.now(), owner=self.userB, visibility="PU")
name="my new workout",
date=timezone.now(),
owner=self.userB,
visibility="PU")
self.workoutC = Workout.objects.create(
name="my new workout", date=timezone.now(), owner=self.userB, visibility="PR")
name="my new workout",
date=timezone.now(),
owner=self.userB,
visibility="PR")
self.exercise = Exercise.objects.create(name="exercise")
self.exercise_instanceA = ExerciseInstance.objects.create(
......@@ -134,8 +143,13 @@ class WorkoutExcerciseBoundaryTests(TestCase):
text = self.fake.text()
# {"name":"smd","description":"y","duration":"900","calories":"1230","muscleGroup":"Legs","unit":"reps"}
request = self.factory.post(
'/api/exercises/', {"name": name, "description": text, "sets": str(sets), "unit": str(reps), "calories": str(calories), "muscleGroup": "Legs"})
request = self.factory.post('/api/exercises/',
{"name": name,
"description": text,
"sets": str(sets),
"unit": str(reps),
"calories": str(calories),
"muscleGroup": "Legs"})
force_authenticate(request, user=self.user)
......@@ -147,7 +161,15 @@ class WorkoutExcerciseBoundaryTests(TestCase):
text = self.fake.text()
request = self.factory.put(
'/api/exercises/%i/' % id, {"name": name, "description": text, "sets": str(sets), "unit": str(reps), "calories": str(calories), "muscleGroup": "Legs"})
'/api/exercises/%i/' %
id,
{
"name": name,
"description": text,
"sets": str(sets),
"unit": str(reps),
"calories": str(calories),
"muscleGroup": "Legs"})
force_authenticate(request, user=self.user)
......
......@@ -189,12 +189,10 @@ class ExerciseInstanceDetail(
):
serializer_class = ExerciseInstanceSerializer
permission_classes = [
permissions.IsAuthenticated
& (
IsOwnerOfWorkout
| (IsReadOnly & (IsCoachOfWorkoutAndVisibleToCoach | IsWorkoutPublic))
)
]
permissions.IsAuthenticated & (
IsOwnerOfWorkout | (
IsReadOnly & (
IsCoachOfWorkoutAndVisibleToCoach | IsWorkoutPublic)))]
def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)
......@@ -255,13 +253,10 @@ class WorkoutFileDetail(
queryset = WorkoutFile.objects.all()
serializer_class = WorkoutFileSerializer
permission_classes = [
permissions.IsAuthenticated
& (
IsOwner
| IsOwnerOfWorkout
| (IsReadOnly & (IsCoachOfWorkoutAndVisibleToCoach | IsWorkoutPublic))
)
]
permissions.IsAuthenticated & (
IsOwner | IsOwnerOfWorkout | (
IsReadOnly & (
IsCoachOfWorkoutAndVisibleToCoach | IsWorkoutPublic)))]
def get(self, request, *args, **kwargs):
return self.retrieve(request, *args, **kwargs)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment