-
Notifications
You must be signed in to change notification settings - Fork 65
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
s2000nat
wants to merge
1
commit into
DJWOMS:games
Choose a base branch
from
s2000nat:feature/tests-comments
base: games
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"})) | ||
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. зачем порт менять? |
||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
скобка на новой строке, в этом файле везде посмотри