From 8f4a38005c01deee3e02bbf838500fe14191b9c3 Mon Sep 17 00:00:00 2001 From: Sabar Dasgupta Date: Tue, 2 Aug 2022 15:41:30 -0400 Subject: [PATCH] add models and mark tests to fail --- graphene_sqlalchemy/tests/models.py | 31 ++++++++++++++++++++++- graphene_sqlalchemy/tests/test_filters.py | 10 ++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/graphene_sqlalchemy/tests/models.py b/graphene_sqlalchemy/tests/models.py index 88e992b9..de786c52 100644 --- a/graphene_sqlalchemy/tests/models.py +++ b/graphene_sqlalchemy/tests/models.py @@ -6,7 +6,7 @@ func, select) from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.ext.hybrid import hybrid_property -from sqlalchemy.orm import column_property, composite, mapper, relationship +from sqlalchemy.orm import backref, column_property, composite, mapper, relationship PetKind = Enum("cat", "dog", name="pet_kind") @@ -39,6 +39,7 @@ class Pet(Base): pet_kind = Column(PetKind, nullable=False) hair_kind = Column(Enum(HairKind, name="hair_kind"), nullable=False) reporter_id = Column(Integer(), ForeignKey("reporters.id")) + legs = Column(Integer(), default=4) class CompositeFullName(object): @@ -76,6 +77,14 @@ def hybrid_prop(self): composite_prop = composite(CompositeFullName, first_name, last_name, doc="Composite") +articles_tags_table = Table( + "articles_tags", + Base.metadata, + Column("article_id", ForeignKey("article.id")), + Column("imgae_id", ForeignKey("image.id")), +) + + class Article(Base): __tablename__ = "articles" id = Column(Integer(), primary_key=True) @@ -83,6 +92,26 @@ class Article(Base): pub_date = Column(Date()) reporter_id = Column(Integer(), ForeignKey("reporters.id")) + # one-to-one relationship with image + image_id = Column(Integer(), ForeignKey('image.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.""" diff --git a/graphene_sqlalchemy/tests/test_filters.py b/graphene_sqlalchemy/tests/test_filters.py index 584bde76..720f84ed 100644 --- a/graphene_sqlalchemy/tests/test_filters.py +++ b/graphene_sqlalchemy/tests/test_filters.py @@ -1,4 +1,5 @@ import graphene +import pytest from ..fields import SQLAlchemyConnectionField from ..filters import FloatFilter @@ -77,6 +78,7 @@ def resolve_reporters(self, _info): # Test a simple example of filtering +@pytest.mark.xfail def test_filter_simple(session): add_test_data(session) Query = create_schema(session) @@ -99,6 +101,7 @@ def test_filter_simple(session): # Test a custom filter type +@pytest.mark.xfail def test_filter_custom_type(session): add_test_data(session) Query = create_schema(session) @@ -132,6 +135,7 @@ class CustomQuery(Query, ExtraQuery): assert result == expected # Test a 1:1 relationship +@pytest.mark.xfail def test_filter_relationship_one_to_one(session): article = Article(headline='Hi!') image = Image(external_id=1, description="A beautiful image.") @@ -162,6 +166,7 @@ def test_filter_relationship_one_to_one(session): # Test a 1:n relationship +@pytest.mark.xfail def test_filter_relationship_one_to_many(session): add_test_data(session) Query = create_schema(session) @@ -238,6 +243,7 @@ def test_filter_relationship_one_to_many(session): assert result == expected # Test a n:m relationship +@pytest.mark.xfail def test_filter_relationship_many_to_many(session): article1 = Article(headline='Article! Look!') article2 = Article(headline='Woah! Another!') @@ -326,6 +332,7 @@ def test_filter_relationship_many_to_many(session): # Test connecting filters with "and" +@pytest.mark.xfail def test_filter_logic_and(session): add_test_data(session) @@ -354,6 +361,7 @@ def test_filter_logic_and(session): # Test connecting filters with "or" +@pytest.mark.xfail def test_filter_logic_or(session): add_test_data(session) Query = create_schema(session) @@ -385,6 +393,7 @@ def test_filter_logic_or(session): # Test connecting filters with "and" and "or" together +@pytest.mark.xfail def test_filter_logic_and_or(session): add_test_data(session) Query = create_schema(session) @@ -415,5 +424,6 @@ def test_filter_logic_and_or(session): # TODO hybrid property +@pytest.mark.xfail def test_filter_hybrid_property(session): raise NotImplementedError