1#    Copyright 2016 EMC Corp.
2#
3#    Licensed under the Apache License, Version 2.0 (the "License"); you may
4#    not use this file except in compliance with the License. You may obtain
5#    a copy of the License at
6#
7#         http://www.apache.org/licenses/LICENSE-2.0
8#
9#    Unless required by applicable law or agreed to in writing, software
10#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12#    License for the specific language governing permissions and limitations
13#    under the License.
14
15from oslo_versionedobjects import fields
16
17from cinder import objects
18from cinder.tests.unit import fake_constants as fake
19
20
21def fake_db_cgsnapshot(**updates):
22    db_values = {
23        'id': fake.CGSNAPSHOT_ID,
24        'consistencygroup_id': fake.CONSISTENCY_GROUP_ID,
25        'user_id': fake.USER_ID,
26        'project_id': fake.PROJECT_ID,
27    }
28    for name, field in objects.CGSnapshot.fields.items():
29        if name in db_values:
30            continue
31        if field.nullable:
32            db_values[name] = None
33        elif field.default != fields.UnspecifiedDefault:
34            db_values[name] = field.default
35        else:
36            raise Exception('fake_db_snapshot needs help with %s' %
37                            name)
38
39    if updates:
40        db_values.update(updates)
41
42    return db_values
43
44
45def fake_cgsnapshot_obj(context, **updates):
46    expected_attrs = updates.pop('expected_attrs', None)
47    return objects.CGSnapshot._from_db_object(context,
48                                              objects.CGSnapshot(),
49                                              fake_db_cgsnapshot(
50                                                  **updates),
51                                              expected_attrs=expected_attrs)
52