def test_asrsnippet(self):

        nightly_snippets = ASRSnippetFactory.create_batch(
            2, targets=[TargetFactory(on_release=False, on_nightly=True)])
        ASRSnippetFactory.create_batch(2, targets=[TargetFactory(on_release=False, on_beta=True)])

        filtr = ChannelFilter(None, {'channel': 'on_nightly'}, ASRSnippet, ASRSnippetAdmin)
        result = filtr.queryset(None, ASRSnippet.objects.all())

        self.assertTrue(result.count(), 2)
        self.assertEqual(set(result.all()), set(nightly_snippets))
예제 #2
0
    def test_asrsnippet(self):

        nightly_snippets = ASRSnippetFactory.create_batch(
            2, targets=[TargetFactory(on_release=False, on_nightly=True)])
        ASRSnippetFactory.create_batch(
            2, targets=[TargetFactory(on_release=False, on_beta=True)])

        filtr = ChannelFilter(None, {'channel': 'on_nightly'}, ASRSnippet,
                              ASRSnippetAdmin)
        result = filtr.queryset(None, ASRSnippet.objects.all())

        self.assertTrue(result.count(), 2)
        self.assertEqual(set(result.all()), set(nightly_snippets))
예제 #3
0
    def test_get_queryset(self):
        snippets = ASRSnippetFactory.create_batch(2)
        qa_snippets = ASRSnippetFactory.create_batch(2, for_qa=True)
        request = self.factory.get('/')
        admin = ASRSnippetAdmin(ASRSnippet, AdminSite())

        # Not Super User
        request.user = UserFactory(is_superuser=False)
        queryset = admin.get_queryset(request)
        self.assertEqual(set(snippets), set(queryset.all()))

        # SuperUser
        request.user = UserFactory(is_superuser=True)
        queryset = admin.get_queryset(request)

        self.assertEqual(set(snippets + qa_snippets), set(queryset.all()))
예제 #4
0
    def test_get_queryset(self):
        snippets = ASRSnippetFactory.create_batch(2)
        qa_snippets = ASRSnippetFactory.create_batch(2, for_qa=True)
        request = self.factory.get('/')
        admin = ASRSnippetAdmin(ASRSnippet, AdminSite())

        # Not Super User
        request.user = UserFactory(is_superuser=False)
        queryset = admin.get_queryset(request)
        self.assertEqual(set(snippets), set(queryset.all()))

        # SuperUser
        request.user = UserFactory(is_superuser=True)
        queryset = admin.get_queryset(request)

        self.assertEqual(set(snippets + qa_snippets), set(queryset.all()))
예제 #5
0
 def test_base(self):
     snippet1, snippet2 = ASRSnippetFactory.create_batch(2)
     snippet3 = ASRSnippetFactory.create(publish_start=datetime(2019, 1, 1))
     snippet4 = ASRSnippetFactory.create(publish_end=datetime(2019, 2, 2))
     filtr = ASRSnippetFilter(QueryDict(),
                              queryset=models.ASRSnippet.objects.all())
     self.assertEqual(set([snippet1, snippet2, snippet3, snippet4]),
                      set(filtr.qs))
예제 #6
0
    def test_make_published(self):
        to_be_published = ASRSnippetFactory.create_batch(2, status=STATUS_CHOICES['Draft'])
        already_published = ASRSnippetFactory(status=STATUS_CHOICES['Published'])
        ASRSnippetFactory.create_batch(2, status=STATUS_CHOICES['Draft'])

        queryset = ASRSnippet.objects.filter(id__in=[
            to_be_published[0].id,
            to_be_published[1].id,
            already_published.id
        ])

        with patch('snippets.base.admin.adminmodels.messages.warning') as warning:
            with patch('snippets.base.admin.adminmodels.messages.success') as success:
                ASRSnippetAdmin(ASRSnippet, None).make_published(None, queryset)

        self.assertEqual(
            set(ASRSnippet.objects.filter(status=STATUS_CHOICES['Published'])),
            set(to_be_published + [already_published])
        )
        self.assertTrue(warning.called)
        self.assertTrue(success.called)
예제 #7
0
    def test_make_published(self):
        to_be_published = ASRSnippetFactory.create_batch(
            2, status=STATUS_CHOICES['Draft'])
        already_published = ASRSnippetFactory(
            status=STATUS_CHOICES['Published'])
        ASRSnippetFactory.create_batch(2, status=STATUS_CHOICES['Draft'])

        queryset = ASRSnippet.objects.filter(id__in=[
            to_be_published[0].id, to_be_published[1].id, already_published.id
        ])

        with patch(
                'snippets.base.admin.adminmodels.messages.warning') as warning:
            with patch('snippets.base.admin.adminmodels.messages.success'
                       ) as success:
                ASRSnippetAdmin(ASRSnippet,
                                None).make_published(None, queryset)

        self.assertEqual(
            set(ASRSnippet.objects.filter(status=STATUS_CHOICES['Published'])),
            set(to_be_published + [already_published]))
        self.assertTrue(warning.called)
        self.assertTrue(success.called)
예제 #8
0
 def test_only_scheduled_all(self):
     snippet1, snippet2 = ASRSnippetFactory.create_batch(2)
     snippet3 = ASRSnippetFactory.create(publish_end=datetime(2019, 2, 2))
     filtr = ASRSnippetFilter(QueryDict(query_string='only_scheduled=all'),
                              queryset=models.ASRSnippet.objects.all())
     self.assertEqual(set([snippet1, snippet2, snippet3]), set(filtr.qs))
예제 #9
0
 def setUp(self):
     self.snippet1, self.snippet2 = ASRSnippetFactory.create_batch(2)
예제 #10
0
 def test_only_scheduled_all(self):
     snippet1, snippet2 = ASRSnippetFactory.create_batch(2)
     snippet3 = ASRSnippetFactory.create(publish_end=datetime(2019, 2, 2))
     filtr = ASRSnippetFilter(QueryDict(query_string='only_scheduled=all'),
                              queryset=models.ASRSnippet.objects.all())
     self.assertEqual(set([snippet1, snippet2, snippet3]), set(filtr.qs))
예제 #11
0
 def test_base(self):
     snippet1, snippet2 = ASRSnippetFactory.create_batch(2)
     snippet3 = ASRSnippetFactory.create(publish_start=datetime(2019, 1, 1))
     snippet4 = ASRSnippetFactory.create(publish_end=datetime(2019, 2, 2))
     filtr = ASRSnippetFilter(QueryDict(), queryset=models.ASRSnippet.objects.all())
     self.assertEqual(set([snippet1, snippet2, snippet3, snippet4]), set(filtr.qs))