import enum

from sqlalchemy.schema import Column
from sqlalchemy.types import Integer

from cliche.sqltypes import EnumType
from cliche.orm import Base


class Color(enum.Enum):

    red = 1
    green = 2
    blue = 3


class ColorTable(Base):

    __tablename__ = 'color_table'

    id = Column(Integer, primary_key=True)
    test_col = Column(EnumType(Color))


def test_enum_type(fx_session):
    red_obj = ColorTable(test_col=Color.red)
    green_obj = ColorTable(test_col=Color.green)
    blue_obj = ColorTable(test_col=Color.blue)
    fx_session.add(red_obj)
    fx_session.add(green_obj)
    fx_session.add(blue_obj)
    fx_session.flush()
    result_obj = fx_session.query(ColorTable) \
                           .filter(ColorTable.test_col == Color.green) \
                           .one()
    assert green_obj is result_obj

import enum

from sqlalchemy.schema import Column
from sqlalchemy.types import Integer

from cliche.sqltypes import EnumType
from cliche.orm import Base


class Color(enum.Enum):

    red = 1
    green = 2
    blue = 3


class ColorTable(Base):

    __tablename__ = 'color_table'

    id = Column(Integer, primary_key=True)
    color = Column(EnumType(Color, name='color'))


def test_enum_type(fx_session):
    red_obj = ColorTable(color=Color.red)
    green_obj = ColorTable(color=Color.green)
    blue_obj = ColorTable(color=Color.blue)
    fx_session.add(red_obj)
    fx_session.add(green_obj)
    fx_session.add(blue_obj)
    fx_session.flush()
    result_obj = fx_session.query(ColorTable) \
                           .filter(ColorTable.color == Color.green) \
                           .one()
    assert green_obj is result_obj

Add name to EnumType in test since pgsql needs it.
Add name to EnumType in test since pgsql needs it.

  import enum
  
  from sqlalchemy.schema import Column
  from sqlalchemy.types import Integer
  
  from cliche.sqltypes import EnumType
  from cliche.orm import Base
  
  
  class Color(enum.Enum):
  
      red = 1
      green = 2
      blue = 3
  
  
  class ColorTable(Base):
  
      __tablename__ = 'color_table'
  
      id = Column(Integer, primary_key=True)
-     test_col = Column(EnumType(Color))
+     color = Column(EnumType(Color, name='color'))
  
  
  def test_enum_type(fx_session):
-     red_obj = ColorTable(test_col=Color.red)
+     red_obj = ColorTable(color=Color.red)
-     green_obj = ColorTable(test_col=Color.green)
+     green_obj = ColorTable(color=Color.green)
-     blue_obj = ColorTable(test_col=Color.blue)
+     blue_obj = ColorTable(color=Color.blue)
      fx_session.add(red_obj)
      fx_session.add(green_obj)
      fx_session.add(blue_obj)
      fx_session.flush()
      result_obj = fx_session.query(ColorTable) \
-                            .filter(ColorTable.test_col == Color.green) \
+                            .filter(ColorTable.color == Color.green) \
                             .one()
      assert green_obj is result_obj
  
Add name to EnumType in test since pgsql needs it.
## Code Before:
import enum

from sqlalchemy.schema import Column
from sqlalchemy.types import Integer

from cliche.sqltypes import EnumType
from cliche.orm import Base


class Color(enum.Enum):

    red = 1
    green = 2
    blue = 3


class ColorTable(Base):

    __tablename__ = 'color_table'

    id = Column(Integer, primary_key=True)
    test_col = Column(EnumType(Color))


def test_enum_type(fx_session):
    red_obj = ColorTable(test_col=Color.red)
    green_obj = ColorTable(test_col=Color.green)
    blue_obj = ColorTable(test_col=Color.blue)
    fx_session.add(red_obj)
    fx_session.add(green_obj)
    fx_session.add(blue_obj)
    fx_session.flush()
    result_obj = fx_session.query(ColorTable) \
                           .filter(ColorTable.test_col == Color.green) \
                           .one()
    assert green_obj is result_obj

## Instruction:
Add name to EnumType in test since pgsql needs it.
## Code After:
import enum

from sqlalchemy.schema import Column
from sqlalchemy.types import Integer

from cliche.sqltypes import EnumType
from cliche.orm import Base


class Color(enum.Enum):

    red = 1
    green = 2
    blue = 3


class ColorTable(Base):

    __tablename__ = 'color_table'

    id = Column(Integer, primary_key=True)
    color = Column(EnumType(Color, name='color'))


def test_enum_type(fx_session):
    red_obj = ColorTable(color=Color.red)
    green_obj = ColorTable(color=Color.green)
    blue_obj = ColorTable(color=Color.blue)
    fx_session.add(red_obj)
    fx_session.add(green_obj)
    fx_session.add(blue_obj)
    fx_session.flush()
    result_obj = fx_session.query(ColorTable) \
                           .filter(ColorTable.color == Color.green) \
                           .one()
    assert green_obj is result_obj
