-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
95 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
A1234567;Garcia;['type1'] | ||
B2345678;Hernandez;['type2'] | ||
C3456789;Smith;[] | ||
D4567890;Jones;['type1', 'type2'] | ||
a93ef111829829ea5038398ba6583dc2e1a2f2c309e24aee535f725dbe1f1250;2c3aaefea8267c66822f6edc0e42d9b7384695f9c0407eabda141770aab8901e;['type1'] | ||
095feaba889222ee1bc97aaf3bb89c90c21238fb556fb48b5cc54760461ea18ce814d016e70b1929d05190edbec1032e07921228fcb61ad3417aaff0abd9d082;123c86e1f2ac255ba31f1ad742defe23d194269669d2aac0d2572e20e9378e395976f84db305caeba1f91e7996463031d4c49365a7a9f4c7dc404873ad330974;['type1'] | ||
A1234567;Garcia;type1 | ||
B2345678;Hernandez;type2 | ||
C3456789;Smith; | ||
D4567890;Jones;type1 | ||
D4567890;Jones;type2 | ||
a93ef111829829ea5038398ba6583dc2e1a2f2c309e24aee535f725dbe1f1250;2c3aaefea8267c66822f6edc0e42d9b7384695f9c0407eabda141770aab8901e;type1 | ||
095feaba889222ee1bc97aaf3bb89c90c21238fb556fb48b5cc54760461ea18ce814d016e70b1929d05190edbec1032e07921228fcb61ad3417aaff0abd9d082;123c86e1f2ac255ba31f1ad742defe23d194269669d2aac0d2572e20e9378e395976f84db305caeba1f91e7996463031d4c49365a7a9f4c7dc404873ad330974;type1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,26 @@ | ||
from eligibility_server.db import db | ||
|
||
|
||
user_eligibility = db.Table( | ||
"user_eligibility", | ||
db.Column("user_id", db.Integer, db.ForeignKey("user.id"), primary_key=True), | ||
db.Column("eligibility_id", db.Integer, db.ForeignKey("eligibility.id"), primary_key=True), | ||
) | ||
|
||
|
||
class Eligibility(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
name = db.Column(db.String, unique=True, nullable=False) | ||
|
||
def __repr__(self): | ||
return f"<Eligibility {self.name}>" | ||
|
||
|
||
class User(db.Model): | ||
id = db.Column(db.Integer, primary_key=True) | ||
sub = db.Column(db.String, unique=True, nullable=False) | ||
name = db.Column(db.String, unique=True, nullable=False) | ||
types = db.Column(db.String, unique=False, nullable=False) | ||
types = db.relationship("Eligibility", secondary=user_eligibility, lazy="subquery", backref=db.backref("users", lazy=True)) | ||
|
||
def __repr__(self): | ||
return "<User %r>" % self.sub | ||
return f"<User {self.sub}>" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import pytest | ||
|
||
from flask_sqlalchemy import inspect | ||
from eligibility_server.db import db | ||
from eligibility_server.db.models import Eligibility, User | ||
|
||
|
||
@pytest.mark.usefixtures("flask") | ||
def test_init_db_command(runner): | ||
"""Assumes that IMPORT_FILE_PATH is data/server.csv.""" | ||
runner.invoke(args="drop-db") | ||
|
||
result = runner.invoke(args="init-db") | ||
|
||
assert result.exit_code == 0 | ||
|
||
assert User.query.count() == 6 | ||
assert Eligibility.query.count() == 2 | ||
|
||
user_with_one_eligibility = User.query.filter_by(sub="A1234567", name="Garcia").first() | ||
type1_eligibility = Eligibility.query.filter_by(name="type1").first() | ||
assert user_with_one_eligibility.types == [type1_eligibility] | ||
|
||
user_with_no_eligibility = User.query.filter_by(sub="C3456789", name="Smith").first() | ||
assert user_with_no_eligibility.types == [] | ||
|
||
user_with_multiple_eligibilities = User.query.filter_by(sub="D4567890", name="Jones").first() | ||
type2_eligibility = Eligibility.query.filter_by(name="type2").first() | ||
assert user_with_multiple_eligibilities.types == [type1_eligibility, type2_eligibility] | ||
|
||
|
||
@pytest.mark.usefixtures("flask") | ||
def test_drop_db_command(runner): | ||
result = runner.invoke(args="drop-db") | ||
|
||
assert result.exit_code == 0 | ||
|
||
inspector = inspect(db.engine) | ||
assert inspector.get_table_names() == [] | ||
|
||
# temp fix to ensure database tests are idempotent - later tests need the database to exist | ||
runner.invoke(args="init-db") |