Esempio n. 1
0
def mark_completed_hidden(request, unit_type):
    """Marks all units of type ``unit_type`` as hidden, if and only if the unit
    is completed or failed. This is what happens when the user clicks the
    "Remove all completed" button in the dashboard GUI.

    This endpoint assumes you are already logged in.

    :param unit_type: 'transfer' or 'ingest' for hiding of Transfers or SIPs,
        respectively
    """
    if request.method not in ("DELETE", ):
        return django.http.HttpResponseNotAllowed(["DELETE"])
    try:
        completed = helpers.completed_units_efficient(unit_type=unit_type)
        if completed:
            if unit_type == "transfer":
                unit_model = models.Transfer
            elif unit_type == "ingest":
                unit_model = models.SIP
            unit_model.objects.filter(uuid__in=completed).update(hidden=True)
        response = {"removed": completed}
        return helpers.json_response(response)
    except Exception:
        LOGGER.debug("Error setting completed %s units to hidden",
                     unit_type,
                     exc_info=True)
        raise django.http.Http404
Esempio n. 2
0
 def test_get_unit_status_rejected(self):
     """It should return REJECTED."""
     # Setup fixtures
     load_fixture(['jobs-processing.json', 'jobs-rejected.json'])
     # Test
     status = views.get_unit_status('3e1e56ed-923b-4b53-84fe-c5c1c0b0cf8e',
                                    'unitTransfer')
     completed = helpers.completed_units_efficient(unit_type='transfer',
                                                   include_failed=True)
     # Verify
     assert len(status) == 2
     assert 'microservice' in status
     assert status['status'] == 'REJECTED'
     assert len(completed) == 0
Esempio n. 3
0
 def test_get_unit_status_backlog(self):
     """It should return COMPLETE and in BACKLOG."""
     # Setup fixtures
     load_fixture(['jobs-processing.json', 'jobs-transfer-backlog.json'])
     # Test
     status = views.get_unit_status('3e1e56ed-923b-4b53-84fe-c5c1c0b0cf8e',
                                    'unitTransfer')
     completed = helpers.completed_units_efficient(unit_type='transfer',
                                                   include_failed=True)
     # Verify
     assert len(status) == 3
     assert 'microservice' in status
     assert status['status'] == 'COMPLETE'
     assert status['sip_uuid'] == 'BACKLOG'
     assert len(completed) == 1
Esempio n. 4
0
 def test_get_unit_status_completed_transfer(self):
     """It should return COMPLETE and the new SIP UUID."""
     # Setup fixtures
     load_fixture([
         'jobs-processing.json', 'jobs-transfer-complete.json', 'files.json'
     ])
     # Test
     status = views.get_unit_status('3e1e56ed-923b-4b53-84fe-c5c1c0b0cf8e',
                                    'unitTransfer')
     completed = helpers.completed_units_efficient(unit_type='transfer',
                                                   include_failed=True)
     # Verify
     assert len(status) == 3
     assert 'microservice' in status
     assert status['status'] == 'COMPLETE'
     assert status['sip_uuid'] == '4060ee97-9c3f-4822-afaf-ebdf838284c3'
     assert len(completed) == 1
Esempio n. 5
0
 def test_get_unit_status_completed_sip(self):
     """It should return COMPLETE."""
     # Setup fixtures
     load_fixture([
         'jobs-processing.json', 'jobs-transfer-complete.json',
         'jobs-sip-complete.json'
     ])
     # Test
     status = views.get_unit_status('4060ee97-9c3f-4822-afaf-ebdf838284c3',
                                    'unitSIP')
     completed = helpers.completed_units_efficient(unit_type='transfer',
                                                   include_failed=True)
     # Verify
     assert len(status) == 2
     assert 'microservice' in status
     assert status['status'] == 'COMPLETE'
     assert len(completed) == 1
Esempio n. 6
0
 def test_get_unit_status_multiple(self):
     """When the database contains 5 units of the following types:
     1. a failed transfer b949773d-7cf7-4c1e-aea5-ccbf65b70ccd
     2. a completed transfer 85216028-1150-4321-abb3-31ea570a341b
     3. a rejected transfer c9cce131-7bd9-41c8-82ab-483190961ae2
     4. a transfer awaiting user input 37a07d96-6fc0-4002-b269-471a58783805
     5. a transfer in backlog 5d0ab97f-a45b-4e0f-9cb6-90ee3a404549
     then ``completed_units_efficient`` should return 3: the failed,
     the completed, and the in-backlog transfer.
     """
     load_fixture(['jobs-various.json'])
     completed = helpers.completed_units_efficient(unit_type='transfer',
                                                   include_failed=True)
     print(completed)
     assert len(completed) == 3
     assert '85216028-1150-4321-abb3-31ea570a341b' in completed
     assert '5d0ab97f-a45b-4e0f-9cb6-90ee3a404549' in completed
     assert 'b949773d-7cf7-4c1e-aea5-ccbf65b70ccd' in completed