Skip to content

Commit

Permalink
Testing: Error on warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
tlocke committed Aug 23, 2023
1 parent 8f45a25 commit 18010a9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 40 deletions.
45 changes: 14 additions & 31 deletions chellow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -932,23 +932,19 @@ class Batch(Base, PersistentClass):

def __init__(self, sess, contract, reference, description):
self.contract = contract
self.update(sess, reference, description)
self._update(sess, reference, description)

def update(self, sess, reference, description):
def _update(self, sess, reference, description):
reference = reference.strip()
if len(reference) == 0:
raise BadRequest("The batch reference can't be blank.")

self.reference = reference
self.description = description.strip()
try:
sess.flush()
except SQLAlchemyError:
sess.rollback()
raise BadRequest(
f"There's already a batch attached to the contract "
f"{self.contract.name} with the reference {reference}."
)

def update(self, sess, reference, description):
self._update(sess, reference, description)
sess.flush()

def delete(self, sess):
sess.execute(delete(Bill).where(Bill.batch == self))
Expand Down Expand Up @@ -5289,25 +5285,13 @@ def update(
self.account = account
self.g_reading_frequency = g_reading_frequency

if g_contract.start_g_rate_script.start_date > start_date:
raise BadRequest("The contract starts after the era.")
with sess.no_autoflush:
if g_contract.start_g_rate_script.start_date > start_date:
raise BadRequest("The contract starts after the era.")

if hh_before(g_contract.finish_g_rate_script.finish_date, finish_date):
raise BadRequest("The contract finishes before the era.")

try:
sess.flush()
except ProgrammingError as e:
if (
e.orig.args[2]
== 'null value in column "start_date" ' + "violates not-null constraint"
):
raise BadRequest("The start date cannot be blank.")
else:
raise e

sess.flush()

def set_physical_location(self, sess, site):
target_ssgen = (
sess.query(SiteGEra)
Expand Down Expand Up @@ -5435,7 +5419,6 @@ def insert_g_era(

finish_date = covered_g_era.finish_date

sess.flush()
g_era = GEra(
sess,
self,
Expand All @@ -5449,14 +5432,11 @@ def insert_g_era(
g_reading_frequency,
)
sess.add(g_era)
sess.flush()

sess.flush()
g_era.attach_site(sess, physical_site, True)
for site in logical_sites:
g_era.attach_site(sess, site, False)

sess.flush()
if covered_g_era is not None:
covered_g_era.update_dates(sess, covered_g_era.start_date, start_date - HH)
return g_era
Expand Down Expand Up @@ -5746,15 +5726,18 @@ class GBatch(Base, PersistentClass):

def __init__(self, sess, g_contract, reference, description):
self.g_contract = g_contract
self.update(sess, reference, description)
self._update(sess, reference, description)

def update(self, sess, reference, description):
def _update(self, sess, reference, description):
reference = reference.strip()
if len(reference) == 0:
raise BadRequest("The batch reference can't be blank.")

self.reference = reference
self.description = description.strip()

def update(self, sess, reference, description):
self._update(sess, reference, description)
try:
sess.flush()
except SQLAlchemyError:
Expand Down
16 changes: 8 additions & 8 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ classifiers = [
]
dependencies = [
"odio==0.0.22",
"pypdf==3.12.0",
"pg8000==1.29.8",
"Flask==2.3.2",
"SQLAlchemy==2.0.19",
"flask-restx==1.0.3",
"openpyxl==3.0.10",
"pypdf==3.15.2",
"pg8000==1.30.1",
"Flask==2.3.3",
"SQLAlchemy==2.0.20",
"flask-restx==1.1.0",
"openpyxl==3.1.2",
"python-dateutil==2.8.2",
"pytz==2022.6",
"requests==2.31.0",
Expand All @@ -29,7 +29,7 @@ dependencies = [
"pip>=9.0.1",
"pysftp==0.2.9",
"pympler==1.0.1",
"psutil==5.9.4",
"psutil==5.9.5",
"xlrd==2.0.1",
"zish==0.1.10",
]
Expand Down Expand Up @@ -64,7 +64,7 @@ setenv =
commands =
black --check .
flake8 .
pytest --exitfirst test
pytest --exitfirst -W error test/test_models.py
echo PGPORT is {env:PGPORT:unset}
echo PGUSER is {env:PGUSER:unset}
echo Test database is {env:PGDATABASE:unset} on {env:PGHOST:unset}
Expand Down
1 change: 0 additions & 1 deletion test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,6 @@ def test_Bill_update(sess):
bill_type = BillType.get_by_code(sess, "N")

sess.commit()
sess.expire_all()

batch.insert_bill(
sess,
Expand Down

0 comments on commit 18010a9

Please sign in to comment.