mirror of
https://github.com/openSUSE/osc.git
synced 2025-08-03 06:03:41 +02:00
Fix handling SimpleFlag model
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
from ..util.models import * # pylint: disable=wildcard-import,unused-wildcard-import
|
||||
from xml.etree import ElementTree as ET
|
||||
|
||||
|
||||
class SimpleFlag(XmlModel):
|
||||
XML_TAG = None
|
||||
XML_TAG_FIELD = "flag"
|
||||
|
||||
def __init__(self, flag, **kwargs):
|
||||
super().__init__(flag=flag, **kwargs)
|
||||
@@ -13,7 +13,6 @@ class SimpleFlag(XmlModel):
|
||||
DISABLE = "disable"
|
||||
|
||||
flag: SimpleFlagChoices = Field(
|
||||
xml_wrapped=True,
|
||||
xml_set_tag=True,
|
||||
)
|
||||
|
||||
@@ -22,3 +21,7 @@ class SimpleFlag(XmlModel):
|
||||
return self.flag == other.flag
|
||||
# allow comparing with a string
|
||||
return self.flag == other
|
||||
|
||||
@classmethod
|
||||
def from_xml(cls, root: ET.Element, *, apiurl: Optional[str] = None):
|
||||
return cls(flag=root[0].tag)
|
||||
|
@@ -3,6 +3,7 @@ import textwrap
|
||||
import unittest
|
||||
|
||||
from osc.util.models import *
|
||||
from osc.obs_api.simple_flag import SimpleFlag
|
||||
|
||||
|
||||
class TestXmlModel(unittest.TestCase):
|
||||
@@ -217,6 +218,27 @@ class TestXmlModel(unittest.TestCase):
|
||||
).strip()
|
||||
self.assertRaises(TypeError, TestModel.from_string, data)
|
||||
|
||||
def test_simple_flag(self):
|
||||
class TestModel(XmlModel):
|
||||
XML_TAG = "model"
|
||||
simple_flag: Optional[SimpleFlag] = Field(
|
||||
xml_wrapped=True,
|
||||
)
|
||||
|
||||
data = textwrap.dedent(
|
||||
"""
|
||||
<model>
|
||||
<simple_flag>
|
||||
<enable />
|
||||
</simple_flag>
|
||||
</model>
|
||||
"""
|
||||
).strip()
|
||||
|
||||
m = TestModel.from_string(data)
|
||||
self.assertEqual(m.simple_flag, "enable")
|
||||
self.assertEqual(data, m.to_string())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
Reference in New Issue
Block a user