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

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