Skip to content

Commit

Permalink
Merge pull request #68 from GSA/update-db-tables
Browse files Browse the repository at this point in the history
Update db tables
  • Loading branch information
rshewitt authored May 17, 2024
2 parents e718f7f + b314db1 commit c7049e2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 10 deletions.
17 changes: 9 additions & 8 deletions database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class Base(db.Model):
class Organization(Base):
__tablename__ = "organization"

name = db.Column(db.String(), nullable=False, index=True)
logo = db.Column(db.String())
name = db.Column(db.String, nullable=False, index=True)
logo = db.Column(db.String)
sources = db.relationship(
"HarvestSource", backref="org", cascade="all, delete-orphan", lazy=True
)
Expand All @@ -25,7 +25,7 @@ class HarvestSource(Base):
__tablename__ = "harvest_source"

name = db.Column(db.String, nullable=False)
notification_emails = db.Column(db.String)
notification_emails = db.Column(db.ARRAY(db.String))
organization_id = db.Column(
db.String(36), db.ForeignKey("organization.id"), nullable=False
)
Expand Down Expand Up @@ -75,9 +75,7 @@ class HarvestError(Base):
harvest_job_id = db.Column(
db.String(36), db.ForeignKey("harvest_job.id"), nullable=False
)
harvest_record_id = db.Column(
db.String, db.ForeignKey("harvest_record.id"), nullable=True
)
harvest_record_id = db.Column(db.String, db.ForeignKey("harvest_record.id"))
date_created = db.Column(db.DateTime, default=func.now())
type = db.Column(db.String)
severity = db.Column(
Expand All @@ -92,15 +90,18 @@ class HarvestError(Base):
class HarvestRecord(Base):
__tablename__ = "harvest_record"

identifier = db.Column(db.String())
identifier = db.Column(db.String)
harvest_job_id = db.Column(
db.String(36), db.ForeignKey("harvest_job.id"), nullable=True
)
harvest_source_id = db.Column(
db.String(36), db.ForeignKey("harvest_source.id"), nullable=True
)
source_hash = db.Column(db.String)
source_raw = db.Column(db.String)
date_created = db.Column(db.DateTime, index=True, default=func.now())
date_finished = db.Column(db.DateTime)
ckan_id = db.Column(db.String, index=True)
type = db.Column(db.String)
status = db.Column(db.String)
action = db.Column(Enum("create", "update", "delete", name="record_action"))
status = db.Column(Enum("error", "success", name="record_status"))
7 changes: 6 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@

EXAMPLE_DATA = Path(__file__).parents[1] / "example_data"

HARVEST_SOURCE_URL = os.getenv('HARVEST_SOURCE_URL')
HARVEST_SOURCE_URL = os.getenv("HARVEST_SOURCE_URL")


@pytest.fixture(scope="session")
def app() -> Flask:
app = create_app()

app.config["TESTING"] = True

with app.app_context():
db.create_all()
yield app
Expand Down Expand Up @@ -134,6 +136,9 @@ def record_data_dcatus(job_data_dcatus: dict) -> dict:
"identifier": "test_identifier",
"harvest_job_id": job_data_dcatus["id"],
"harvest_source_id": job_data_dcatus["harvest_source_id"],
"action": "create",
"status": "success",
"source_raw": "example data",
}


Expand Down
10 changes: 9 additions & 1 deletion tests/integration/database/test_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,18 @@ def test_update_harvest_source(
interface.add_organization(organization_data)
source = interface.add_harvest_source(source_data_dcatus)

updates = {"name": "Updated Test Source"}
updates = {
"name": "Updated Test Source",
"notification_emails": ["[email protected]", "[email protected]"],
}

updated_source = interface.update_harvest_source(source.id, updates)
assert updated_source is not None
assert updated_source["name"] == updates["name"]
assert updated_source["notification_emails"] == [
"[email protected]",
"[email protected]",
]

def test_delete_harvest_source(
self, interface, organization_data, source_data_dcatus
Expand Down

1 comment on commit c7049e2

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests Skipped Failures Errors Time
39 0 💤 0 ❌ 0 🔥 16.448s ⏱️

Please sign in to comment.