Exemplo n.º 1
0
Arquivo: tests.py Projeto: 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", "*****@*****.**", password="******")
        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="*****@*****.**"))
        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", "*****@*****.**", "test-q", "https://" + pc._hostname + "/api/v1/collection/1/"]
            )
Exemplo n.º 2
0
Arquivo: tests.py Projeto: ucldc/avram
 def test_queue_harvest_integration(self):
     pc = Collection.objects.all()[0]
     u = User.objects.create_user("test", "*****@*****.**", password="******")
     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, "*****@*****.**", "https://" + socket.getfqdn() + "/api/v1/collection/1/"]
         )