Example #1
0
    def _test_auth_review(self, role_class, auth_cache,
                          case_number, person_id, is_admin,
                          reviewer_id, expect_codes):
        proposal_states = ProposalState.get_options()
        self.assertEqual(len(expect_codes), len(proposal_states),
                         'codes for review case {}'.format(case_number))
        reviewer = self.db.search_reviewer(
            reviewer_id=reviewer_id,
            with_review=True).get_single()

        if self.quick_proposal_state:
            proposal_orig = self.db.get_proposal(
                None, reviewer.proposal_id, with_members=True)

        for (state_info, expect_code) in zip(
                proposal_states.items(), expect_codes):
            (state, state_name) = state_info
            expect = self._expect_code('review', case_number, expect_code,
                                       rating=True)

            if self.quick_proposal_state:
                proposal = proposal_orig._replace(state=state)
            else:
                self.db.update_proposal(reviewer.proposal_id, state=state)
                proposal = self.db.get_proposal(
                    None, reviewer.proposal_id, with_members=True)

            with self._as_person(person_id, is_admin):
                self.assertEqual(
                    auth.for_review(role_class, self.db, reviewer, proposal,
                                    auth_cache=auth_cache),
                    expect, 'auth review case {} state {}'.format(
                        case_number, state_name))
Example #2
0
    def _test_auth_proposal(self, role_class, auth_cache,
                            case_number, person_id, is_admin,
                            proposal_id, expect_codes, expect_codes_fb,
                            expect_codes_dec):
        proposal_states = ProposalState.get_options()
        self.assertEqual(len(expect_codes), len(proposal_states),
                         'codes for proposal case {}'.format(case_number))
        self.assertEqual(len(expect_codes_fb), len(proposal_states),
                         'fb codes for proposal case {}'.format(case_number))
        self.assertEqual(len(expect_codes_dec), len(proposal_states),
                         'dec codes for proposal case {}'.format(case_number))

        if self.quick_proposal_state:
            proposal_orig = self.db.get_proposal(
                None, proposal_id, with_members=True, with_reviewers=True)

        for (state_info, expect_code, expect_code_fb, expect_code_dec) in zip(
                proposal_states.items(), expect_codes,
                expect_codes_fb, expect_codes_dec):
            (state, state_name) = state_info
            expect = self._expect_code('proposal', case_number, expect_code)
            expect_fb = self._expect_code('proposal fb', case_number,
                                          expect_code_fb)
            expect_dec = self._expect_code('proposal dec', case_number,
                                           expect_code_dec)

            if self.quick_proposal_state:
                proposal = proposal_orig._replace(state=state)
            else:
                self.db.update_proposal(proposal_id, state=state)
                proposal = self.db.get_proposal(
                    None, proposal_id, with_members=True, with_reviewers=True)

            with self._as_person(person_id, is_admin):
                self.assertEqual(
                    auth.for_proposal(role_class, self.db, proposal,
                                      auth_cache=auth_cache),
                    expect, 'auth proposal case {} state {}'.format(
                        case_number, state_name))
                self.assertEqual(
                    auth.for_proposal_feedback(role_class, self.db, proposal,
                                               auth_cache=auth_cache),
                    expect_fb, 'auth proposal fb case {} state {}'.format(
                        case_number, state_name))
                self.assertEqual(
                    auth.for_proposal_decision(self.db, proposal,
                                               auth_cache=auth_cache),
                    expect_dec, 'auth proposal dec case {} state {}'.format(
                        case_number, state_name))
Example #3
0
    def _test_auth_add_review(self, role_class, auth_cache,
                              case_number, person_id, is_admin,
                              proposal_id, expect_by_state):
        if self.quick_proposal_state:
            proposal_orig = self.db.get_proposal(
                None, proposal_id, with_members=True, with_reviewers=True)

        for (state, state_name) in ProposalState.get_options().items():
            expect = set(expect_by_state.get(state, []))

            if self.quick_proposal_state:
                proposal = proposal_orig._replace(state=state)
            else:
                self.db.update_proposal(proposal_id, state=state)
                proposal = self.db.get_proposal(
                    None, proposal_id, with_members=True, with_reviewers=True)

            with self._as_person(person_id, is_admin):
                self.assertEqual(
                    set(auth.can_add_review_roles(
                        role_class, self.db, proposal, auth_cache=auth_cache)),
                    expect, 'add review case {} state {}'.format(
                        case_number, state_name))
