summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Helmert III <ajak@gentoo.org>2023-12-17 21:15:07 -0800
committerJohn Helmert III <ajak@gentoo.org>2023-12-17 21:21:13 -0800
commit3086ebf95004d00716984a3aacdd70c516c18361 (patch)
tree37b0316f1eb003e3cb338290ad3952073ac8b79d
parentviews: edit_glsa: oops, guard against empty error (diff)
downloadglsamaker-3086ebf95004d00716984a3aacdd70c516c18361.tar.gz
glsamaker-3086ebf95004d00716984a3aacdd70c516c18361.tar.bz2
glsamaker-3086ebf95004d00716984a3aacdd70c516c18361.zip
test_views: add a test to trigger bug table primary key error
SQLAlchemy's implicit handling of uniqueness of primary keys in merges seems to have changed, and this triggers the following error when submitting an edited GLSA twice. It ends up attempting to merge multiple bug rows with the same ID, rather than simply reusing existing rows. glsamaker-http-1 | sqlalchemy.exc.IntegrityError: (raised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely) glsamaker-http-1 | (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "bug_pkey" glsamaker-http-1 | DETAIL: Key (bug_id)=(713098) already exists. glsamaker-http-1 | glsamaker-http-1 | [SQL: INSERT INTO bug (bug_id) VALUES (%(bug_id)s)] glsamaker-http-1 | [parameters: {'bug_id': '713098'}] glsamaker-http-1 | (Background on this error at: https://sqlalche.me/e/20/gkpj) Interestingly, this seems to trigger when creating Affected rows, which shouldn't touch the bugs table: glsamaker-http-1 | File "/usr/local/lib/python3.11/site-packages/glsamaker/views.py", line 205, in edit_glsa glsamaker-http-1 | glsa.affected = parse_atoms(request, "unaffected") + parse_atoms( glsamaker-http-1 | ^^^^^^^^^^^^ glsamaker-http-1 | File "/usr/local/lib/python3.11/site-packages/glsamaker/views.py", line 166, in parse_atoms glsamaker-http-1 | ret.append(atom_to_affected(pkg, arch, range_type)) glsamaker-http-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ glsamaker-http-1 | File "/usr/local/lib/python3.11/site-packages/glsamaker/views.py", line 151, in atom_to_affected glsamaker-http-1 | return Affected(pn, version, pkg_range, arch, slot, range_type) glsamaker-http-1 | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Signed-off-by: John Helmert III <ajak@gentoo.org>
-rw-r--r--test/test_views.py35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/test_views.py b/test/test_views.py
index 7d644a9..1f82e88 100644
--- a/test/test_views.py
+++ b/test/test_views.py
@@ -87,3 +87,38 @@ def test_edit_glsa(app, auth, db):
response = auth.get(f"/edit_glsa/{db.session.query(GLSA).first().glsa_id}")
assert response.status_code == 200
+
+ glsa_data = {
+ # see views.GLSAForm for what's required here
+ "title": "glsa title",
+ "synopsis": "glsa synopsis",
+ "product_type": "ebuild",
+ "bugs": "123456,654321",
+ "access": "remote",
+ "background": "glsa background",
+ "description": "glsa description",
+ "impact": "glsa impact",
+ "impact_type": "normal",
+ "workaround": "glsa workaround",
+ "resolution": "glsa resolution",
+ "references": "glsa references",
+ "submit": "Submit",
+ }
+
+ # a trivial submit test
+ response = auth.post(
+ f"/edit_glsa/{db.session.query(GLSA).first().glsa_id}",
+ follow_redirects=True,
+ data=glsa_data,
+ )
+
+ assert response.status_code == 200
+
+ # TODO: test for idempotence too
+ response = auth.post(
+ f"/edit_glsa/{db.session.query(GLSA).first().glsa_id}",
+ follow_redirects=True,
+ data=glsa_data,
+ )
+
+ assert response.status_code == 200