Example #1
0
    def test_contract_get_all_no_view_no_projectid_no_owner(self):

        expected_filters = {
            'status': 'random',
            'offer_uuid': 'offeruuid',
        }

        # admin
        expected_filters['project_id'] = admin_ctx_dict['project_id']
        filters = ContractsController._contract_get_all_authorize_filters(
            admin_ctx_dict, status='random', offer_uuid='offeruuid')
        self.assertEqual(expected_filters, filters)

        # owner
        expected_filters['project_id'] = owner_ctx.project_id
        filters = ContractsController._contract_get_all_authorize_filters(
            owner_ctx_dict, status='random', offer_uuid='offeruuid')
        self.assertEqual(expected_filters, filters)

        # lessee
        expected_filters['project_id'] = lessee_ctx.project_id
        filters = ContractsController._contract_get_all_authorize_filters(
            lessee_ctx_dict, status='random', offer_uuid='offeruuid')
        self.assertEqual(expected_filters, filters)

        # random
        self.assertRaises(
            policy.PolicyNotAuthorized,
            ContractsController._contract_get_all_authorize_filters,
            random_ctx_dict,
            status='random',
            offer_uuid='offeruuid')
Example #2
0
    def test__contract_authorize_management_valid_lessee(
            self, mock_authorize, mock_gbu):

        ContractsController._contract_authorize_management(
            test_contract, lessee_ctx.to_policy_values())

        assert not mock_authorize.called
        assert not mock_gbu.called
Example #3
0
    def test_contract_get_all_no_view_project_no_owner(self):

        expected_filters = {'status': ['random']}

        # admin
        expected_filters['project_id'] = admin_ctx_dict['project_id']
        filters = ContractsController._contract_get_all_authorize_filters(
            admin_ctx_dict,
            project_id=admin_ctx_dict['project_id'],
            status='random')
        self.assertEqual(expected_filters, filters)

        expected_filters['project_id'] = random_ctx.project_id
        filters = ContractsController._contract_get_all_authorize_filters(
            admin_ctx_dict, project_id=random_ctx.project_id, status='random')
        self.assertEqual(expected_filters, filters)

        # lessee
        expected_filters['project_id'] = lessee_ctx.project_id
        filters = ContractsController._contract_get_all_authorize_filters(
            lessee_ctx_dict, project_id=lessee_ctx.project_id, status='random')
        self.assertEqual(expected_filters, filters)

        self.assertRaises(
            policy.PolicyNotAuthorized,
            ContractsController._contract_get_all_authorize_filters,
            lessee_ctx_dict,
            project_id=random_ctx.project_id,
            status='random')

        # owner
        expected_filters['project_id'] = owner_ctx.project_id
        filters = ContractsController._contract_get_all_authorize_filters(
            owner_ctx_dict, project_id=owner_ctx.project_id, status='random')
        self.assertEqual(expected_filters, filters)

        self.assertRaises(
            policy.PolicyNotAuthorized,
            ContractsController._contract_get_all_authorize_filters,
            lessee_ctx_dict,
            project_id=random_ctx.project_id,
            status='random')

        # random
        self.assertRaises(
            policy.PolicyNotAuthorized,
            ContractsController._contract_get_all_authorize_filters,
            random_ctx_dict,
            project_id=random_ctx.project_id,
            status='random')
Example #4
0
    def test_contract_get_all_status(self):

        expected_filters = {
            'project_id': 'adminid',
            'status': ['created', 'active']
        }

        # admin
        filters = ContractsController._contract_get_all_authorize_filters(
            admin_ctx_dict)
        self.assertEqual(expected_filters, filters)

        del (expected_filters['status'])
        filters = ContractsController._contract_get_all_authorize_filters(
            admin_ctx_dict, status='any')
        self.assertEqual(expected_filters, filters)
Example #5
0
    def test_contract_get_all_all_view_times(self):

        start = datetime.datetime(2016, 7, 16, 19, 20, 30)
        end = datetime.datetime(2020, 7, 16, 19, 20, 30)

        expected_filters = {
            'status': 'random',
            'start_time': start,
            'end_time': end
        }

        # admin
        filters = ContractsController._contract_get_all_authorize_filters(
            admin_ctx_dict,
            view='all',
            start_time=start,
            end_time=end,
            status='random')
        self.assertEqual(expected_filters, filters)

        self.assertRaises(
            exception.InvalidTimeAPICommand,
            ContractsController._contract_get_all_authorize_filters,
            admin_ctx_dict,
            view='all',
            start_time=start,
            status='random')

        self.assertRaises(
            exception.InvalidTimeAPICommand,
            ContractsController._contract_get_all_authorize_filters,
            admin_ctx_dict,
            view='all',
            end_time=end,
            status='random')
Example #6
0
    def test_contract_get_all_all_view(self):

        expected_filters = {'status': 'random'}

        # admin
        filters = ContractsController._contract_get_all_authorize_filters(
            admin_ctx_dict, view='all', status='random')
        self.assertEqual(expected_filters, filters)

        # not admin
        self.assertRaises(
            policy.PolicyNotAuthorized,
            ContractsController._contract_get_all_authorize_filters,
            lessee_ctx_dict,
            view='all',
            status='random')

        self.assertRaises(
            policy.PolicyNotAuthorized,
            ContractsController._contract_get_all_authorize_filters,
            owner_ctx_dict,
            view='all',
            status='random')

        self.assertRaises(
            policy.PolicyNotAuthorized,
            ContractsController._contract_get_all_authorize_filters,
            random_ctx_dict,
            view='all',
            status='random')
Example #7
0
    def test__contract_authorize_management_valid_owner(
            self, mock_authorize, mock_gbu):

        mock_gbu.return_value = test_offer
        mock_authorize.side_effect = [
            policy.PolicyNotAuthorized('esi_leap:contract:contract_admin',
                                       lessee_ctx.to_policy_values(),
                                       lessee_ctx.to_policy_values()), None
        ]

        ContractsController._contract_authorize_management(
            test_contract, owner_ctx.to_policy_values())

        mock_authorize.assert_called_once_with(
            'esi_leap:contract:contract_admin', owner_ctx.to_policy_values(),
            owner_ctx.to_policy_values())

        mock_gbu.assert_called_with(test_contract.offer_uuid)
Example #8
0
    def test__contract_get_authorized_contract_unique(self, mock_get,
                                                      mock_cam):
        mock_get.return_value = [test_contract, test_contract_3]
        mock_cam.side_effect = [
            None,
            policy.PolicyNotAuthorized('esi_leap:offer:contract_admin',
                                       lessee_ctx.to_policy_values(),
                                       lessee_ctx.to_policy_values())
        ]

        p = ContractsController._contract_get_authorized_contract(
            'c', lessee_ctx.to_policy_values())

        mock_get.assert_called_once_with('c')
        mock_cam.assert_has_calls([
            mock.call(test_contract, lessee_ctx.to_policy_values()),
            mock.call(test_contract_3, lessee_ctx.to_policy_values()),
        ])

        assert p.uuid == test_contract.uuid