From 0d679fdaa3bb202eed7e77eb4112ac05f5e7c49b Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Thu, 22 Dec 2022 19:42:53 +0100 Subject: Fix tests --- archaeological_operations/tests.py | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) (limited to 'archaeological_operations/tests.py') diff --git a/archaeological_operations/tests.py b/archaeological_operations/tests.py index a9fe8760e..7bc51539d 100644 --- a/archaeological_operations/tests.py +++ b/archaeological_operations/tests.py @@ -16,6 +16,7 @@ # along with this program. If not, see . # See the file COPYING for details. +from bs4 import BeautifulSoup import json import datetime from subprocess import Popen, PIPE @@ -4041,10 +4042,16 @@ class DocumentTest(OperationInitTest, TestCase): c.login(username=self.username, password=self.password) response = c.get(url, {"operation": self.operation.pk}) self.assertEqual(response.status_code, 200) - self.assertIn( - 'option value="{}" selected'.format(self.operation.pk), - response.content.decode(), - ) + + result = response.content.decode() + soup = BeautifulSoup(result, "lxml") + ok = False + for field in soup.findAll("option"): + keys = list(field.attrs.keys()) + if "selected" in keys and "value" in keys and field["value"] == str(self.operation.pk): + ok = True + break + self.assertTrue(ok, msg="Operation not selected in Document form") posted = {"authors": []} for related_key in models.Document.RELATED_MODELS: @@ -4079,10 +4086,16 @@ class DocumentTest(OperationInitTest, TestCase): c.login(username=self.username, password=self.password) response = c.get(url) self.assertEqual(response.status_code, 200) - self.assertIn( - 'option value="{}" selected'.format(self.operation.pk), - response.content.decode(), - ) + + result = response.content.decode() + soup = BeautifulSoup(result, "lxml") + ok = False + for field in soup.findAll("option"): + keys = list(field.attrs.keys()) + if "selected" in keys and "value" in keys and field["value"] == str(self.operation.pk): + ok = True + break + self.assertTrue(ok, msg="Operation not selected in Document form") posted = {"authors": [], "title": "hop2-is-back"} for related_key in models.Document.RELATED_MODELS: -- cgit v1.2.3