Blame SOURCES/0003-Do-not-skip-type-mandatory-in-xml-output-and-test-it-RhBu1771224.patch

d63d71
From be21c727509e252859d7850f7d7ec06c51ba15b3 Mon Sep 17 00:00:00 2001
d63d71
From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= <amatej@redhat.com>
d63d71
Date: Mon, 6 Jan 2020 12:08:00 +0100
d63d71
Subject: [PATCH] Do not skip type=mandatory in xml output and test it
d63d71
 (RhBug:1771224)
d63d71
d63d71
The mandatory type is used when no other configuration and no other
d63d71
type is specified but since this behavior can be overridden with passed
d63d71
configuration it doesn't make sense to always skip outputting the type
d63d71
mandatory.
d63d71
The user can specify for example optional type as default and then
d63d71
the knowledge that some specific <packagereq> were mandatory would be
d63d71
lost.
d63d71
d63d71
https://bugzilla.redhat.com/show_bug.cgi?id=1771224
d63d71
---
d63d71
 libcomps/src/comps_docpackage.c     |  5 +++--
d63d71
 libcomps/src/python/tests/__test.py | 10 +++++++++-
d63d71
 2 files changed, 12 insertions(+), 3 deletions(-)
d63d71
d63d71
diff --git a/libcomps/src/comps_docpackage.c b/libcomps/src/comps_docpackage.c
d63d71
index 25d8564..f2d6bae 100644
d63d71
--- a/libcomps/src/comps_docpackage.c
d63d71
+++ b/libcomps/src/comps_docpackage.c
d63d71
@@ -164,8 +164,9 @@ signed char comps_docpackage_xml(COMPS_DocGroupPackage *pkg,
d63d71
         str = "conditional";
d63d71
     else
d63d71
         str = "default";
d63d71
-    if (pkg->type != COMPS_PACKAGE_MANDATORY)
d63d71
-        ret = xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST str);
d63d71
+
d63d71
+    ret = xmlTextWriterWriteAttribute(writer, BAD_CAST "type", BAD_CAST str);
d63d71
+
d63d71
     if (pkg->requires) {
d63d71
         str = comps_object_tostr((COMPS_Object*)pkg->requires);
d63d71
         ret = xmlTextWriterWriteAttribute(writer, (xmlChar*) "requires",
d63d71
diff --git a/libcomps/src/python/tests/__test.py b/libcomps/src/python/tests/__test.py
d63d71
index c7529f3..9cb957a 100644
d63d71
--- a/libcomps/src/python/tests/__test.py
d63d71
+++ b/libcomps/src/python/tests/__test.py
d63d71
@@ -620,6 +620,14 @@ def test_hash(self):
d63d71
         self.assertTrue(hash(pkg2) != hash(pkg3))
d63d71
         self.assertTrue(len(set([pkg1,pkg2,pkg3])) == 2)
d63d71
 
d63d71
+    def test_mandatory_in_xml_out(self):
d63d71
+        self.comps = libcomps.Comps()
d63d71
+        self.comps.groups.append(libcomps.Group("g1", "group1", "group desc", 0, 0, 0, "en"))
d63d71
+        self.comps.groups[0].packages.append(libcomps.Package("kernel", libcomps.PACKAGE_TYPE_MANDATORY))
d63d71
+
d63d71
+        out = self.comps.xml_str()
d63d71
+        self.assertTrue("<packagereq type=\"mandatory\" requires=\"\">kernel</packagereq>" in out)
d63d71
+
d63d71
 #@unittest.skip("skip")
d63d71
 class DictTest(unittest.TestCase):
d63d71
     def test_dict(self):
d63d71
@@ -998,7 +1006,7 @@ def test_xml_options(self):
d63d71
         self.assertEqual(len(comps2.groups), 0)
d63d71
         self.assertEqual(len(comps2.categories), 0)
d63d71
         self.assertEqual(len(comps2.environments), 0)
d63d71
-        
d63d71
+
d63d71
         s = comps.toxml_str(xml_options={"empty_groups": True,
d63d71
                                      "empty_categories": True,
d63d71
                                      "empty_environments": True})