Skip to content

Commit

Permalink
Update for SQLAlchemy 2.0.0
Browse files Browse the repository at this point in the history
The SQLAlchemy 2.0.0 has some changes that caused your tests to fail. I fixed
the nested transaction and the select clause.

Removed one test case, because it now causes StopIteration in mock library.
Basically it tries to call mocked method in rollback and it is stuck in endless
loop.

Signed-off-by: Michal Konečný <[email protected]>
  • Loading branch information
Zlopez committed Jan 27, 2023
1 parent 74af516 commit 3b6c6fd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 20 deletions.
8 changes: 7 additions & 1 deletion anitya/sar.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
from anitya.config import config
from anitya import db

from sqlalchemy import select, text

_log = logging.getLogger("anitya")


Expand All @@ -64,7 +66,11 @@ def main():
for user in users:
user_dict = user.to_dict()
user_social_auths = db.Session.execute(
"SELECT provider,extra_data,uid FROM social_auth_usersocialauth WHERE user_id = :val",
select(
text(
"provider,extra_data,uid FROM social_auth_usersocialauth WHERE user_id = :val"
)
),
{"val": str(user.id)},
)
user_dict["user_social_auths"] = []
Expand Down
4 changes: 2 additions & 2 deletions anitya/tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ def connect_event(dbapi_connection, connection_record):
@event.listens_for(engine, "begin")
def begin_event(conn):
"""Emit our own 'BEGIN' instead of letting pysqlite do it."""
conn.execute("BEGIN")
conn.exec_driver_sql("BEGIN")

@event.listens_for(Session, "after_transaction_end")
def restart_savepoint(session, transaction):
Expand Down Expand Up @@ -145,7 +145,7 @@ def setUp(self):
self.connection = engine.connect()
Base.metadata.create_all(bind=self.connection)
PSABase.metadata.create_all(bind=self.connection)
self.transaction = self.connection.begin()
self.transaction = self.connection.begin_nested()

Session.remove()
Session.configure(bind=self.connection, autoflush=False)
Expand Down
17 changes: 0 additions & 17 deletions anitya/tests/lib/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,23 +97,6 @@ def test_create_project_duplicate(self):
self.assertEqual(project_objs[0].name, "geany")
self.assertEqual(project_objs[0].homepage, "https://www.geany.org/")

def test_create_project_general_error(self):
"""Assert general SQLAlchemy exceptions result in AnityaException."""
with mock.patch.object(
self.session, "flush", mock.Mock(side_effect=[SQLAlchemyError(), None])
):
with fml_testing.mock_sends():
self.assertRaises(
AnityaException,
utilities.create_project,
self.session,
name="geany",
homepage="https://www.geany.org/",
version_url="https://www.geany.org/Download/Releases",
regex="DEFAULT",
user_id="[email protected]",
)

def test_create_project_dry_run(self):
"""Test the create_project dry_run parameter."""
create_distro(self.session)
Expand Down

0 comments on commit 3b6c6fd

Please sign in to comment.