Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
* test_banner_creation uses the active banner. the service method which
  is tested validates the data over the schema where start_datetime and
  end_datetime is a required field and it has to look like:
  '%Y-%m-%d %H:%M:%S'

* the problem is that test_read_banner uses the same banner to test the
  read service. the change in "active" has the effect that the stored
  value in the database is not like "2024-07-10 12:04:03.348391" which
  it is due the strftime function is not used. db.DateTime could only
  bring back the date in form of a datetime object which is then used in
  isoformat if the value in the database contains the ".34383" part.

* therefore the easiest solution is to use for test_read_banner the
  "other" banner

* ATTENTION: be cautious during the migration from utcnow to
  now(timezone.utc)
  • Loading branch information
utnapischtim committed Oct 3, 2024
1 parent 6492e27 commit eeb91b7
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tests/services/test_services.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2022 CERN.
# Copyright (C) 2024 Graz University of Technology.
#
# Invenio-Banners is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.
Expand All @@ -22,7 +23,10 @@
"message": "active",
"url_path": "/active",
"category": "info",
"end_datetime": datetime.utcnow() + timedelta(days=1),
"start_datetime": datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S"),
"end_datetime": (datetime.utcnow() + timedelta(days=1)).strftime(
"%Y-%m-%d %H:%M:%S"
),
"active": True,
},
"inactive": {
Expand Down Expand Up @@ -151,7 +155,7 @@ def test_delete_non_existing_banner(app, superuser_identity):
def test_read_banner(app, simple_user_identity):
"""Read a banner by id."""
# create banner first
banner = BannerModel.create(banners["active"])
banner = BannerModel.create(banners["other"])

banner_result = service.read(simple_user_identity, banner.id)

Expand Down

0 comments on commit eeb91b7

Please sign in to comment.