def test_page_template(self): one = 'template one' two = 'template two' three = 'template three' four = 'template four' page = factories.PageFactory() # Row 1 row = factories.RowFactory() search_filter_block = factories.SearchFilterBlockFactory(template=one) breadbox_block = factories.BreadboxBlockFactory(template=two) models.BlockOrder.objects.create(block=search_filter_block, row=row, order=1) models.BlockOrder.objects.create(block=breadbox_block, row=row, order=2) models.RowOrder.objects.create(page=page, row=row, order=1) # Row 2 row = factories.RowFactory() search_filter_block = factories.SearchFilterBlockFactory(template=three) breadbox_block = factories.BreadboxBlockFactory(template=four) models.BlockOrder.objects.create(block=search_filter_block, row=row, order=1) models.BlockOrder.objects.create(block=breadbox_block, row=row, order=2) models.RowOrder.objects.create(page=page, row=row, order=2) # Confirm that both templates are joined together in the correct order template = page.get_template(self.search_results_request) pattern = '.*%s.*%s.*%s.*%s.*' % (one, two, three, four) self.assertRegexpMatches(template, pattern) # Try a new order. page = factories.PageFactory() # Row 1 row = factories.RowFactory() search_filter_block = factories.SearchFilterBlockFactory(template=one) breadbox_block = factories.BreadboxBlockFactory(template=two) models.BlockOrder.objects.create(block=search_filter_block, row=row, order=2) models.BlockOrder.objects.create(block=breadbox_block, row=row, order=1) models.RowOrder.objects.create(page=page, row=row, order=1) # Row 2 row = factories.RowFactory() search_filter_block = factories.SearchFilterBlockFactory(template=three) breadbox_block = factories.BreadboxBlockFactory(template=four) models.BlockOrder.objects.create(block=search_filter_block, row=row, order=2) models.BlockOrder.objects.create(block=breadbox_block, row=row, order=1) models.RowOrder.objects.create(page=page, row=row, order=2) # Confirm that both templates are joined together in the correct order template = page.get_template(self.search_results_request) pattern = '.*%s.*%s.*%s.*%s.*' % (two, one, four, three) self.assertRegexpMatches(template, pattern)
def test_column_block_template(self): one = 'template one' two = 'template two' column_block = factories.ColumnBlockFactory() search_filter_block = factories.SearchFilterBlockFactory(template=one) breadbox_block = factories.BreadboxBlockFactory(template=two) models.ColumnBlockOrder.objects.create(block=search_filter_block, column_block=column_block, order=1) models.ColumnBlockOrder.objects.create(block=breadbox_block, column_block=column_block, order=2) # Confirm that both templates are joined together in the correct order template = column_block.get_template() self.assertRegexpMatches(template, '.*%s.*%s.*' % (one, two)) # Try a new order. reverse_column_block = factories.ColumnBlockFactory() models.ColumnBlockOrder.objects.create(block=search_filter_block, column_block=reverse_column_block, order=2) models.ColumnBlockOrder.objects.create(block=breadbox_block, column_block=reverse_column_block, order=1) # Confirm that both templates are again joined in the correct order. template = reverse_column_block.get_template() self.assertRegexpMatches(template, '.*%s.*%s.*' % (two, one))
def test_row_required_js(self): row = factories.RowFactory() search_filter_block = factories.SearchFilterBlockFactory() breadbox_block = factories.BreadboxBlockFactory() models.BlockOrder.objects.create(block=search_filter_block, row=row, order=1) models.BlockOrder.objects.create(block=breadbox_block, row=row, order=2) models.BlockOrder.objects.create(block=search_filter_block, row=row, order=3) js = row.required_js() # Only SearchFilterBlock has expected js, and that js should be # included only once. search_filter_block_js = search_filter_block.required_js() self.assertEqual(len(js), len(search_filter_block_js)) self.assertEqual(search_filter_block_js, js)
def test_row_context(self): row = factories.RowFactory() search_filter_block = factories.SearchFilterBlockFactory() breadbox_block = factories.BreadboxBlockFactory() models.BlockOrder.objects.create(block=search_filter_block, row=row, order=1) models.BlockOrder.objects.create(block=breadbox_block, row=row, order=2) context = row.context(self.search_results_request) keys = context.keys() # The context should contain the required context for both # blocks. expected_context = ['widgets', 'breadbox'] for field in expected_context: self.assertIn(field, keys) self.assertIsNotNone(context[field])
def test_page_context(self): row = factories.RowFactory() search_filter_block = factories.SearchFilterBlockFactory() breadbox_block = factories.BreadboxBlockFactory() models.BlockOrder.objects.create(block=search_filter_block, row=row, order=1) models.BlockOrder.objects.create(block=breadbox_block, row=row, order=2) page = factories.PageFactory() models.RowOrder.objects.create(page=page, row=row, order=1) context = page.context(self.search_results_request) keys = context.keys() expected_context = ['widgets', 'breadbox', 'site_description', 'site_title'] for field in expected_context: self.assertIn(field, keys)
def test_page_get_head(self): one = 'head 1' two = 'head 2' three = 'head 3' row = factories.RowFactory() search_filter_block = factories.SearchFilterBlockFactory(head=one) breadbox_block = factories.BreadboxBlockFactory(head=two) models.BlockOrder.objects.create(block=search_filter_block, row=row, order=1) models.BlockOrder.objects.create(block=breadbox_block, row=row, order=2) page = factories.PageFactory(head=three) models.RowOrder.objects.create(page=page, row=row, order=1) head = page.get_head() self.assertRegexpMatches(head, '.*%s.*%s.*%s.*' % (one, two, three)) for js in search_filter_block.required_js(): self.assertIn(js, head)
def test_search_filter_context(self): search_filter_block = factories.SearchFilterBlockFactory() context = search_filter_block.context(self.search_results_request) self.assertIsNotNone(context['widgets'])