Пример #1
0
    def setUp(self):
        global customer

        FunctionalTest.setUp(self)
        customer_logic.DataManager = get_mock_datamanager
        customer_logic.pecan = mock.MagicMock()

        customer_logic.utils = mock.MagicMock()
        customer_logic.utils.make_transid.return_value = 'some_trans_id'
        customer_logic.utils.audit_trail.return_value = None
        customer_logic.utils.make_uuid.return_value = 'some_uuid'
        customer_logic.utils.get_time_human.return_value = '1337'

        customer_logic.RdsProxy = mock.MagicMock()
        customer_logic.RdsProxy.send_customer.return_value = None
        customer_logic.RdsProxy.get_status.return_value = RdsStatus()

        customer_logic.build_response = mock.MagicMock()

        customer = models.Customer()
        user = models.User()
        customer.users = [user, models.User()]
        user.role = ['user', 'admin']

        global flow_type
        flow_type = 0
Пример #2
0
    def test_add_users_success(self):
        logic = customer_logic.CustomerLogic()
        users = [models.User(), models.User()]

        logic.add_users('some_uuid', 'some_region', users, 'some_transaction')

        assert data_manager_mock.add_user.call_count == 2
        assert data_manager_mock.commit.called
Пример #3
0
    def test_replace_default_users_fail(self):
        global mock_returns_error
        mock_returns_error = True
        users = [models.User(), models.User()]

        logic = customer_logic.CustomerLogic()

        self.assertRaises(SystemError, logic.replace_default_users, 'id',
                          users, 'trans_id')
        assert data_manager_mock.rollback.called
Пример #4
0
    def test_replace_users_success(self):
        logic = customer_logic.CustomerLogic()
        users = [models.User(), models.User()]

        logic.replace_users('some_uuid', 'some_region', users,
                            'some_transaction')

        assert record_mock.delete_all_users_from_region.called
        assert data_manager_mock.add_user.called
        assert data_manager_mock.commit.called
Пример #5
0
    def test_add_default_users_with_regions_success(self):
        user = models.User()
        user.role = ['user', 'admin']

        users = [user, models.User()]
        logic = customer_logic.CustomerLogic()

        logic.add_default_users('customer_uuid', users, 'transaction_id')

        assert data_manager_mock.commit.called
        assert data_manager_mock.add_user.call_count == 2
        assert data_manager_mock.add_role.call_count == 2
Пример #6
0
    def test_replace_default_users_no_regions_success(self):
        user = models.User()
        user.role = ['user', 'admin']

        users = [user, models.User()]
        logic = customer_logic.CustomerLogic()

        logic.replace_default_users('customer_uuid', users, 'transaction_id')

        assert data_manager_mock.commit.called
        assert record_mock.delete_all_users_from_region.called
        assert not customer_logic.RdsProxy.send_customer.called
        assert data_manager_mock.add_user.call_count == 2
        assert data_manager_mock.add_role.call_count == 2
Пример #7
0
    def to_wsme(self):
        name = self.region.name
        type = self.region.type
        quota = []
        quotas = {}
        for region_quota in self.customer_region_quotas:
            quotas[region_quota.quota_type] = {}
            for quota_field in region_quota.quota_field_details:
                quotas[region_quota.quota_type][
                    quota_field.
                    field_key] = quota_field.field_value or wsme.Unset

        if quotas:
            compute = None
            storage = None
            network = None

            if 'compute' in quotas:
                compute = [WsmeModels.Compute(**quotas['compute'])]
            if 'storage' in quotas:
                storage = [WsmeModels.Storage(**quotas['storage'])]
            if 'network' in quotas:
                network = [WsmeModels.Network(**quotas['network'])]

            quota = [
                WsmeModels.Quota(compute=compute,
                                 storage=storage,
                                 network=network)
            ]

        users = []
        user = None
        for user_role in self.customer_region_user_roles:
            if user and user.id != user_role.user.name:
                users.append(user)
                user = WsmeModels.User(id=user_role.user.name,
                                       role=[user_role.role.name])
            elif user is None:
                user = WsmeModels.User(id=user_role.user.name,
                                       role=[user_role.role.name])
            else:
                user.role.append(user_role.role.name)
        if user:
            users.append(user)

        region = WsmeModels.Region(name=name,
                                   type=type,
                                   quotas=quota,
                                   users=users)
        return region
Пример #8
0
    def test_replace_users_error(self):
        global mock_returns_error
        mock_returns_error = True

        logic = customer_logic.CustomerLogic()
        users = [models.User()]

        self.assertRaises(SystemError, logic.replace_users, 'id', 'region',
                          users, 'trans_id')
Пример #9
0
def get_cust_model():
    """this function create a customer model object for testing
    :return: new customer object
    """

    cust = models.Customer(enabled=False,
                           name='a',
                           metadata={'a': 'b'},
                           regions=[
                               models.Region(
                                   name='r1',
                                   type='group',
                                   quotas=[models.Quota()],
                                   users=[models.User(id='a', role=['admin'])])
                           ],
                           users=[models.User(id='b', role=['admin'])],
                           defaultQuotas=[models.Quota()])

    return cust
Пример #10
0
    def test_add_customer_with_default_users(self):
        default_quota = models.Quota()
        customer.defaultQuotas = [default_quota]

        default_region = models.Region()
        customer.regions = [default_region]

        default_user = models.User()
        default_user.role = ['user', 'admin']

        default_region.users = [default_user]

        logic = customer_logic.CustomerLogic()

        logic.create_customer(customer, 'some_uuid', 'some_trans_id')

        assert data_manager_mock.add_user.called
Пример #11
0
    "name": "myDomain",
    "metadata": {
        "my_server_name": "Apache1",
        "ocx_cust": "123456889"
    },
    "regions": [Models.Region(**{"name": "SAN1", "type": "single", "quotas": [Models.Quota(**{
        "compute": [Models.Compute(instances='1', injected_files='1', key_pairs='1', ram='1',
                                   vcpus='1', metadata_items='1', injected_file_content_bytes='1',
                                   floating_ips='1', fixed_ips='1', injected_file_path_bytes='1',
                                   server_groups='1', server_group_members='1')],
        "storage": [Models.Storage(gigabytes='1', snapshots='1', volumes='1')],
        "network": [Models.Network(floating_ips='1', networks='1', ports='1', routers='1', subnets='1',
                                   security_groups='1', security_group_rules='1', health_monitor='1',
                                   member='1', pool='1', nat_instance='1', route_table='1', vip='1')]
    })]})],
    "users": [Models.User(**
                          {"id": "userId1", "role": ["admin", "other"]})
              ],
    "defaultQuotas": [Models.Quota(**{
        "compute": [Models.Compute(instances='1', injected_files='1', key_pairs='1', ram='1',
                                   vcpus='1', metadata_items='1', injected_file_content_bytes='1',
                                   floating_ips='1', fixed_ips='1', injected_file_path_bytes='1',
                                   server_groups='1', server_group_members='1')],
        "storage": [Models.Storage(gigabytes='1', snapshots='1', volumes='1')],
        "network": [Models.Network(floating_ips='1', networks='1', ports='1', routers='1', subnets='1',
                                   security_groups='1', security_group_rules='1', health_monitor='1',
                                   member='1', pool='1', nat_instance='1', route_table='1', vip='1')]
    })]
}

INVALID_CREATE_CUSTOMER_DATA = {
    "descriptionInvalid": "Customer description",
Пример #12
0
    def to_wsme(self):
        id = ""
        role = []

        user = WsmeModels.User(id=id, role=role)
        return user