Skip to content

Commit

Permalink
Added tests for JSON views
Browse files Browse the repository at this point in the history
  • Loading branch information
n.lyubchich committed Aug 17, 2015
1 parent f6659c4 commit 80cf1bc
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion project/tests/test_admin.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import json
from unittest.mock import Mock
from flask import url_for
from project.admin.utils import EntryList
from project.admin.views import SECTIONS, mainpage
from project.models import PageBlock, Page
from project.tests.utils import ProjectTestCase


Expand Down Expand Up @@ -49,7 +51,6 @@ class MainPageTest(ProjectTestCase):
def setUp(self):
self.view = mainpage
self.view()
# self.response = self.client.get("/admin/")

def test_view_uses_correct_template(self):
self.assertTemplateUsed("admin/main.html")
Expand All @@ -65,3 +66,29 @@ def test_all_endpoints_can_be_resolved(self):
expected_sections[name],
url_for("admin." + SECTIONS[name])
)


class VacancyAuxilliarTest(ProjectTestCase):
def test_avail_block_view_returns_correct_value(self):
self.log_in()
pageblocks = [{"label": str(block), "value": str(block.id)}
for block in PageBlock.query.all()]
url = url_for('admin.available_blocks')
response = self.client.get(url, follow_redirects=True)
expected = bytes(
json.dumps({"blocks": pageblocks}, sort_keys=True),
encoding='utf8',
)
self.assertEqual(expected, response.data)

def test_chosen_block_view_returns_correct_value(self):
self.log_in()
for page in Page.query.all():
blocks = [str(block.id) for block in page.blocks]
url = url_for('admin.block_list', entry_id=page.id)
response = self.client.get(url, follow_redirects=True)
expected = bytes(
json.dumps({"entries": blocks}, sort_keys=True),
encoding='utf8',
)
self.assertEqual(expected, response.data)

0 comments on commit 80cf1bc

Please sign in to comment.