コード例 #1
0
    def test_apply(self):
        operations = [{
            'operation': 'a',
            'data': {
                'a': 'a'
            }
        }, {
            'operation': 'b',
            'data': {
                'b': 'b'
            }
        }, {
            'operation': 'c',
            'data': {
                'c': 'c'
            }
        }]
        migration = BKIAMResourceMigration(operations)
        for op in operations:
            setattr(migration, op['operation'], MagicMock())

        migration.apply()

        for op in operations:
            getattr(migration,
                    op['operation']).assert_called_once_with(op['data'])
コード例 #2
0
    def test_batch_upsert_resource_types(self):
        migration = BKIAMResourceMigration({})
        migration.client = MagicMock()
        migration.client.batch_upsert_resource_types = MagicMock(
            return_value={'result': True})

        migration.batch_upsert_resource_types(self.call_data)

        migration.client.batch_upsert_resource_types.assert_called_once_with(
            **self.call_data)
コード例 #3
0
    def test_register_system__raise_error(self):
        migration = BKIAMResourceMigration({})
        migration.client = MagicMock()
        migration.client.register_system = MagicMock(return_value={
            'result': False,
            'message': ''
        })

        self.assertRaises(MigrationOperationFailedError,
                          migration.register_system, self.call_data)
コード例 #4
0
    def test_delete_resource_type__raise_error(self):
        migration = BKIAMResourceMigration({})
        migration.client = MagicMock()
        migration.client.delete_resource_type = MagicMock(return_value={
            'result': False,
            'message': ''
        })

        self.assertRaises(MigrationOperationFailedError,
                          migration.delete_resource_type, self.call_data)
コード例 #5
0
    def test_register_system(self):
        migration = BKIAMResourceMigration({})
        migration.client = MagicMock()
        migration.client.register_system = MagicMock(
            return_value={'result': True})

        migration.register_system(self.call_data)

        migration.client.register_system.assert_called_once_with(
            **self.call_data)

        migration.client.register_system = MagicMock(
            return_value={
                'result': False,
                'code': migration.SYSTEM_EXIST_CODE
            })

        migration.register_system(self.call_data)

        migration.client.register_system.assert_called_once_with(
            **self.call_data)
コード例 #6
0
    def test_delete_resource_type(self):
        migration = BKIAMResourceMigration({})
        migration.client = MagicMock()
        migration.client.delete_resource_type = MagicMock(
            return_value={'result': True})

        migration.delete_resource_type(self.call_data)

        migration.client.delete_resource_type.assert_called_once_with(
            **self.call_data)

        migration.client.delete_resource_type = MagicMock(
            return_value={
                'result': False,
                'code': migration.RESOURCE_NOT_EXIST_CODE
            })

        migration.delete_resource_type(self.call_data)

        migration.client.delete_resource_type.assert_called_once_with(
            **self.call_data)