Exemplo n.º 1
0
    def test_add_regions_success(self):
        regions = [models.Region(), models.Region()]
        logic = customer_logic.CustomerLogic()

        logic.add_regions('customer_uuid', regions, 'transaction_id')

        assert data_manager_mock.commit.called
        assert customer_logic.RdsProxy.send_customer_dict.called
Exemplo n.º 2
0
    def test_replace_regions_fail(self):
        global mock_returns_error
        mock_returns_error = True
        regions = [models.Region(), models.Region()]
        logic = customer_logic.CustomerLogic()

        self.assertRaises(SystemError, logic.replace_regions, 'customer_uuid',
                          regions, 'transaction_id')
        assert data_manager_mock.rollback.called
Exemplo n.º 3
0
    def test_replace_regions_success(self):
        regions = [models.Region(), models.Region()]
        logic = customer_logic.CustomerLogic()

        logic.replace_regions('customer_uuid', regions, 'transaction_id')

        assert data_manager_mock.commit.called
        assert customer_logic.RdsProxy.send_customer_dict.called
        assert record_mock.delete_all_regions_for_customer.called
Exemplo n.º 4
0
    def test_create_customer_success_with_regions(self):
        customer.regions = [models.Region(name="a")]
        logic = customer_logic.CustomerLogic()
        logic.create_customer(customer, 'some_uuid', 'some_trans_id')

        # sql_customer, trans_id = customer_logic.RdsProxy.send_customer.call_args_list[0][0]
        # assert trans_id is 'some_trans_id'
        # assert type(sql_customer) is sql_models.Customer
        assert data_manager_mock.commit.called
        assert not data_manager_mock.rollback.called
Exemplo n.º 5
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
Exemplo n.º 6
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
Exemplo n.º 7
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
Exemplo n.º 8
0
    def test_add_regions_action(self):
        regions = [models.Region(), models.Region()]
        logic = customer_logic.CustomerLogic()
        logic.add_regions('some_uuid', regions, 'some_trans_id')

        res = customer_logic.RdsProxy.send_customer.call_args_list
Exemplo n.º 9
0
 def mock_to_wsme():
     return models.Customer(
         regions=[models.Region(name='DPK', status='Success')])
Exemplo n.º 10
0
    ]
}

RET_CUSTOMER_JSON = {
    "description": "Customer description",
    "enabled": True,
    "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',