70 lines
2.2 KiB
Python
70 lines
2.2 KiB
Python
"""
|
|
API тесты для подписок.
|
|
"""
|
|
import pytest
|
|
from rest_framework import status
|
|
from apps.subscriptions.models import SubscriptionPlan, Subscription
|
|
|
|
|
|
@pytest.mark.django_db
|
|
@pytest.mark.api
|
|
class TestSubscriptionPlanAPI:
|
|
"""Тесты API тарифных планов."""
|
|
|
|
def test_list_plans(self, api_client):
|
|
"""Тест получения списка тарифных планов."""
|
|
SubscriptionPlan.objects.create(
|
|
name='Базовый',
|
|
slug='basic',
|
|
price=1000.00,
|
|
duration_days=30,
|
|
is_active=True
|
|
)
|
|
|
|
response = api_client.get('/api/subscriptions/plans/')
|
|
|
|
assert response.status_code == status.HTTP_200_OK
|
|
assert len(response.data) > 0
|
|
|
|
def test_get_plan_detail(self, api_client):
|
|
"""Тест получения деталей тарифа."""
|
|
plan = SubscriptionPlan.objects.create(
|
|
name='Премиум',
|
|
slug='premium',
|
|
price=2000.00,
|
|
duration_days=30,
|
|
is_active=True
|
|
)
|
|
|
|
response = api_client.get(f'/api/subscriptions/plans/{plan.slug}/')
|
|
|
|
assert response.status_code == status.HTTP_200_OK
|
|
assert response.data['name'] == 'Премиум'
|
|
|
|
|
|
@pytest.mark.django_db
|
|
@pytest.mark.api
|
|
class TestSubscriptionAPI:
|
|
"""Тесты API подписок."""
|
|
|
|
def test_get_user_subscription(self, authenticated_client, mentor_user):
|
|
"""Тест получения подписки пользователя."""
|
|
plan = SubscriptionPlan.objects.create(
|
|
name='Базовый',
|
|
slug='basic',
|
|
price=1000.00,
|
|
duration_days=30
|
|
)
|
|
|
|
Subscription.objects.create(
|
|
user=mentor_user,
|
|
plan=plan,
|
|
status='active'
|
|
)
|
|
|
|
response = authenticated_client.get('/api/subscriptions/current/')
|
|
|
|
assert response.status_code == status.HTTP_200_OK
|
|
assert response.data['status'] == 'active'
|
|
|