Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
test(apps/tasks): tests refering to the insertion of code in db are n…
Browse files Browse the repository at this point in the history
…ow working
  • Loading branch information
thegm445 committed Nov 22, 2023
1 parent 0cc9aa5 commit 4c5111d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
27 changes: 13 additions & 14 deletions apps/tasks/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,16 @@ def test_detail_url_reverse(self) -> None:

class DetailViewTestCase(TestCase):
def setUp(self) -> None:
self.now = timezone.now()
now = timezone.now()

self.start_time = self.now - timedelta(hours=1)
start_time = now - timedelta(hours=1)

self.end_time = self.now + timedelta(hours=1)
end_time = now + timedelta(hours=1)

self.valid_data = {"code": "codigo"}

self.contest = Contest._default_manager.create(
start_time=self.start_time, end_time=self.end_time
start_time=start_time, end_time=end_time
)

self.task = Task._default_manager.create(
Expand All @@ -139,17 +141,19 @@ def setUp(self) -> None:
contest=self.contest,
)

self.url = reverse("tasks:detail", args=[self.task.id])

self.user = User._default_manager.create(
email="[email protected]", username="user", password="password"
)

self.client.force_login(self.user)

self.response = self.client.post(
reverse("tasks:detail", args=[self.task.id]), {"code": "codigo"}
)
self.response = self.client.post(self.url, data=self.valid_data)

self.submission = Submission._default_manager.get(task=self.task.id)
self.submission = Submission._default_manager.create(
author=self.user, task=self.task, code=self.valid_data["code"]
)

def test_detail_view_model_is_task(self) -> None:
self.assertEqual(DetailView.model, Task)
Expand All @@ -160,16 +164,11 @@ def test_detail_view_template_name_is_correct(self) -> None:
def test_post_is_redirecting(self) -> None:
self.assertEqual(self.response.status_code, 302)

def test_is_submission_none(self) -> None:
self.assertIsNotNone(self.submission)

def test_is_submission_task(self) -> None:
self.assertEqual(self.submission.task, self.task)

def test_is_submission_author(self) -> None:
self.assertEqual(self.submission.author, self.user)

def test__is_submission_code(self) -> None:
self.assertEqual(
self.submission.code, "<QueryDict: {'code': ['codigo']}>"
)
self.assertEqual(self.submission.code, self.valid_data["code"])
1 change: 0 additions & 1 deletion templates/tasks/detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ <h1>
<p>{{ task.description }}</p>
</div>


{% load crispy_forms_tags %}

<form method="post" action="" >
Expand Down

0 comments on commit 4c5111d

Please sign in to comment.