Example #4
0
    def test_proposal_state(self):
        options = ProposalState.get_options()
        self.assertIsInstance(options, OrderedDict)

        states = set()
        for state in (
                ProposalState.PREPARATION,
                ProposalState.SUBMITTED,
                ProposalState.WITHDRAWN,
                ProposalState.REVIEW,
                ProposalState.ACCEPTED,
                ProposalState.REJECTED,
        ):
            # Check state is an integer.
            self.assertIsInstance(state, int)
            self.assertNotIn(state, states)

            # Check state is unique.
            states.add(state)

            # State should be considered valid.
            self.assertTrue(ProposalState.is_valid(state))

            # State should have a name.
            self.assertIsInstance(ProposalState.get_name(state), unicode)

            # State should have boolean "can_edit" property.
            self.assertIn(ProposalState.can_edit(state), (True, False))

            # State should be in the options list.
            self.assertIn(state, options)
            self.assertIsInstance(options[state], unicode)
            self.assertEqual(options[state], ProposalState.get_name(state))

        self.assertFalse(ProposalState.is_valid(999))

        states = ProposalState.editable_states()
        self.assertIsInstance(states, list)
        self.assertIn(ProposalState.PREPARATION, states)
        self.assertNotIn(ProposalState.REVIEW, states)

        states = ProposalState.submitted_states()
        self.assertIsInstance(states, list)
        self.assertNotIn(ProposalState.PREPARATION, states)
        self.assertIn(ProposalState.REVIEW, states)

        states = ProposalState.review_states()
        self.assertIsInstance(states, list)
        self.assertEqual(
            set(states), set(
                (ProposalState.REVIEW, ProposalState.FINAL_REVIEW)))

        states = ProposalState.reviewed_states()
        self.assertIsInstance(states, list)
        self.assertNotIn(ProposalState.PREPARATION, states)
        self.assertNotIn(ProposalState.SUBMITTED, states)
        self.assertNotIn(ProposalState.ABANDONED, states)
        self.assertIn(ProposalState.ACCEPTED, states)
        self.assertIn(ProposalState.REJECTED, states)
        self.assertTrue(ProposalState.is_reviewed(ProposalState.ACCEPTED))
        self.assertTrue(ProposalState.is_reviewed(ProposalState.REJECTED))
        self.assertFalse(ProposalState.is_reviewed(ProposalState.REVIEW))
        self.assertFalse(ProposalState.is_reviewed(ProposalState.ABANDONED))

        self.assertEqual(ProposalState.by_name('accepted'),
                         ProposalState.ACCEPTED)
        with self.assertRaisesRegexp(NoSuchValue, 'not recognised'):
            ProposalState.by_name('not a real state')
Example #5
0
    def test_proposal_state(self):
        options = ProposalState.get_options()
        self.assertIsInstance(options, OrderedDict)

        states = set()
        for state in (
                ProposalState.PREPARATION,
                ProposalState.SUBMITTED,
                ProposalState.WITHDRAWN,
                ProposalState.REVIEW,
                ProposalState.ACCEPTED,
                ProposalState.REJECTED,
                ):
            # Check state is an integer.
            self.assertIsInstance(state, int)
            self.assertNotIn(state, states)

            # Check state is unique.
            states.add(state)

            # State should be considered valid.
            self.assertTrue(ProposalState.is_valid(state))

            # State should have a name.
            self.assertIsInstance(ProposalState.get_name(state), unicode)

            # State should have boolean "can_edit" property.
            self.assertIn(ProposalState.can_edit(state), (True, False))

            # State should be in the options list.
            self.assertIn(state, options)
            self.assertIsInstance(options[state], unicode)
            self.assertEqual(options[state], ProposalState.get_name(state))

        self.assertFalse(ProposalState.is_valid(999))

        states = ProposalState.editable_states()
        self.assertIsInstance(states, list)
        self.assertIn(ProposalState.PREPARATION, states)
        self.assertNotIn(ProposalState.REVIEW, states)

        states = ProposalState.submitted_states()
        self.assertIsInstance(states, list)
        self.assertNotIn(ProposalState.PREPARATION, states)
        self.assertIn(ProposalState.REVIEW, states)

        states = ProposalState.review_states()
        self.assertIsInstance(states, list)
        self.assertEqual(
            set(states),
            set((ProposalState.REVIEW, ProposalState.FINAL_REVIEW)))

        states = ProposalState.reviewed_states()
        self.assertIsInstance(states, list)
        self.assertNotIn(ProposalState.PREPARATION, states)
        self.assertNotIn(ProposalState.SUBMITTED, states)
        self.assertNotIn(ProposalState.ABANDONED, states)
        self.assertIn(ProposalState.ACCEPTED, states)
        self.assertIn(ProposalState.REJECTED, states)
        self.assertTrue(ProposalState.is_reviewed(ProposalState.ACCEPTED))
        self.assertTrue(ProposalState.is_reviewed(ProposalState.REJECTED))
        self.assertFalse(ProposalState.is_reviewed(ProposalState.REVIEW))
        self.assertFalse(ProposalState.is_reviewed(ProposalState.ABANDONED))

        self.assertEqual(ProposalState.by_name('accepted'),
                         ProposalState.ACCEPTED)
        with self.assertRaisesRegexp(NoSuchValue, 'not recognised'):
            ProposalState.by_name('not a real state')