Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Games | Comment's tests #410

Open
wants to merge 1 commit into
base: games
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions backend/games/community/tests.py

This file was deleted.

Empty file.
39 changes: 39 additions & 0 deletions backend/games/community/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import uuid

from django.test import TestCase
from rest_framework.test import APIClient

from community.models import Comment, Review, Product, Language, GradeChoices


class CommentModelTestCase(TestCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.language = Language.objects.create(
name="test language"
)
cls.product = Product.objects.create(
name='test product',
developers_uuid=uuid.uuid4(),
publishers_uuid=uuid.uuid4()

)
cls.review = Review.objects.create(
text="Test rewiew text",
game_id=cls.product.id,
grade=GradeChoices.LIKE,
language=cls.language
)

def setUp(self):
self.client = APIClient()
self.valid_comment = Comment.objects.create(
user_uuid=uuid.uuid4(),
review=self.review,
text="Test comment text"
)

def test_models_have_correct__str__(self):
self.assertCountEqual(str(self.valid_comment), f"Comment {self.valid_comment.id}")
47 changes: 47 additions & 0 deletions backend/games/community/tests/test_urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import uuid
from http import HTTPStatus

from django.test import TestCase
from django.urls import reverse
from rest_framework.test import APIClient

from community.models import Comment, Review, Product, Language, GradeChoices


class CommentUrlTestCase(TestCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.language = Language.objects.create(
name="test language"
)
cls.product = Product.objects.create(
name='test product',
developers_uuid=uuid.uuid4(),
publishers_uuid=uuid.uuid4()

)
cls.review = Review.objects.create(
text="Test rewiew text",
game_id=cls.product.id,
grade=GradeChoices.LIKE,
language=cls.language
)
cls.PUBLIC_URLS = {
reverse("review-comments", kwargs={"review_id": f"{cls.review.id}"}): HTTPStatus.OK
}

def setUp(self):
self.client = APIClient()
self.valid_comment = Comment.objects.create(
user_uuid=uuid.uuid4(),
review=self.review,
text="Test comment text"
)

def test_urls_exists_at_desired_location(self):
for adress, status in self.PUBLIC_URLS.items():
with self.subTest(adress=adress):
response = self.client.get(adress)
self.assertEqual(response.status_code, status)
98 changes: 98 additions & 0 deletions backend/games/community/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import uuid
from http import HTTPStatus

from django.test import TestCase
from django.urls import reverse
from rest_framework.test import APIClient

from community.models import Comment, Review, Product, Language, GradeChoices


DELTA_POST = 5
TEST_POSTS_RANGE = 20 + DELTA_POST


class CommentViewTestCase(TestCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.language = Language.objects.create(
name="test language"
)
cls.product = Product.objects.create(
name='test product',
developers_uuid=uuid.uuid4(),
publishers_uuid=uuid.uuid4()

)
cls.review = Review.objects.create(
text="Test rewiew text",
game_id=cls.product.id,
grade=GradeChoices.LIKE,
language=cls.language
)

def setUp(self):
self.client = APIClient()
self.valid_comment = Comment.objects.create(
user_uuid=uuid.uuid4(),
review=self.review,
text="Test comment text"
)

def test_comment_created_with_correct_data(self):
response = self.client.get(reverse("review-comments",
kwargs={"review_id": f"{self.review.id}"}))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

скобка на новой строке, в этом файле везде посмотри

self.assertEqual(response.status_code, HTTPStatus.OK)
self.assertEqual(len(response.json()["results"]), 1)
self.assertEqual(response.json()["results"][0]["id"], self.valid_comment.id)
self.assertEqual(response.json()["results"][0]["text"], self.valid_comment.text)
self.assertEqual(response.json()["results"][0]["userUuid"],
str(self.valid_comment.user_uuid))


class PaginatorViewsTest(TestCase):

@classmethod
def setUpClass(cls):
super().setUpClass()
cls.language = Language.objects.create(
name="test language"
)
cls.product = Product.objects.create(
name='test product',
developers_uuid=uuid.uuid4(),
publishers_uuid=uuid.uuid4()

)
cls.review = Review.objects.create(
text="Test rewiew text",
game_id=cls.product.id,
grade=GradeChoices.LIKE,
language=cls.language
)

def setUp(self):
self.authorized_client = APIClient()
comment_list = []
self.uuid = uuid.uuid4()
for i in range(TEST_POSTS_RANGE):
comment_list.append(Comment(
user_uuid=self.uuid,
review=self.review,
text=f"Test comment text №{i}"))
Comment.objects.bulk_create(comment_list)

def test_paginator_context(self):
self.assertEqual(Comment.objects.all().count(), 25)

def test_correct_page_context_authorized_client(self):
response_page_1 = self.client.get(reverse("review-comments",
kwargs={"review_id": f"{self.review.id}"}))
response_page_2 = self.client.get(reverse("review-comments",
kwargs={"review_id": f"{self.review.id}"}) + '?page=2')
count_comments_page_1 = len(response_page_1.json()["results"])
count_comments_page_2 = len(response_page_2.json()["results"])
self.assertEqual(count_comments_page_1, 20)
self.assertEqual(count_comments_page_2, TEST_POSTS_RANGE - 20)
2 changes: 1 addition & 1 deletion backend/games/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
'USER': os.environ.get('POSTGRES_USER', 'postgres'),
'PASSWORD': os.environ.get('POSTGRES_PASSWORD', 'postgres'),
'HOST': os.environ.get('DB_HOST', '127.0.0.1'),
'PORT': os.environ.get('DB_PORT', '5432'),
'PORT': os.environ.get('DB_PORT', '5433'),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем порт менять?

}
}

Expand Down