refactoring
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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>'])
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user