Created test for get_sections().
This commit is contained in:
parent
661731a914
commit
f20e034897
1 changed files with 54 additions and 0 deletions
|
@ -5,6 +5,7 @@ from users.models import CustomUser
|
||||||
from unittest.mock import MagicMock, Mock, patch
|
from unittest.mock import MagicMock, Mock, patch
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from backend.views import *
|
from backend.views import *
|
||||||
|
from .policy import pol
|
||||||
import json
|
import json
|
||||||
|
|
||||||
class BackendTests(TestCase):
|
class BackendTests(TestCase):
|
||||||
|
@ -249,6 +250,59 @@ class BackendTests(TestCase):
|
||||||
# Section-related Tests
|
# Section-related Tests
|
||||||
#######################
|
#######################
|
||||||
|
|
||||||
|
@patch('backend.views.get_fields', Mock(return_value={}))
|
||||||
|
def test_get_sections(self):
|
||||||
|
"""
|
||||||
|
Test gettings sections for a report.
|
||||||
|
"""
|
||||||
|
report = Report.objects.create(
|
||||||
|
user_id=self.test_user_1,
|
||||||
|
title="Report Title",
|
||||||
|
date_created=timezone.now(),
|
||||||
|
reference_number="1234"
|
||||||
|
)
|
||||||
|
report.save()
|
||||||
|
section_0 = Section.objects.create(
|
||||||
|
report_id=report,
|
||||||
|
auto_submit=False,
|
||||||
|
required=False,
|
||||||
|
completed=False,
|
||||||
|
title='Section Zero',
|
||||||
|
html_description='<p>Description zero</p>',
|
||||||
|
number=0
|
||||||
|
)
|
||||||
|
section_0.save()
|
||||||
|
section_1 = Section.objects.create(
|
||||||
|
report_id=report,
|
||||||
|
auto_submit=False,
|
||||||
|
required=False,
|
||||||
|
completed=False,
|
||||||
|
title='Section One',
|
||||||
|
html_description='<p>Description one</p>',
|
||||||
|
number=1
|
||||||
|
)
|
||||||
|
section_1.save()
|
||||||
|
expected = {
|
||||||
|
'sections': [
|
||||||
|
{
|
||||||
|
'completed': False,
|
||||||
|
'html_description': '<p>Description zero</p>',
|
||||||
|
'id': 1,
|
||||||
|
'rule_violations': [],
|
||||||
|
'title': 'Section Zero'
|
||||||
|
},
|
||||||
|
{
|
||||||
|
'completed': False,
|
||||||
|
'html_description': '<p>Description one</p>',
|
||||||
|
'id': 2,
|
||||||
|
'rule_violations': [],
|
||||||
|
'title': 'Section One'
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
result = get_sections(1)
|
||||||
|
self.assertEqual(expected, result)
|
||||||
|
|
||||||
def test_user_owns_section_true(self):
|
def test_user_owns_section_true(self):
|
||||||
"""
|
"""
|
||||||
Test when a user owns a section
|
Test when a user owns a section
|
||||||
|
|
Loading…
Reference in a new issue