refactoring

This commit is contained in:
frankknoll
2023-10-10 09:12:36 +02:00
parent fde9844b88
commit e457568ef6
4 changed files with 11 additions and 37 deletions

View File

@@ -1,21 +1,7 @@
from bs4 import BeautifulSoup
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
class BatchcodeOptionsSetter:
def setBatchcodeOptions(self, html, options):
soup = self._setBatchcodeOptions(self._parse(html), self._parseOptions(options))
return str(soup)
def _setBatchcodeOptions(self, soup, options):
batchcodeSelect = soup.find(id = "batchCodeSelect")
batchcodeSelect.clear()
for option in options:
batchcodeSelect.append(option)
return soup
def _parseOptions(self, options):
return [self._parse(option).option for option in options]
def _parse(self, html):
return BeautifulSoup(html, 'lxml')
return OptionsSetter().setOptions(html, 'batchCodeSelect', options)

View File

@@ -3,15 +3,15 @@ from bs4 import BeautifulSoup
class OptionsSetter:
def setOptions(self, html, options):
soup = self._setBatchcodeOptions(self._parse(html), self._parseOptions(options))
def setOptions(self, html, selectElementId, options):
soup = self._setOptions(self._parse(html), selectElementId, self._parseOptions(options))
return str(soup)
def _setBatchcodeOptions(self, soup, options):
batchcodeSelect = soup.find(id = "vaccineSelect")
batchcodeSelect.clear()
def _setOptions(self, soup, selectElementId, options):
selectElement = soup.find(id = selectElementId)
selectElement.clear()
for option in options:
batchcodeSelect.append(option)
selectElement.append(option)
return soup
def _parseOptions(self, options):

View File

@@ -21,6 +21,7 @@ class OptionsSetterTest(unittest.TestCase):
</body>
</html>
''',
selectElementId = 'vaccineSelect',
options=[
'<option value="6VAX-F">6VAX-F</option>',
'<option value="ADEN">ADEN</option>'])

View File

@@ -1,21 +1,8 @@
from bs4 import BeautifulSoup
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
class KreisOptionsSetter:
def setKreisOptions(self, html, options):
soup = self._setKreisOptions(self._parse(html), self._parseOptions(options))
return str(soup)
def _setKreisOptions(self, soup, options):
kreisSelect = soup.find(id = "kreisSelect")
kreisSelect.clear()
for option in options:
kreisSelect.append(option)
return soup
def _parseOptions(self, options):
return [self._parse(option).option for option in options]
def _parse(self, html):
return BeautifulSoup(html, 'lxml')
return OptionsSetter().setOptions(html, 'kreisSelect', options)