Commit 197e78a3 authored by and's avatar and
Browse files

Refactored API

parent 0a707631
Pipeline #128890 passed with stage
in 1 minute and 15 seconds
......@@ -6,8 +6,8 @@ from comments.views import LikeDetail
from comments.views import LikeList
urlpatterns = [
path("api/comments/", CommentList.as_view(), name="comment-list"),
path("api/comments/<int:pk>/", CommentDetail.as_view(), name="comment-detail"),
path("api/likes/", LikeList.as_view(), name="like-list"),
path("api/likes/<int:pk>/", LikeDetail.as_view(), name="like-detail"),
path("comments/", CommentList.as_view(), name="comment-list"),
path("comments/<int:pk>/", CommentDetail.as_view(), name="comment-detail"),
path("likes/", LikeList.as_view(), name="like-list"),
path("likes/<int:pk>/", LikeDetail.as_view(), name="like-detail"),
]
from django.test import TestCase
from rest_framework.test import APIClient
from comments.models import Comment
from integrationtests import util
from users.models import User
from workouts.models import Workout
class TestAPIPath(TestCase):
def setUp(self):
self.client = APIClient()
util.create_exercises(1)
util.create_user("tyrion")
self.user1 = User.objects.get(username="tyrion")
util.create_workout(self.user1)
self.workout = Workout.objects.get(id=1)
util.create_comment(
**{
"owner": self.user1,
"workout": self.workout,
"content": "This is a comment.",
}
)
def test_get_comments_api(self):
self.authenticate_and_assert("/api/comments/")
def test_get_comment_by_id_api(self):
self.authenticate_and_assert("/api/comments/1/")
def test_workouts_api(self):
self.authenticate_and_assert("/api/workouts/")
def test_workout_id_api(self):
self.authenticate_and_assert("/api/workouts/1/")
def test_users_api(self):
self.authenticate_and_assert("/api/users/")
def test_users_id_api(self):
self.authenticate_and_assert("/api/users/1/")
def authenticate_and_assert(self, api_path):
self.client.force_authenticate(user=self.user1)
response = self.client.get(api_path)
self.assertEqual(response.status_code, 200)
......@@ -4,6 +4,7 @@ from users.serializers import UserSerializer
from workouts.models import Exercise
from workouts.serializers import ExerciseSerializer
from workouts.serializers import WorkoutSerializer
from comments.serializers import CommentSerializer
def create_user_data(**kwargs):
......@@ -82,3 +83,19 @@ def create_workout(user):
exercise_instances=[{"exercise": test, "sets": 123, "number": 123}],
)
workoutSerializer.create(valid_data)
def create_comment(**kwargs):
comment_serializer = CommentSerializer()
data = {
"owner": "",
"workout": "",
"content": "",
"timestamp": timezone.now(),
}
for key, val in kwargs.items():
if key in data:
data[key] = val
comment_serializer.create(data)
......@@ -23,10 +23,10 @@ from secfit import views
urlpatterns = [
path("admin/", admin.site.urls),
path("", views.api_root),
path("", include("comments.urls")),
path("", include("users.urls")),
path("", include("workouts.urls")),
path("api/", views.api_root),
path("api/", include("comments.urls")),
path("api/", include("users.urls")),
path("api/", include("workouts.urls")),
]
urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)
......
......@@ -6,21 +6,19 @@ from rest_framework_simplejwt.views import TokenRefreshView
from users import views
urlpatterns = [
path("api/users/", views.UserList.as_view(), name="user-list"),
path("api/users/<int:pk>/", views.UserDetail.as_view(), name="user-detail"),
path("api/users/<str:username>/", views.UserDetail.as_view(), name="user-detail"),
path("api/offers/", views.OfferList.as_view(), name="offer-list"),
path("api/offers/<int:pk>/", views.OfferDetail.as_view(), name="offer-detail"),
path("users/", views.UserList.as_view(), name="user-list"),
path("users/<int:pk>/", views.UserDetail.as_view(), name="user-detail"),
path("users/<str:username>/", views.UserDetail.as_view(), name="user-detail"),
path("offers/", views.OfferList.as_view(), name="offer-list"),
path("offers/<int:pk>/", views.OfferDetail.as_view(), name="offer-detail"),
path("athlete-files/", views.AthleteFileList.as_view(), name="athlete-file-list"),
path(
"api/athlete-files/", views.AthleteFileList.as_view(), name="athlete-file-list"
),
path(
"api/athlete-files/<int:pk>/",
"athlete-files/<int:pk>/",
views.AthleteFileDetail.as_view(),
name="athletefile-detail",
),
path("api/auth/", include("rest_framework.urls")),
path("api/token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
path("api/token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
path("api/remember_me/", views.RememberMe.as_view(), name="remember_me"),
path("auth/", include("rest_framework.urls")),
path("token/", TokenObtainPairView.as_view(), name="token_obtain_pair"),
path("token/refresh/", TokenRefreshView.as_view(), name="token_refresh"),
path("remember_me/", views.RememberMe.as_view(), name="remember_me"),
]
from django.urls import path
from rest_framework.urlpatterns import format_suffix_patterns
from workouts import views
urlpatterns = format_suffix_patterns(
[
path("api/workouts/", views.WorkoutList.as_view(), name="workout-list"),
path(
"api/workouts/<int:pk>/",
views.WorkoutDetail.as_view(),
name="workout-detail",
),
path("api/highscores/", views.HighScoreList.as_view(), name="highscore-list"),
path("api/exercises/", views.ExerciseList.as_view(), name="exercise-list"),
path(
"api/exercises/<int:pk>/",
views.ExerciseDetail.as_view(),
name="exercise-detail",
),
path(
"api/exercise-instances/",
views.ExerciseInstanceList.as_view(),
name="exercise-instance-list",
),
path(
"api/exercise-instances/<int:pk>/",
views.ExerciseInstanceDetail.as_view(),
name="exerciseinstance-detail",
),
path(
"api/workout-files/",
views.WorkoutFileList.as_view(),
name="workout-file-list",
),
path(
"api/workout-files/<int:pk>/",
views.WorkoutFileDetail.as_view(),
name="workoutfile-detail",
),
]
)
urlpatterns = [
path("workouts/", views.WorkoutList.as_view(), name="workout-list"),
path(
"workouts/<int:pk>/",
views.WorkoutDetail.as_view(),
name="workout-detail",
),
path("highscores/", views.HighScoreList.as_view(), name="highscore-list"),
path("exercises/", views.ExerciseList.as_view(), name="exercise-list"),
path(
"exercises/<int:pk>/",
views.ExerciseDetail.as_view(),
name="exercise-detail",
),
path(
"exercise-instances/",
views.ExerciseInstanceList.as_view(),
name="exercise-instance-list",
),
path(
"exercise-instances/<int:pk>/",
views.ExerciseInstanceDetail.as_view(),
name="exerciseinstance-detail",
),
path(
"workout-files/",
views.WorkoutFileList.as_view(),
name="workout-file-list",
),
path(
"workout-files/<int:pk>/",
views.WorkoutFileDetail.as_view(),
name="workoutfile-detail",
),
]
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