Skip to content

Commit

Permalink
add models and mark tests to fail
Browse files Browse the repository at this point in the history
  • Loading branch information
sabard committed Aug 2, 2022
1 parent e655b21 commit 8f4a380
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
31 changes: 30 additions & 1 deletion graphene_sqlalchemy/tests/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -76,13 +77,41 @@ 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)
headline = Column(String(100))
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."""
Expand Down
10 changes: 10 additions & 0 deletions graphene_sqlalchemy/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import graphene
import pytest

from ..fields import SQLAlchemyConnectionField
from ..filters import FloatFilter
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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.")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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!')
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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

0 comments on commit 8f4a380

Please sign in to comment.