class TestDistributionOrProductOrProjectGroupVocabulary(TestCaseWithFactory, VocabFilterMixin):
    """Test for DistributionOrProductOrProjectGroupVocabulary."""

    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestDistributionOrProductOrProjectGroupVocabulary, self).setUp()
        self.vocabulary = DistributionOrProductOrProjectGroupVocabulary()
        self.product = self.factory.makeProduct(name="orchid-snark")
        self.distribution = self.factory.makeDistribution(name="zebra-snark")
        self.project_group = self.factory.makeProject(name="apple-snark")

    def test_supported_filters(self):
        # The vocab supports the correct filters.
        self.assertEqual(
            [
                DistributionOrProductOrProjectGroupVocabulary.ALL_FILTER,
                DistributionOrProductOrProjectGroupVocabulary.PROJECT_FILTER,
                DistributionOrProductOrProjectGroupVocabulary.PROJECTGROUP_FILTER,
                DistributionOrProductOrProjectGroupVocabulary.DISTRO_FILTER,
            ],
            self.vocabulary.supportedFilters(),
        )

    def test_project_filter(self):
        self._test_project_filter()

    def test_projectgroup_filter(self):
        self._test_projectgroup_filter()

    def test_distribution_filter(self):
        self._test_distribution_filter()

    def test_contains_all_pillars_active(self):
        # All active products, project groups and distributions are included.
        self.assertTrue(self.product in self.vocabulary)
        self.assertTrue(self.distribution in self.vocabulary)
        self.assertTrue(self.project_group in self.vocabulary)

    def test_inactive_products_are_excluded(self):
        # Inactive product are not in the vocabulary.
        with celebrity_logged_in("registry_experts"):
            self.product.active = False
        terms = self.vocabulary.searchForTerms("snark")
        result = [term.value for term in terms]
        self.assertEqual([self.project_group, self.distribution], result)
        self.assertFalse(self.product in self.vocabulary)

    def test_inactive_product_groups_are_excluded(self):
        # Inactive project groups are not in the vocabulary.
        with celebrity_logged_in("registry_experts"):
            self.project_group.active = False
        terms = self.vocabulary.searchForTerms("snark")
        result = [term.value for term in terms]
        self.assertEqual([self.product, self.distribution], result)
        self.assertFalse(self.project_group in self.vocabulary)
class TestDistributionOrProductOrProjectGroupVocabulary(
        TestCaseWithFactory, VocabFilterMixin):
    """Test for DistributionOrProductOrProjectGroupVocabulary."""
    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestDistributionOrProductOrProjectGroupVocabulary, self).setUp()
        self.vocabulary = DistributionOrProductOrProjectGroupVocabulary()
        self.product = self.factory.makeProduct(name='orchid-snark')
        self.distribution = self.factory.makeDistribution(name='zebra-snark')
        self.project_group = self.factory.makeProject(name='apple-snark')

    def test_supported_filters(self):
        # The vocab supports the correct filters.
        self.assertEqual([
            DistributionOrProductOrProjectGroupVocabulary.ALL_FILTER,
            DistributionOrProductOrProjectGroupVocabulary.PROJECT_FILTER,
            DistributionOrProductOrProjectGroupVocabulary.PROJECTGROUP_FILTER,
            DistributionOrProductOrProjectGroupVocabulary.DISTRO_FILTER,
        ], self.vocabulary.supportedFilters())

    def test_project_filter(self):
        self._test_project_filter()

    def test_projectgroup_filter(self):
        self._test_projectgroup_filter()

    def test_distribution_filter(self):
        self._test_distribution_filter()

    def test_contains_all_pillars_active(self):
        # All active products, project groups and distributions are included.
        self.assertTrue(self.product in self.vocabulary)
        self.assertTrue(self.distribution in self.vocabulary)
        self.assertTrue(self.project_group in self.vocabulary)

    def test_inactive_products_are_excluded(self):
        # Inactive product are not in the vocabulary.
        with celebrity_logged_in('registry_experts'):
            self.product.active = False
        terms = self.vocabulary.searchForTerms('snark')
        result = [term.value for term in terms]
        self.assertEqual([self.project_group, self.distribution], result)
        self.assertFalse(self.product in self.vocabulary)

    def test_inactive_product_groups_are_excluded(self):
        # Inactive project groups are not in the vocabulary.
        with celebrity_logged_in('registry_experts'):
            self.project_group.active = False
        terms = self.vocabulary.searchForTerms('snark')
        result = [term.value for term in terms]
        self.assertEqual([self.product, self.distribution], result)
        self.assertFalse(self.project_group in self.vocabulary)
 def setUp(self):
     super(TestDistributionOrProductOrProjectGroupVocabulary, self).setUp()
     self.vocabulary = DistributionOrProductOrProjectGroupVocabulary()
     self.product = self.factory.makeProduct(name="orchid-snark")
     self.distribution = self.factory.makeDistribution(name="zebra-snark")
     self.project_group = self.factory.makeProject(name="apple-snark")
 def setUp(self):
     super(TestDistributionOrProductOrProjectGroupVocabulary, self).setUp()
     self.vocabulary = DistributionOrProductOrProjectGroupVocabulary()
     self.product = self.factory.makeProduct(name='orchid-snark')
     self.distribution = self.factory.makeDistribution(name='zebra-snark')
     self.project_group = self.factory.makeProject(name='apple-snark')
