
import abc
import uuid

from restalchemy.dm import properties
from restalchemy.dm import types


class Model(properties.PropertyBasedObject):
    __metaclass__ = abc.ABCMeta

    def __init__(self, **kwargs):
        super(Model, self).__init__(properties.AbstractProperty, **kwargs)

    @classmethod
    def restore(cls, **kwargs):
        return super(Model, cls).restore(properties.AbstractProperty, **kwargs)

    @abc.abstractmethod
    def get_id(self):
        pass


class ModelWithUUID(Model):
    uuid = properties.property(types.UUID, read_only=True,
                               default=lambda: str(uuid.uuid4()))

    def get_id(self):
        return self.uuid


import abc
import uuid

from restalchemy.dm import properties
from restalchemy.dm import types


class Model(properties.PropertyBasedObject):
    __metaclass__ = abc.ABCMeta

    def __init__(self, **kwargs):
        super(Model, self).__init__(properties.AbstractProperty, **kwargs)

    @classmethod
    def restore(cls, **kwargs):
        return super(Model, cls).restore(properties.AbstractProperty, **kwargs)

    @abc.abstractmethod
    def get_id(self):
        pass


class ModelWithUUID(Model):
    uuid = properties.property(types.UUID, read_only=True,
                               default=lambda: str(uuid.uuid4()))

    def get_id(self):
        return self.uuid

    def __eq__(self, other):
        if isinstance(other, type(self)):
            return self.get_id() == other.get_id()
        return False

Add equal method to model with uuid
Add equal method to model with uuid

Change-Id: Iefa05d50f2f591399d5423debd699f88074a574e

  
  import abc
  import uuid
  
  from restalchemy.dm import properties
  from restalchemy.dm import types
  
  
  class Model(properties.PropertyBasedObject):
      __metaclass__ = abc.ABCMeta
  
      def __init__(self, **kwargs):
          super(Model, self).__init__(properties.AbstractProperty, **kwargs)
  
      @classmethod
      def restore(cls, **kwargs):
          return super(Model, cls).restore(properties.AbstractProperty, **kwargs)
  
      @abc.abstractmethod
      def get_id(self):
          pass
  
  
  class ModelWithUUID(Model):
      uuid = properties.property(types.UUID, read_only=True,
                                 default=lambda: str(uuid.uuid4()))
  
      def get_id(self):
          return self.uuid
  
+     def __eq__(self, other):
+         if isinstance(other, type(self)):
+             return self.get_id() == other.get_id()
+         return False
+ 
Add equal method to model with uuid
## Code Before:

import abc
import uuid

from restalchemy.dm import properties
from restalchemy.dm import types


class Model(properties.PropertyBasedObject):
    __metaclass__ = abc.ABCMeta

    def __init__(self, **kwargs):
        super(Model, self).__init__(properties.AbstractProperty, **kwargs)

    @classmethod
    def restore(cls, **kwargs):
        return super(Model, cls).restore(properties.AbstractProperty, **kwargs)

    @abc.abstractmethod
    def get_id(self):
        pass


class ModelWithUUID(Model):
    uuid = properties.property(types.UUID, read_only=True,
                               default=lambda: str(uuid.uuid4()))

    def get_id(self):
        return self.uuid

## Instruction:
Add equal method to model with uuid
## Code After:

import abc
import uuid

from restalchemy.dm import properties
from restalchemy.dm import types


class Model(properties.PropertyBasedObject):
    __metaclass__ = abc.ABCMeta

    def __init__(self, **kwargs):
        super(Model, self).__init__(properties.AbstractProperty, **kwargs)

    @classmethod
    def restore(cls, **kwargs):
        return super(Model, cls).restore(properties.AbstractProperty, **kwargs)

    @abc.abstractmethod
    def get_id(self):
        pass


class ModelWithUUID(Model):
    uuid = properties.property(types.UUID, read_only=True,
                               default=lambda: str(uuid.uuid4()))

    def get_id(self):
        return self.uuid

    def __eq__(self, other):
        if isinstance(other, type(self)):
            return self.get_id() == other.get_id()
        return False
