Ejemplo n.º 1
0
Archivo: tests.py Proyecto: ucldc/avram
    def test_queue_harvest_function(self, mock_modeladmin):
        """
        Test of harvest starting function. Kicks off a "harvest" for the
        given collection.
        """
        pc = Collection.objects.all()[0]
        u = User.objects.create_user("test", "[email protected]", password="fake")
        library_collection.admin_actions.HARVEST_SCRIPT = "xxxxx"
        pc.url_harvest = "http://example.com/oai"
        pc.harvest_extra_data = "testset"
        pc.save()
        self.assertRaises(TypeError, queue_harvest, u, pc, "test-q")

        class Bunch(object):
            def __init__(self, **kwargs):
                self.__dict__.update(kwargs)

        request = Bunch(user=Bunch(email="[email protected]"))
        pc.harvest_type = "OAC"
        retVal = queue_harvest(mock_modeladmin, request, [pc], "test-q")
        self.assertEqual(retVal[0], "Cannot find xxxxx for running 1 collections On demand " "patron requests")
        self.assertEqual(retVal[1], False)
        with patch("subprocess.Popen") as mock_subprocess:
            retVal = queue_harvest(mock_modeladmin, request, [pc], "test-q")
            self.assertTrue(mock_subprocess.called)
            mock_subprocess.assert_called_with(
                ["xxxxx", "[email protected]", "test-q", "https://" + pc._hostname + "/api/v1/collection/1/"]
            )
Ejemplo n.º 2
0
Archivo: tests.py Proyecto: ucldc/avram
 def test_queue_harvest_integration(self):
     pc = Collection.objects.all()[0]
     u = User.objects.create_user("test", "[email protected]", password="fake")
     pc.url_harvest = "http://example.com/oai"
     pc.harvest_extra_data = "testset"
     pc.save()
     retVal = queue_harvest(u, pc, "test-queue")
     self.assertTrue(isinstance(retVal, int))
     with patch("subprocess.Popen") as mock_subprocess:
         retVal = queue_harvest(u, "test-queue")
         self.assertTrue(mock_subprocess.called)
         mock_subprocess.assert_called_with(
             [pc.harvest_script, "[email protected]", "https://" + socket.getfqdn() + "/api/v1/collection/1/"]
         )