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

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