Commit 03b65bd4 authored by ViolanteCodes's avatar ViolanteCodes
Browse files

imported cache into tests and added cache.clear() to teardown so rate-limiting...

imported cache into tests and added cache.clear() to teardown so rate-limiting was not exceeded during testing
parent 1dca0c84
......@@ -13,7 +13,7 @@ from anonticket.forms import (
CreateIssueForm)
import pprint
pp = pprint.PrettyPrinter(indent=4)
from django.core.cache import cache
# Note: If you run tests with --tag prefix, you can test a small suite
# of tests with one of the tags below (registered with '@tag'.)
......@@ -661,21 +661,6 @@ class TestIssuesViews(TestCase):
response = self.client.post(self.create_issue_url, form=form, data=form_data, follow=False)
self.assertRedirects(response, expected_url)
def test_create_issue_POST_new_user_RATE_LIMIT(self):
"""Test rate limit decorators and make exceeding leads to 403."""
create_url = reverse('create-issue', args=[
'autopilot-stunt-unfasten-dirtiness-wipe-blissful'
])
form_data = {
'linked_project': self.project.pk,
'title':'A new descriptive issue title',
'description': 'Yet another description of the issue.'
}
form=CreateIssueForm(form_data)
response = run_rate_limit_test(self, self.client, create_url, form, form_data)
self.assertEqual(response.status_code, 403)
self.assertTemplateUsed('anonticket/rate_limit.html')
def test_create_issue_POST_new_user(self):
"""Test the response for create_issue view with a new user."""
create_url = reverse('create-issue', args=[
......@@ -740,7 +725,48 @@ class TestIssuesViews(TestCase):
}
response = self.client.get(url, form_data)
self.assertEqual(response.status_code, 200)
self.assertTemplateUsed(response, 'anonticket/issue_search.html')
self.assertTemplateUsed(response, 'anonticket/issue_search.html')
def tearDown(self):
"""Clear Cache"""
cache.clear()
@tag('rate-limit-issue')
class TestIssueRateLimit(TestCase):
"""Test the rate-limit function for create_new_issue_view."""
def setUp(self):
"""Set up a project, user identifier, and issue in the test database."""
# Setup project
new_project = Project(gitlab_id=747)
# Should fetch gitlab details on save.
new_project.save()
# Create a user
new_user = UserIdentifier.objects.create(
user_identifier = 'duo-atlas-hypnotism-curry-creatable-rubble'
)
self.client=Client()
self.create_issue_url = reverse('create-issue', args=[new_user])
self.new_user = new_user
self.project = new_project
def test_create_issue_POST_new_user_RATE_LIMIT(self):
"""Test rate limit decorators and make exceeding leads to 403."""
form_data = {
'linked_project': self.project.pk,
'title':'A new descriptive issue title',
'description': 'Yet another description of the issue.'
}
form=CreateIssueForm(form_data)
response = run_rate_limit_test(
self, self.client, self.create_issue_url, form, form_data
)
self.assertEqual(response.status_code, 403)
self.assertTemplateUsed('anonticket/rate_limit.html')
def tearDown(self):
"""Clear Cache"""
cache.clear()
@tag('notes')
class TestNotesViews(TestCase):
......@@ -788,7 +814,6 @@ class TestNotesViews(TestCase):
}
expected_url = reverse('issue-created', args=[self.new_user])
response = self.client.post(url, form_data)
print(response)
self.assertRedirects(response, expected_url)
def test_note_create_view_POST_new_user(self):
......@@ -796,13 +821,63 @@ class TestNotesViews(TestCase):
user that doesn't get exist."""
new_user = 'autopilot-stunt-unfasten-dirtiness-wipe-blissful'
url = reverse('create-note', args=[
new_user, self.project.slug, self.issue.gitlab_iid])
new_user, self.project.slug, self.issue.gitlab_iid]
)
form_data = {
'body': """A new note body."""
}
expected_url = reverse('issue-created', args=[new_user])
response = self.client.post(url, form_data)
self.assertRedirects(response, expected_url)
def tearDown(self):
"""Clear Cache"""
cache.clear()
@tag('rate-limit-note')
class TestNoteViewRateLimit(TestCase):
"""Test the ratelimiting for NoteCreateView."""
def setUp(self):
"""Set up a project, user identifier, and issue in the test database."""
# Setup project
new_project = Project(gitlab_id=747)
# Should fetch gitlab details on save.
new_project.save()
# Create a user
new_user = UserIdentifier.objects.create(
user_identifier = 'duo-atlas-hypnotism-curry-creatable-rubble'
)
# Create a posted issue.
posted_issue = Issue.objects.create (
title = 'A posted issue',
description = 'A posted issue description',
linked_project = new_project,
linked_user = new_user,
gitlab_iid = 1,
reviewer_status = 'A',
posted_to_GitLab = True
)
self.client=Client()
self.new_user = new_user
self.project = new_project
self.issue = posted_issue
def test_note_create_view_POST_RATE_LIMIT(self):
"""Test rate limit decorators for note crate view."""
url = reverse('create-note', args=[
self.new_user, self.project.slug, self.issue.gitlab_iid])
form_data = {
'body': """A new note body."""
}
form=CreateIssueForm(form_data)
response = run_rate_limit_test(self, self.client, url, form, form_data)
self.assertEqual(response.status_code, 403)
self.assertTemplateUsed('anonticket/rate_limit.html')
def tearDown(self):
"""Clear Cache"""
cache.clear()
@tag('gitlab')
class TestGitlabAccountRequestViews(TestCase):
......
......@@ -127,7 +127,6 @@ USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.1/howto/static-files/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment