def test_updateinfo_repo_unit_nevra_q_filter(self, mock_rpm): # A mongoengine "QCombination" object is used to efficiently search for units # by nevra. This checks that the QCombination object is properly created based # on the errata unit parsed from the test updateinfo XML. with open(os.path.join(DATA_DIR, 'updateinfo.xml'), 'r') as handle: generator = packages.package_list_generator( handle, 'update', updateinfo.process_package_element) erratum_unit = next(generator) context = UpdateinfoXMLFileContext(self.metadata_file_dir) context._repo_unit_nevra(erratum_unit, 'mock_repo') # Call 0 to mock_rpm's filter should have one arg, which should be the QCombination # object that is built with an OR operator, with two children (one for each package # in the errata unit that was passed to the method under test. qcombination = mock_rpm.objects.filter.call_args_list[0][0][0] self.assertTrue(isinstance(qcombination, QCombination)) self.assertEqual(qcombination.operation, qcombination.OR) self.assertEqual(len(qcombination.children), 2)
def test_updateinfo_repo_unit_nevra_q_filter(self, mock_rpm): # A mongoengine "QCombination" object is used to efficiently search for units # by nevra. This checks that the QCombination object is properly created based # on the errata unit parsed from the test updateinfo XML. with open(os.path.join(DATA_DIR, 'updateinfo.xml'), 'r') as handle: generator = packages.package_list_generator( handle, 'update', updateinfo.process_package_element) erratum_unit = next(generator) context = UpdateinfoXMLFileContext(self.metadata_file_dir) context._repo_unit_nevra(erratum_unit, 'mock_repo') # Call 0 to mock_rpm's filter should have one arg, which should be the QCombination # object that is built with an OR operator, with two children (one for each package # in the errata unit that was passed to the method under test. qcombination = mock_rpm.objects.filter.call_args_list[0][0][0] self.assertTrue(isinstance(qcombination, QCombination)) self.assertEqual(qcombination.operation, qcombination.OR) self.assertEqual(len(qcombination.children), 2)
def test_updateinfo_repo_unit_nevra_return(self, mock_rcu, mock_rpm): # Build up the mock data as well as the expected returns nevra_fields = ('name', 'epoch', 'version', 'release', 'arch') unit1_nevra = ('n1', 'e1', 'v1', 'r1', 'a1') unit1_nevra_dict = dict(zip(nevra_fields, unit1_nevra)) unit2_nevra = ('n2', 'e2', 'v2', 'r2', 'a2') unit2_nevra_dict = dict(zip(nevra_fields, unit2_nevra)) # This is the result to the query for all units with a given nevra # The expected value is a list of tuples containing unit ids and nevra fields; mock_rpm.objects.filter().scalar.return_value = [ ('id1', ) + unit1_nevra, ('id2', ) + unit2_nevra, ] # The expected value here is a list of unit IDs from the previous query that are # associated with our mock repo. mock_rcu.objects.filter().scalar.return_value = ['id1'] # Load the updateinfo XML to get an erratum unit to process with open(os.path.join(DATA_DIR, 'updateinfo.xml'), 'r') as handle: generator = packages.package_list_generator( handle, 'update', updateinfo.process_package_element) erratum_unit = next(generator) context = UpdateinfoXMLFileContext(self.metadata_file_dir) repo_unit_nevra = context._repo_unit_nevra(erratum_unit, 'mock_repo') # Call 0 created the scalar mock, so we're interested in call 1. In this case, check # that filter was called at least once with the expected filter kwargs and values. mock_rcu.objects.filter.assert_any_call(unit_id__in=['id2', 'id1'], repo_id='mock_repo') # And finally, make sure the return value is actually good! # We made the RPM mock simulate two units known to pulp with the nevra seen in our errata. # Then, we made the RepositoryContentUnit mock simulate that only one of those units is # associated with the passed-in repo. The return value should be a list with only the # single matching unit's nevra dict in it. self.assertEqual(len(repo_unit_nevra), 1) self.assertTrue(unit1_nevra_dict in repo_unit_nevra) self.assertTrue(unit2_nevra_dict not in repo_unit_nevra)
def test_updateinfo_repo_unit_nevra_return(self, mock_rcu, mock_rpm): # Build up the mock data as well as the expected returns nevra_fields = ('name', 'epoch', 'version', 'release', 'arch') unit1_nevra = ('n1', 'e1', 'v1', 'r1', 'a1') unit1_nevra_dict = dict(zip(nevra_fields, unit1_nevra)) unit2_nevra = ('n2', 'e2', 'v2', 'r2', 'a2') unit2_nevra_dict = dict(zip(nevra_fields, unit2_nevra)) # This is the result to the query for all units with a given nevra # The expected value is a list of tuples containing unit ids and nevra fields; mock_rpm.objects.filter().scalar.return_value = [ ('id1',) + unit1_nevra, ('id2',) + unit2_nevra, ] # The expected value here is a list of unit IDs from the previous query that are # associated with our mock repo. mock_rcu.objects.filter().scalar.return_value = ['id1'] # Load the updateinfo XML to get an erratum unit to process with open(os.path.join(DATA_DIR, 'updateinfo.xml'), 'r') as handle: generator = packages.package_list_generator( handle, 'update', updateinfo.process_package_element) erratum_unit = next(generator) context = UpdateinfoXMLFileContext(self.metadata_file_dir) repo_unit_nevra = context._repo_unit_nevra(erratum_unit, 'mock_repo') # Call 0 created the scalar mock, so we're interested in call 1. In this case, check # that filter was called at least once with the expected filter kwargs and values. mock_rcu.objects.filter.assert_any_call(unit_id__in=['id2', 'id1'], repo_id='mock_repo') # And finally, make sure the return value is actually good! # We made the RPM mock simulate two units known to pulp with the nevra seen in our errata. # Then, we made the RepositoryContentUnit mock simulate that only one of those units is # associated with the passed-in repo. The return value should be a list with only the # single matching unit's nevra dict in it. self.assertEqual(len(repo_unit_nevra), 1) self.assertTrue(unit1_nevra_dict in repo_unit_nevra) self.assertTrue(unit2_nevra_dict not in repo_unit_nevra)