Skip to content

Commit

Permalink
make filter tests run
Browse files Browse the repository at this point in the history
  • Loading branch information
sabard committed Aug 11, 2022
1 parent e0cd465 commit 32254b6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 19 deletions.
2 changes: 2 additions & 0 deletions graphene_sqlalchemy/filters.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class FloatFilter:
pass
32 changes: 16 additions & 16 deletions graphene_sqlalchemy/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,24 @@ def hybrid_prop_list(self) -> List[int]:
articles_tags_table = Table(
"articles_tags",
Base.metadata,
Column("article_id", ForeignKey("article.id")),
Column("imgae_id", ForeignKey("image.id")),
Column("article_id", ForeignKey("articles.id")),
Column("tag_id", ForeignKey("tags.id")),
)


class Image(Base):
__tablename__ = "images"
id = Column(Integer(), primary_key=True)
external_id = Column(Integer())
description = Column(String(30))


class Tag(Base):
__tablename__ = "tags"
id = Column(Integer(), primary_key=True)
name = Column(String(30))


class Article(Base):
__tablename__ = "articles"
id = Column(Integer(), primary_key=True)
Expand All @@ -139,26 +152,13 @@ class ArticleReader(Base):
reader_id = Column(Integer(), ForeignKey("readers.id"), primary_key=True)

# one-to-one relationship with image
image_id = Column(Integer(), ForeignKey('image.id'), unique=True)
image_id = Column(Integer(), ForeignKey('images.id'), unique=True)
image = relationship("Image", backref=backref("articles", uselist=False))

# many-to-many relationship with tags
tags = relationship("Tag", secondary=articles_tags_table, backref="articles")


class Image(Base):
__tablename__ = "images"
id = Column(Integer(), primary_key=True)
external_id = Column(Integer())
description = Column(String(30))


class Tag(Base):
__tablename__ = "tags"
id = Column(Integer(), primary_key=True)
name = Column(String(30))


class ReflectedEditor(type):
"""Same as Editor, but using reflected table."""

Expand Down
4 changes: 2 additions & 2 deletions graphene_sqlalchemy/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ class Meta:
class Query(graphene.ObjectType):
article = graphene.Field(ArticleType)
articles = graphene.List(ArticleType)
image = graphene.Field(ImageType)
images = graphene.List(ImageType)
# image = graphene.Field(ImageType)
# images = graphene.List(ImageType)
reporter = graphene.Field(ReporterType)
reporters = graphene.List(ReporterType)

Expand Down
10 changes: 9 additions & 1 deletion graphene_sqlalchemy/tests/test_sort_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ class Meta:
"HAIR_KIND_DESC",
"REPORTER_ID_ASC",
"REPORTER_ID_DESC",
"LEGS_ASC",
"LEGS_DESC",
]
assert str(sort_enum.ID_ASC.value.value) == "pets.id ASC"
assert str(sort_enum.ID_DESC.value.value) == "pets.id DESC"
Expand Down Expand Up @@ -94,6 +96,8 @@ class Meta:
"PET_KIND_DESC",
"HAIR_KIND_ASC",
"HAIR_KIND_DESC",
"LEGS_ASC",
"LEGS_DESC",
]


Expand Down Expand Up @@ -134,6 +138,8 @@ class Meta:
"HAIR_KIND_DESC",
"REPORTER_ID_ASC",
"REPORTER_ID_DESC",
"LEGS_ASC",
"LEGS_DESC",
]
assert str(sort_enum.ID_ASC.value.value) == "pets.id ASC"
assert str(sort_enum.ID_DESC.value.value) == "pets.id DESC"
Expand All @@ -148,7 +154,7 @@ def test_sort_argument_with_excluded_fields_in_object_type():
class PetType(SQLAlchemyObjectType):
class Meta:
model = Pet
exclude_fields = ["hair_kind", "reporter_id"]
exclude_fields = ["hair_kind", "reporter_id", "legs"]

sort_arg = PetType.sort_argument()
sort_enum = sort_arg.type._of_type
Expand Down Expand Up @@ -237,6 +243,8 @@ def get_symbol_name(column_name, sort_asc=True):
"HairKindDown",
"ReporterIdUp",
"ReporterIdDown",
"LegsUp",
"LegsDown",
]
assert sort_arg.default_value == ["IdUp"]

Expand Down

0 comments on commit 32254b6

Please sign in to comment.