def test_post(self, _reserve_resource, mock_apply_async):
        # Setup
        task_id = str(uuid.uuid4())
        mock_apply_async.return_value = AsyncResult(task_id)
        _reserve_resource.return_value = ReservedResourceApplyAsync()
        upload_id = self.upload_manager.initialize_upload()
        self.upload_manager.save_data(upload_id, 0, 'string data')

        repo_manager = manager_factory.repo_manager()
        repo_manager.create_repo('repo-upload')
        importer_manager = manager_factory.repo_importer_manager()
        importer_manager.set_importer('repo-upload', 'dummy-importer', {})

        # Test
        body = {
            'upload_id' : upload_id,
            'unit_type_id' : 'dummy-type',
            'unit_key' : {'name' : 'foo'},
            'unit_metadata' : {'stuff' : 'bar'},
        }
        status, body = self.post('/v2/repositories/repo-upload/actions/import_upload/', body)

        # Verify
        self.assertEqual(202, status)
        assert_body_matches_async_task(body, mock_apply_async.return_value)
        exepcted_call_args = ['repo-upload', 'dummy-type',
                              {'name': 'foo'}, {'stuff': 'bar'}, 
                              upload_id]
        self.assertEqual(exepcted_call_args, mock_apply_async.call_args[0][0])
    def test_post_with_override_config(self, mock_get_worker_for_reservation, mock_uuid,
                                       mock_apply_async):
        # Setup
        uuid_list = [uuid.uuid4() for i in range(10)]
        mock_uuid.uuid4.side_effect = copy.deepcopy(uuid_list)
        expected_async_result = AsyncResult(str(uuid_list[0]))
        mock_get_worker_for_reservation.return_value = Worker('some_queue', datetime.datetime.now())
        upload_id = self.upload_manager.initialize_upload()
        self.upload_manager.save_data(upload_id, 0, 'string data')

        repo_manager = manager_factory.repo_manager()
        repo_manager.create_repo('repo-upload')
        importer_manager = manager_factory.repo_importer_manager()
        importer_manager.set_importer('repo-upload', 'dummy-importer', {})

        # Test
        test_override_config = {'key1': 'value1', 'key2': 'value2'}
        body = {
            'upload_id' : upload_id,
            'unit_type_id' : 'dummy-type',
            'unit_key' : {'name' : 'foo'},
            'unit_metadata' : {'stuff' : 'bar'},
            'override_config': test_override_config,
        }
        status, body = self.post('/v2/repositories/repo-upload/actions/import_upload/', body)

        # Verify
        self.assertEqual(202, status)
        assert_body_matches_async_task(body, expected_async_result)
        exepcted_call_args = ['repo-upload', 'dummy-type',
                              {'name': 'foo'}, {'stuff': 'bar'},
                              upload_id, test_override_config]
        self.assertEqual(exepcted_call_args, mock_apply_async.call_args[0][0])
Beispiel #3
0
 def test_successful_match(self):
     body = {
         'spawned_tasks': [
             {
                 'task_id': "foo"
             },
         ]
     }
     task = Mock()
     task.id = "foo"
     util.assert_body_matches_async_task(body, task)
    def test_post(self, _reserve_resource, mock_apply_async):
        # Setup
        task_id = str(uuid.uuid4())
        mock_apply_async.return_value = AsyncResult(task_id)
        _reserve_resource.return_value = ReservedResourceApplyAsync()
        upload_id = self.upload_manager.initialize_upload()
        self.upload_manager.save_data(upload_id, 0, 'string data')

        repo_manager = manager_factory.repo_manager()
        repo_manager.create_repo('repo-upload')
        importer_manager = manager_factory.repo_importer_manager()
        importer_manager.set_importer('repo-upload', 'dummy-importer', {})

        # Test
        body = {
            'upload_id': upload_id,
            'unit_type_id': 'dummy-type',
            'unit_key': {
                'name': 'foo'
            },
            'unit_metadata': {
                'stuff': 'bar'
            },
        }
        status, body = self.post(
            '/v2/repositories/repo-upload/actions/import_upload/', body)

        # Verify
        self.assertEqual(202, status)
        assert_body_matches_async_task(body, mock_apply_async.return_value)
        exepcted_call_args = [
            'repo-upload', 'dummy-type', {
                'name': 'foo'
            }, {
                'stuff': 'bar'
            }, upload_id
        ]
        self.assertEqual(exepcted_call_args, mock_apply_async.call_args[0][0])
Beispiel #5
0
 def test_successful_match(self):
     body = {"spawned_tasks": [{"task_id": "foo"}]}
     task = Mock()
     task.id = "foo"
     util.assert_body_matches_async_task(body, task)
Beispiel #6
0
 def test_successful_match(self):
     body = {'spawned_tasks': [{'task_id': "foo"}, ]}
     task = Mock()
     task.id = "foo"
     util.assert_body_matches_async_task(body, task)