<commit_before>import mock

from django import test
from django.conf import settings

from model_mommy import mommy

from devilry.devilry_group.cradmin_instances import crinstance_examiner


class TestCrinstanceExaminer(test.TestCase):

    def test_get_rolequeryset_no_assignmentgroups_where_period_is_inactive_old(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        testassignment = mommy.make_recipe('devilry.apps.core.assignment_oldperiod_end')
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup__parentnode=testassignment,)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertEquals(0, crinstance.get_rolequeryset().count())

    def test_get_rolequeryset_one_assignmentgroup(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup__parentnode=mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start'),)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertEquals(1, crinstance.get_rolequeryset().count())

    def test_get_rolequeryset_multiple_assignmentgroups(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup__parentnode=mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start'),)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup__parentnode=mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start'),)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup__parentnode=mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start'),)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertEquals(3, crinstance.get_rolequeryset().count())

    def test_get_rolequeryset_has_access_to_feedbackset(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start')
        testgroup = mommy.make('core.AssignmentGroup',
                               parentnode=testassignment)
        feedbackset = mommy.make('devilry_group.FeedbackSet',
                                 group=testgroup)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup=testgroup,)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertEquals(feedbackset, crinstance.get_rolequeryset()[0].feedbackset_set.all()[0])

    def test_get_rolequeryset_does_not_have_access_to_feedbackset(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start')
        testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment)
        unrelated_feedbackset = mommy.make('devilry_group.FeedbackSet')
        mommy.make('devilry_group.FeedbackSet',
                   group=testgroup)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup=testgroup,)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertNotEqual(unrelated_feedbackset, crinstance.get_rolequeryset()[0].feedbackset_set.all()[0])

    def test_get_rolequeryset_access_to_multiple_assignment_groups_in_assignment(self):<commit_msg>devilry_group/test/test_crinstance_examiner.py: added test for instance class.<commit_after>import mock

from django import test
from django.conf import settings

from model_mommy import mommy

from devilry.devilry_group.cradmin_instances import crinstance_examiner


class TestCrinstanceExaminer(test.TestCase):

    def test_get_titletext_for_role(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        testgroup = mommy.make('core.AssignmentGroup',
                               parentnode__parentnode__parentnode__short_name='s1',
                               parentnode__parentnode__short_name='p1',
                               parentnode__short_name='a1')
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup=testgroup)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertEqual('s1.p1 - a1', crinstance.get_titletext_for_role(testgroup))

    def test_get_rolequeryset_no_assignmentgroups_where_period_is_inactive_old(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        testassignment = mommy.make_recipe('devilry.apps.core.assignment_oldperiod_end')
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup__parentnode=testassignment,)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertEquals(0, crinstance.get_rolequeryset().count())

    def test_get_rolequeryset_one_assignmentgroup(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup__parentnode=mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start'),)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertEquals(1, crinstance.get_rolequeryset().count())

    def test_get_rolequeryset_multiple_assignmentgroups(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup__parentnode=mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start'),)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup__parentnode=mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start'),)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup__parentnode=mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start'),)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertEquals(3, crinstance.get_rolequeryset().count())

    def test_get_rolequeryset_has_access_to_feedbackset(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start')
        testgroup = mommy.make('core.AssignmentGroup',
                               parentnode=testassignment)
        feedbackset = mommy.make('devilry_group.FeedbackSet',
                                 group=testgroup)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup=testgroup,)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertEquals(feedbackset, crinstance.get_rolequeryset()[0].feedbackset_set.all()[0])

    def test_get_rolequeryset_does_not_have_access_to_feedbackset(self):
        testuser = mommy.make(settings.AUTH_USER_MODEL)
        testassignment = mommy.make_recipe('devilry.apps.core.assignment_activeperiod_start')
        testgroup = mommy.make('core.AssignmentGroup', parentnode=testassignment)
        unrelated_feedbackset = mommy.make('devilry_group.FeedbackSet')
        mommy.make('devilry_group.FeedbackSet',
                   group=testgroup)
        mommy.make('core.Examiner',
                   relatedexaminer__user=testuser,
                   assignmentgroup=testgroup,)
        mockrequest = mock.MagicMock()
        mockrequest.user = testuser
        crinstance = crinstance_examiner.ExaminerCrInstance(request=mockrequest)
        self.assertEqual(1, len(crinstance.get_rolequeryset()[0].feedbackset_set.all()))
        self.assertNotIn(unrelated_feedbackset, crinstance.get_rolequeryset()[0].feedbackset_set.all())

    def test_get_rolequeryset_access_to_multiple_assignment_groups_in_assignment(self):
{'fraction_non_alphanumeric': 0.08394280100425718, 'fraction_numerical': 0.0022923261652658005, 'mean_word_length': 3.249536178107607, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5107380', 'n_tokens_mistral': 2718, 'n_tokens_neox': 2652, 'n_words': 271}