def test_get_service(mock_session): fake_service = models.Service() mock_session.return_value.__enter__.return_value. \ query.return_value.filter.return_value.first.return_value = \ fake_service result = api.get_service(None, 'a9e54256-2b8b-47d9-8ca1-355db52d60f1') assert result == fake_service.to_dict()
def test_create_service(mock_session, mock_uuid): mock_uuid.return_value = '85a56708-a072-4525-9cc2-bb2f4e4a93e1' expected = models.Service() expected.id = '85a56708-a072-4525-9cc2-bb2f4e4a93e1' expected.name = 'volume provsioning' actual = api.create_service(None, dict(name='volume provsioning')) mock_session.return_value.__enter__.return_value.add.assert_called_once() for key, value in actual.__dict__.items(): if hasattr(models.Service, key): assert getattr(expected, key) == value
def create_service(context, values): service = models.Service() for key, value in values.items(): if hasattr(service, key): setattr(service, key, value) if not service.id: service.id = uuid.uuid4() with session_scope() as session: session.add(service) return service
def create_service(context, values): service = models.Service() if 'id' not in values: values['id'] = str(uuid.uuid4()) for key, value in values.items(): if hasattr(service, key): setattr(service, key, value) with session_scope() as session: session.add(service) return get_service(None, values['id'])