class FilterableListRelationsTestCase(TestCase):
    def setUp(self):
        self.filter_controls = filter_controls

        self.filterable_page = BrowseFilterablePage(title="Blog", slug="test")
        self.root = Site.objects.get(is_default_site=True).root_page
        self.root.add_child(instance=self.filterable_page)

        self.set_filterable_controls(filter_controls)

        self.child_page = BlogPage(title="Child test page", live=True)
        self.sibling_page = BlogPage(title="Sibling test page", live=True)
        self.archived_sibling_page = BlogPage(title="Archive test page",
                                              live=True,
                                              is_archived='yes')
        self.filterable_page.add_child(instance=self.child_page)
        self.filterable_page.get_parent().add_child(instance=self.sibling_page)
        self.filterable_page.get_parent().add_child(
            instance=self.archived_sibling_page)

    def set_filterable_controls(self, value):
        self.filterable_page.content = StreamValue(
            self.filterable_page.content.stream_block, [value], True)
        self.filterable_page.save()

    def test_get_filterable_children_pages(self):
        filter_controls['value']['filter_children'] = True
        filter_controls['value']['filter_siblings'] = False
        self.set_filterable_controls(self.filter_controls)

        qs = self.filterable_page.get_filterable_queryset()
        self.assertEqual(qs.count(), 1)
        self.assertEqual(qs[0].pk, self.child_page.pk)

    def test_get_filterable_siblings_pages(self):
        filter_controls['value']['filter_children'] = False
        filter_controls['value']['filter_siblings'] = True
        self.set_filterable_controls(self.filter_controls)

        qs = self.filterable_page.get_filterable_queryset()
        self.assertEqual(qs.count(), 2)
        self.assertEqual(qs[0].pk, self.sibling_page.pk)

    def test_get_filterable_root_siblings(self):
        filter_controls['value']['filter_children'] = False
        filter_controls['value']['filter_siblings'] = True
        self.set_filterable_controls(self.filter_controls)

        root = self.filterable_page.get_filterable_root()
        self.assertEqual("/", root)

    def test_get_filterable_root_site_wide(self):
        filter_controls['value']['filter_children'] = False
        filter_controls['value']['filter_siblings'] = False
        self.set_filterable_controls(self.filter_controls)

        root = self.filterable_page.get_filterable_root()
        self.assertEqual("/", root)
class TestSocialSharingImage(TestCase):
    def setUp(self):
        self.page = BrowseFilterablePage(
            title='Browse Filterable Page',
            slug='browse-filterable-page',
        )
        save_new_page(self.page)

    def test_validation_error_thrown_if_width_height_too_large(self):
        self.page.social_sharing_image = mommy.prepare(CFGOVImage, width=5000, height=5000)
        with self.assertRaisesRegexp(
            ValidationError,
            'Social sharing image must be less than 4096w x 4096h'
        ):
            self.page.save()

    def test_validation_error_thrown_if_width_too_large(self):
        self.page.social_sharing_image = mommy.prepare(CFGOVImage, width=4097, height=1500)
        with self.assertRaisesRegexp(
            ValidationError,
            'Social sharing image must be less than 4096w x 4096h'
        ):
            self.page.save()

    def test_validation_error_thrown_if_height_too_large(self):
        self.page.social_sharing_image = mommy.prepare(CFGOVImage, width=1500, height=4097)
        with self.assertRaisesRegexp(
            ValidationError,
            'Social sharing image must be less than 4096w x 4096h'
        ):
            self.page.save()
class TestSocialSharingImage(TestCase):
    def setUp(self):
        self.page = BrowseFilterablePage(
            title='Browse Filterable Page',
            slug='browse-filterable-page',
        )
        save_new_page(self.page)

    def test_validation_error_thrown_if_width_height_too_large(self):
        self.page.social_sharing_image = baker.prepare(CFGOVImage,
                                                       width=5000,
                                                       height=5000)
        with self.assertRaisesRegexp(
                ValidationError,
                'Social sharing image must be less than 4096w x 4096h'):
            self.page.save()

    def test_validation_error_thrown_if_width_too_large(self):
        self.page.social_sharing_image = baker.prepare(CFGOVImage,
                                                       width=4097,
                                                       height=1500)
        with self.assertRaisesRegexp(
                ValidationError,
                'Social sharing image must be less than 4096w x 4096h'):
            self.page.save()

    def test_validation_error_thrown_if_height_too_large(self):
        self.page.social_sharing_image = baker.prepare(CFGOVImage,
                                                       width=1500,
                                                       height=4097)
        with self.assertRaisesRegexp(
                ValidationError,
                'Social sharing image must be less than 4096w x 4096h'):
            self.page.save()