Example #1
0
 def test_flagged_view(self):
     request = self.mk_request()
     objects_to_flag = [
         {
             'obj': save_valid_submission(),
             'flag_type': 'notworking',
             'explanation': 'I am not good at computer.'
         },
         {
             'obj': Document.objects.get(pk=4),
             'flag_type': 'bad',
             'explanation': 'This is in fact not a pipe.'
         },
         {
             'obj': Document.objects.get(pk=8),
             'flag_type': 'unneeded',
             'explanation': 'Camels are for Perl, not Python.'
         },
     ]
     for o in objects_to_flag:
         flag, created = ContentFlag.objects.flag(
             request=request,
             object=o['obj'],
             flag_type=o['flag_type'],
             explanation=o['explanation'])
     resp = self.client.get(reverse('contentflagging.flagged'))
     eq_(200, resp.status_code)
Example #2
0
    def test_flag_dict(self):
        request = _mock_request()
        objects_to_flag = [
            {'obj': save_valid_submission(),
             'flag_type': 'notworking',
             'explanation': 'I am not good at computer.'},
            {'obj': Document.objects.get(pk=4),
             'flag_type': 'bad',
             'explanation': 'This is in fact not a pipe.'},
            {'obj': Document.objects.get(pk=8),
             'flag_type': 'unneeded',
             'explanation': 'Camels are for Perl, not Python.'},
        ]
        for o in objects_to_flag:
            flag, created = ContentFlag.objects.flag(
                request=request, object=o['obj'], flag_type=o['flag_type'],
                explanation=o['explanation'])
        flag_dict = ContentFlag.objects.flags_by_type()

        # These are translation proxy objects, not strings, so we have
        # to pull them off the model class.
        sub = Submission._meta.verbose_name_plural
        doc = Document._meta.verbose_name_plural

        ok_(sub in flag_dict)
        eq_(1, len(flag_dict[sub]))
        eq_('hello world',
            flag_dict[sub][0].content_object.title)

        ok_(doc in flag_dict)
        eq_(2, len(flag_dict[doc]))
        eq_('le title',
            flag_dict[doc][0].content_object.title)
        eq_('getElementByID',
            flag_dict[doc][1].content_object.title)