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: class BatchcodeOptionsSetter:
def setBatchcodeOptions(self, html, options): def setBatchcodeOptions(self, html, options):
soup = self._setBatchcodeOptions(self._parse(html), self._parseOptions(options)) return OptionsSetter().setOptions(html, 'batchCodeSelect', 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')

View File

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

View File

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

View File

@@ -1,21 +1,8 @@
from bs4 import BeautifulSoup from bs4 import BeautifulSoup
from SymptomsCausedByVaccines.OptionsSetter import OptionsSetter
class KreisOptionsSetter: class KreisOptionsSetter:
def setKreisOptions(self, html, options): def setKreisOptions(self, html, options):
soup = self._setKreisOptions(self._parse(html), self._parseOptions(options)) return OptionsSetter().setOptions(html, 'kreisSelect', 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')