Example #1
0
    def test_creates_runs1(self, submit_job):
        """
        Test that sending data through the API view 'post' method starts a Run
        Checks to make sure that a Run is successfully created
        """
        # Load fixtures
        test_files_fixture = os.path.join(settings.TEST_FIXTURE_DIR,
                                          "10075_D_single_TN_pair.file.json")
        call_command("loaddata", test_files_fixture, verbosity=0)
        test_files_fixture = os.path.join(
            settings.TEST_FIXTURE_DIR,
            "10075_D_single_TN_pair.filemetadata.json")
        call_command("loaddata", test_files_fixture, verbosity=0)
        test_files_fixture = os.path.join(settings.TEST_FIXTURE_DIR,
                                          "argos_reference_files.json")
        call_command("loaddata", test_files_fixture, verbosity=0)

        number_of_runs = len(Run.objects.all())
        self.assertEqual(number_of_runs, 0)

        pipeline_name = "argos"
        request_ids = ["10075_D"]

        request = MockRequest()
        request.data = dict()
        request.data["request_ids"] = request_ids
        request.data["pipeline_name"] = pipeline_name

        view = OperatorViewSet()
        response = view.post(request)

        number_of_runs = len(Run.objects.all())
        self.assertEqual(number_of_runs, 1)
Example #2
0
    def test_create_demo_operator_run(self, submit_job):
        """
        Test case for creating a Demo Operator run
        """
        # there should be no Runs
        self.assertEqual(len(Run.objects.all()), 0)
        self.assertEqual(len(Port.objects.all()), 0)
        self.assertEqual(len(File.objects.all()), 2)
        self.assertEqual(len(FileMetadata.objects.all()), 2)

        # make a fake http request with some data
        # and send it to the API endpoint for starting a run
        request = MockRequest()
        request.data = {
            "request_ids": ["1"],
            "pipeline_name": DemoOperator._pipeline_name
        }
        view = OperatorViewSet()
        response = view.post(request)

        # there should be 1 run now
        self.assertEqual(len(Run.objects.all()), 1)
        self.assertEqual(len(Port.objects.all()), 3)
        self.assertEqual(len(File.objects.all()), 2)
        self.assertEqual(len(FileMetadata.objects.all()), 2)
    def test_post_to_view1(self):
        """
        Test that data sent through the API view 'post' method returns a successful status and expected response
        """
        pipeline_name = 'argos'
        request_ids = ['foo', 'bar']

        request = MockRequest()
        request.data = {}
        request.data['request_ids'] = request_ids
        request.data['pipeline_name'] = pipeline_name

        view = OperatorViewSet()
        response = view.post(request)

        self.assertEqual(response.data, {'details': "Operator Job submitted {}".format(request_ids)})
        self.assertEqual(response.status_code, 200)
Example #4
0
    def test_live_demo_operator_run(self):
        """
        A test case for submitting a job to Ridgeback for the Demo Operator

        Need to enable a specific env var to run this test since it should submit a job to Ridgeback

        Make sure that a Ridgeback instance is running! Set with env var BEAGLE_RIDGEBACK_URL

        This one takes about 3-6min to run on LSF with Ridgeback

        NOTE: see this one also; https://github.com/mskcc/beagle/blob/master/runner/tests/run/test_run.py#L291 RunObjectTest.test_run_complete_job

        Usage
        ------

            $ BEAGLE_RIDGEBACK_URL=http://silo:5003 LIVE_DEMO=1 PRESERVE=1 python manage.py test runner.tests.operator.demo_operator.test_demo_operator.TestDemoOperator.test_live_demo_operator_run
        """
        self.preserve = os.environ.get("PRESERVE")
        enable_testcase = os.environ.get("LIVE_DEMO")
        request_id = "test_live_demo_operator_run"

        if enable_testcase:
            print(">>> running TestDemoOperator.test_live_demo_operator_run")
            print(">>> using RIDGEBACK_URL: ", settings.RIDGEBACK_URL)
            # sanity check: there are no runs to start with
            self.assertEqual(len(OperatorRun.objects.all()), 0)
            self.assertEqual(len(Run.objects.all()), 0)

            # make a file
            path = os.path.join(self.tmpdir, "file.txt")
            with open(path, "w") as f:
                f.write("some data\n")

            # make db entries
            file_instance = File.objects.create(
                file_name=os.path.basename(path),
                path=path,
                file_group=self.filegroup)
            filemetadata_instance = FileMetadata.objects.create(
                file=file_instance, metadata={"requestId": request_id})

            # check the number of files present, there should be two from setUp and a third from this test
            self.assertEqual(len(File.objects.all()), 3)

            # make a request to start the run
            request = MockRequest()
            request.data = {
                "request_ids": [request_id],
                "pipeline_name": DemoOperator._pipeline_name
            }
            view = OperatorViewSet()
            response = view.post(request)
            print(">>> response: ", response, response.data)

            # check the Beagle response code for the submitted run
            self.assertEqual(response.status_code, 200)

            # there should be 1 run now in the Beagle db
            self.assertEqual(len(Run.objects.all()), 1)
            self.assertEqual(len(OperatorRun.objects.all()), 1)

            # get the Run and OperatorRun instances for this run
            run_instance = Run.objects.all().first()
            operator_run_instance = OperatorRun.objects.all().first()

            # wait for the run to finish in Ridgeback
            wait_on_runs(run_instance, operator_run_instance)

            # check for the output from the Run
            print(">>> operator run located at; ", self.tmpdir)
            for port in Port.objects.all():
                pprint(port.__dict__)

            # get the output file
            output_port = Port.objects.get(name="output_file")
            print(output_port.files.all())

            # there should be an extra File object for the output
            self.assertEqual(len(File.objects.all()), 4)
            self.assertEqual(len(output_port.files.all()), 1)

            for file_instance in File.objects.all():
                pprint(file_instance.__dict__, indent=4)