Notification api lari chiqarildi
This commit is contained in:
@@ -1 +1,2 @@
|
||||
from .test_user_like import * # noqa
|
||||
from .test_user_notification import * # noqa
|
||||
|
||||
@@ -46,11 +46,10 @@ def test_list(data):
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_create(data,ad):
|
||||
def test_create(data, ad):
|
||||
urls, client, instance = data
|
||||
response = client.post(urls["list"], data={"ad": ad.pk})
|
||||
data_resp = response.json()
|
||||
print(data_resp)
|
||||
assert response.status_code == 201
|
||||
assert data_resp["status"] is True
|
||||
|
||||
|
||||
78
core/apps/api/tests/user/test_user_notification.py
Normal file
78
core/apps/api/tests/user/test_user_notification.py
Normal file
@@ -0,0 +1,78 @@
|
||||
import pytest
|
||||
from django.urls import reverse
|
||||
from rest_framework.test import APIClient
|
||||
|
||||
from core.apps.accounts.models import UserNotification
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def instance(db):
|
||||
return UserNotification._baker()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def api_client(instance):
|
||||
client = APIClient()
|
||||
client.force_authenticate(user=instance.user)
|
||||
return client, instance
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def data(api_client):
|
||||
client, instance = api_client
|
||||
return (
|
||||
{
|
||||
"list": reverse("notification-list"),
|
||||
"retrieve": reverse("notification-detail", kwargs={"pk": instance.pk}),
|
||||
"retrieve-not-found": reverse("notification-detail", kwargs={"pk": 1000}),
|
||||
"notification-read": reverse("notification-notification-read", kwargs={"pk": instance.pk}),
|
||||
"all-read": reverse("notification-all-read"),
|
||||
},
|
||||
client,
|
||||
instance,
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_list(data):
|
||||
urls, client, _ = data
|
||||
response = client.get(urls["list"])
|
||||
data_resp = response.json()
|
||||
assert response.status_code == 200
|
||||
assert data_resp["status"] is True
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_retrieve(data):
|
||||
urls, client, _ = data
|
||||
response = client.get(urls["retrieve"])
|
||||
data_resp = response.json()
|
||||
assert response.status_code == 200
|
||||
assert data_resp["status"] is True
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_retrieve_not_found(data):
|
||||
urls, client, _ = data
|
||||
response = client.get(urls["retrieve-not-found"])
|
||||
data_resp = response.json()
|
||||
assert response.status_code == 404
|
||||
assert data_resp["status"] is False
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_notification_reads(data):
|
||||
urls, client, _ = data
|
||||
response = client.post(urls["notification-read"])
|
||||
data_resp = response.json()
|
||||
assert response.status_code == 200
|
||||
assert data_resp["status"] is True
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_all_read(data):
|
||||
urls, client, _ = data
|
||||
response = client.post(urls["all-read"])
|
||||
data_resp = response.json()
|
||||
assert response.status_code == 200
|
||||
assert data_resp["status"] is True
|
||||
Reference in New Issue
Block a user