class TestDistributionOrProductOrProjectGroupVocabulary(TestCaseWithFactory,
                                                        VocabFilterMixin):
    """Test for DistributionOrProductOrProjectGroupVocabulary."""
    layer = DatabaseFunctionalLayer

    def setUp(self):
        super(TestDistributionOrProductOrProjectGroupVocabulary, self).setUp()
        self.vocabulary = DistributionOrProductOrProjectGroupVocabulary()
        self.product = self.factory.makeProduct(name='orchid-snark')
        self.distribution = self.factory.makeDistribution(name='zebra-snark')
        self.project_group = self.factory.makeProject(name='apple-snark')

    def test_supported_filters(self):
        # The vocab supports the correct filters.
        self.assertEqual([
            DistributionOrProductOrProjectGroupVocabulary.ALL_FILTER,
            DistributionOrProductOrProjectGroupVocabulary.PROJECT_FILTER,
            DistributionOrProductOrProjectGroupVocabulary.PROJECTGROUP_FILTER,
            DistributionOrProductOrProjectGroupVocabulary.DISTRO_FILTER,
            ],
            self.vocabulary.supportedFilters()
        )

    def test_project_filter(self):
        self._test_project_filter()

    def test_projectgroup_filter(self):
        self._test_projectgroup_filter()

    def test_distribution_filter(self):
        self._test_distribution_filter()

    def test_contains_all_pillars_active(self):
        # All active products, project groups and distributions are included.
        self.assertTrue(self.product in self.vocabulary)
        self.assertTrue(self.distribution in self.vocabulary)
        self.assertTrue(self.project_group in self.vocabulary)

    def test_inactive_products_are_excluded(self):
        # Inactive product are not in the vocabulary.
        with celebrity_logged_in('registry_experts'):
            self.product.active = False
        terms = self.vocabulary.searchForTerms('snark')
        result = [term.value for term in terms]
        self.assertEqual([self.project_group, self.distribution], result)
        self.assertFalse(self.product in self.vocabulary)

    def test_inactive_product_groups_are_excluded(self):
        # Inactive project groups are not in the vocabulary.
        with celebrity_logged_in('registry_experts'):
            self.project_group.active = False
        terms = self.vocabulary.searchForTerms('snark')
        result = [term.value for term in terms]
        self.assertEqual([self.product, self.distribution], result)
        self.assertFalse(self.project_group in self.vocabulary)

    def test_invisible_private_projects_are_excluded(self):
        with admin_logged_in():
            owner = self.factory.makePerson()
            private = self.factory.makeProduct(
                name="private-snark", owner=owner,
                information_type=InformationType.PROPRIETARY)

        # Anonymous users don't get the private project.
        terms = self.vocabulary.searchForTerms('snark')
        result = [term.value for term in terms]
        self.assertNotIn(private, result)

        # But the owner can see it.
        login_person(owner)
        terms = self.vocabulary.searchForTerms('snark')
        result = [term.value for term in terms]
        self.assertIn(private, result)