示例#1
0
    def test_missing(self):
        """Tests calling the source files view with an invalid id or file name."""

        url = rest_util.get_url('/sources/12345/')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, response.content)

        url = rest_util.get_url('/sources/missing_file.txt/')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, response.content)
示例#2
0
    def test_edit_config(self):
        """Tests editing the configuration of a workspace"""

        config = {
            'version': '1.0',
            'broker': {
                'type': 'nfs',
                'nfs_path': 'host:/dir',
            },
        }

        json_data = {
            'json_config': config,
        }

        url = rest_util.get_url('/workspaces/%d/' % self.workspace.id)
        response = self.client.generic('PATCH', url, json.dumps(json_data), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(result['id'], self.workspace.id)
        self.assertEqual(result['title'], self.workspace.title)
        self.assertDictEqual(result['json_config'], config)

        workspace = Workspace.objects.get(pk=self.workspace.id)
        self.assertEqual(workspace.title, self.workspace.title)
        self.assertDictEqual(workspace.json_config, config)
示例#3
0
    def test_edit_simple(self):
        """Tests editing only the basic attributes of a workspace"""

        json_data = {
            'title': 'Title EDIT',
            'description': 'Description EDIT',
            'is_active': False,
        }

        url = rest_util.get_url('/workspaces/%d/' % self.workspace.id)
        response = self.client.generic('PATCH', url, json.dumps(json_data), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertTrue(isinstance(result, dict), 'result  must be a dictionary')
        self.assertEqual(result['id'], self.workspace.id)
        self.assertEqual(result['title'], 'Title EDIT')
        self.assertEqual(result['description'], 'Description EDIT')
        self.assertDictEqual(result['json_config'], self.workspace.json_config)
        self.assertFalse(result['is_active'])

        workspace = Workspace.objects.get(pk=self.workspace.id)
        self.assertEqual(workspace.title, 'Title EDIT')
        self.assertEqual(workspace.description, 'Description EDIT')
        self.assertFalse(result['is_active'])
示例#4
0
    def test_successful(self):
        """Tests calling the create Workspace view successfully."""

        json_data = {
            'name': 'ws-name',
            'title': 'Workspace Title',
            'description': 'Workspace description',
            'base_url': 'http://host/my/path/',
            'is_active': False,
            'json_config': {
                'broker': {
                    'type': 'host',
                    'host_path': '/host/path',
                },
            },
        }

        url = rest_util.get_url('/workspaces/')
        response = self.client.generic('POST', url, json.dumps(json_data), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content)

        workspaces = Workspace.objects.filter(name='ws-name')
        self.assertEqual(len(workspaces), 1)

        result = json.loads(response.content)
        self.assertEqual(result['title'], workspaces[0].title)
        self.assertEqual(result['description'], workspaces[0].description)
        self.assertDictEqual(result['json_config'], workspaces[0].json_config)
        self.assertEqual(result['base_url'], workspaces[0].base_url)
        self.assertEqual(result['is_active'], workspaces[0].is_active)
        self.assertFalse(workspaces[0].is_active)
示例#5
0
    def test_max_duration(self):
        """Tests calling the job load view with time values that define a range greater than 31 days"""

        url = rest_util.get_url("/load/?started=2015-01-01T00:00:00Z&ended=2015-02-02T00:00:00Z")
        response = self.client.generic("GET", url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#6
0
    def test_not_found(self):
        """Tests successfully calling the get batch details view with a batch id that does not exist."""

        url = rest_util.get_url('/batches/100/')
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, response.content)
示例#7
0
    def test_invalid_ended(self):
        """Tests calling the source file updates view when the ended parameter is invalid."""

        url = rest_util.get_url('/sources/updates/?started=1970-01-01T00:00:00Z&ended=hello')
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#8
0
    def test_missing_tz_ended(self):
        """Tests calling the source files view when the ended parameter is missing timezone."""

        url = rest_util.get_url('/sources/?started=1970-01-01T00:00:00Z&ended=1970-01-02T00:00:00')
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#9
0
    def test_get_error_not_found(self):
        """Test calling the Get Error method with a bad error id."""

        url = rest_util.get_url('/errors/9999/')
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, response.content)
示例#10
0
    def test_warnings(self):
        """Tests validating a new workspace where the broker type is changed."""

        json_config = {
            'broker': {
                'type': 'host',
                'host_path': '/host/path',
            },
        }
        storage_test_utils.create_workspace(name='ws-test', json_config=json_config)

        json_data = {
            'name': 'ws-test',
            'json_config': {
                'broker': {
                    'type': 'nfs',
                    'nfs_path': 'host:/dir',
                },
            },
        }

        url = rest_util.get_url('/workspaces/validation/')
        response = self.client.generic('POST', url, json.dumps(json_data), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        results = json.loads(response.content)
        self.assertEqual(len(results['warnings']), 1)
        self.assertEqual(results['warnings'][0]['id'], 'broker_type')
示例#11
0
    def test_not_found(self):
        """Tests calling the recipe type details view with an id that does not exist."""

        url = rest_util.get_url('/recipe-types/100/')
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, response.content)
示例#12
0
    def test_negative_time_range(self):
        """Tests calling the source files view with a negative time range."""

        url = rest_util.get_url('/sources/?started=1970-01-02T00:00:00Z&ended=1970-01-01T00:00:00')
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#13
0
    def test_create(self):
        """Tests creating a new batch."""
        json_data = {
            'recipe_type_id': self.recipe_type1.id,
            'title': 'batch-title-test',
            'description': 'batch-description-test',
            'definition': {
                'version': '1.0',
                'all_jobs': True,
            },
        }

        url = rest_util.get_url('/batches/')
        response = self.client.generic('POST', url, json.dumps(json_data), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content)

        batch = Batch.objects.filter(title='batch-title-test').first()

        result = json.loads(response.content)
        self.assertEqual(result['id'], batch.id)
        self.assertEqual(result['title'], 'batch-title-test')
        self.assertEqual(result['description'], 'batch-description-test')
        self.assertEqual(result['recipe_type']['id'], self.recipe_type1.id)
        self.assertIsNotNone(result['event'])
        self.assertIsNotNone(result['creator_job'])
        self.assertIsNotNone(result['definition'])
示例#14
0
    def test_create(self):
        """Tests creating a new recipe type."""
        json_data = {
            'name': 'recipe-type-post-test',
            'version': '1.0.0',
            'title': 'Recipe Type Post Test',
            'description': 'This is a test.',
            'definition': {
                'version': '1.0',
                'input_data': [{
                    'name': 'input_file',
                    'type': 'file',
                    'media_types': ['image/x-hdf5-image'],
                }],
                'jobs': [],
            }
        }

        url = rest_util.get_url('/recipe-types/')
        response = self.client.generic('POST', url, json.dumps(json_data), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content)

        recipe_type = RecipeType.objects.filter(name='recipe-type-post-test').first()

        results = json.loads(response.content)
        self.assertEqual(results['id'], recipe_type.id)
        self.assertIsNone(results['trigger_rule'])
示例#15
0
    def test_edit_definition_and_trigger_rule(self):
        """Tests editing the recipe type definition and trigger rule together"""
        definition = self.definition.copy()
        definition['input_data'] = [{
            'name': 'input_file',
            'type': 'file',
            'media_types': ['text/plain'],
        }]
        trigger_config = self.trigger_config.copy()
        trigger_config['condition']['media_type'] = 'application/json'

        json_data = {
            'definition': definition,
            'trigger_rule': {
                'type': 'PARSE',
                'configuration': trigger_config,
            }
        }

        url = rest_util.get_url('/recipe-types/%d/' % self.recipe_type.id)
        response = self.client.generic('PATCH', url, json.dumps(json_data), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(result['id'], self.recipe_type.id)
        self.assertEqual(result['title'], self.recipe_type.title)
        self.assertEqual(result['revision_num'], 2)
        self.assertEqual(len(result['definition']['input_data']), 1)
        self.assertEqual(result['definition']['input_data'][0]['name'], 'input_file')
        self.assertEqual(result['trigger_rule']['configuration']['condition']['media_type'], 'application/json')
        self.assertNotEqual(result['trigger_rule']['id'], self.trigger_rule.id)
示例#16
0
    def test_bad_trigger_config(self):
        """Tests validating a new recipe type with an invalid trigger rule configuration."""
        json_data = {
            'name': 'recipe-type-post-test',
            'version': '1.0.0',
            'description': 'This is a test.',
            'definition': {
                'version': '1.0',
                'input_data': [{
                    'name': 'input_file',
                    'type': 'file',
                    'media_types': ['image/x-hdf5-image'],
                }],
                'jobs': [],
            },
            'trigger_rule': {
                'type': 'PARSE',
                'configuration': {
                    'BAD': '1.0',
                }
            }
        }

        url = rest_util.get_url('/recipe-types/validation/')
        response = self.client.generic('POST', url, json.dumps(json_data), 'application/json')

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#17
0
    def test_invalid_started(self):
        """Tests calling the product files view when the started parameter is invalid."""

        url = rest_util.get_url('/products/?started=hello')
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#18
0
    def test_negative_time_range(self):
        """Tests calling the source products view with a negative time range."""

        url = '/sources/%d/products/?started=1970-01-02T00:00:00Z&ended=1970-01-01T00:00:00' % self.src_file.id
        url = rest_util.get_url(url)
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#19
0
    def test_missing_tz_ended(self):
        """Tests calling the source products view when the ended parameter is missing timezone."""

        url = '/sources/%d/products/?started=1970-01-01T00:00:00Z&ended=1970-01-02T00:00:00' % self.src_file.id
        url = rest_util.get_url(url)
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#20
0
    def test_list_all(self):
        """Tests getting a list of recipe types."""
        url = rest_util.get_url('/recipe-types/')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        results = json.loads(response.content)
        self.assertEqual(len(results['results']), 2)
示例#21
0
    def test_invalid_product_id(self):
        """Tests calling the product file source products view when the source ID is invalid."""

        url = rest_util.get_url('/products/12345678/sources/')
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         response.content)
示例#22
0
    def test_not_found(self):
        """Tests successfully calling the get Scan process details view with a model id that does not exist."""

        url = rest_util.get_url('/scans/100/')
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         response.content)
示例#23
0
    def test_not_found(self):
        """Tests calling the recipe type details view with an id that does not exist."""

        url = rest_util.get_url('/recipe-types/100/')
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         response.content)
示例#24
0
    def test_update_node_no_fields(self):
        """Test calling the Update Node method with no fields."""

        json_data = {}
        url = rest_util.get_url('/nodes/%d/' % self.node2.id)
        response = self.client.patch(url, json.dumps(json_data), 'application/json')

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#25
0
    def test_get_error_not_found(self):
        """Test calling the Get Error method with a bad error id."""

        url = rest_util.get_url('/errors/9999/')
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         response.content)
示例#26
0
    def test_invalid_started(self):
        """Tests calling the product files view when the started parameter is invalid."""

        url = rest_util.get_url('/products/?started=hello')
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.content)
示例#27
0
    def test_missing_tz_started(self):
        """Tests calling the product files view when the started parameter is missing timezone."""

        url = rest_util.get_url('/products/?started=1970-01-01T00:00:00')
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.content)
示例#28
0
    def test_list_all(self):
        """Tests getting a list of recipe types."""
        url = rest_util.get_url('/recipe-types/')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        results = json.loads(response.content)
        self.assertEqual(len(results['results']), 2)
示例#29
0
    def test_nodes_view(self):
        """ test the REST call to retrieve an empty list of nodes"""
        url = rest_util.get_url('/nodes/')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        results = json.loads(response.content)
        self.assertEqual(len(results['results']), 0)
示例#30
0
    def test_success(self):
        """Test getting overall version/build information successfully"""
        url = rest_util.get_url('/version/')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertIsNotNone(result['version'])
示例#31
0
    def test_successful(self):
        """Tests successfully calling the job load view."""

        url = rest_util.get_url("/load/")
        response = self.client.generic("GET", url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result["results"]), 3)
示例#32
0
    def test_successful(self):
        """Tests successfully calling the job load view."""

        url = rest_util.get_url('/load/')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 3)
示例#33
0
    def test_batch_id(self):
        """Tests successfully calling the source products view filtered by batch identifier."""

        url = rest_util.get_url('/sources/%d/products/?batch_id=%s' % (self.src_file.id, self.batch.id))
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 3)
示例#34
0
    def test_invalid_ended(self):
        """Tests calling the source file updates view when the ended parameter is invalid."""

        url = rest_util.get_url(
            '/sources/updates/?started=1970-01-01T00:00:00Z&ended=hello')
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.content)
示例#35
0
    def test_invalid_time_field(self):
        """Tests calling the product file source files view when the time_field parameter is invalid."""

        url = rest_util.get_url('/products/%d/sources/?started=1970-01-01T00:00:00Z&time_field=hello' \
                                % self.product1.id)
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.content)
示例#36
0
    def test_no_changes(self):
        """Tests reprocessing a recipe that has not changed without specifying any jobs throws an error."""

        json_data = {}

        url = rest_util.get_url('/recipes/%i/reprocess/' % self.recipe1.id)
        response = self.client.generic('POST', url, json.dumps(json_data), 'application/json')

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#37
0
    def test_successful_superseded(self):
        """Tests getting superseded recipes"""

        url = rest_util.get_url('/recipes/?include_superseded=true')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        results = json.loads(response.content)
        self.assertEqual(results['count'], 3)
示例#38
0
    def test_superseded(self):
        """Tests getting superseded jobs from source jobs view."""

        url = rest_util.get_url('/sources/%d/jobs/?include_superseded=true' % self.src_file.id)
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 3)
示例#39
0
    def test_missing_recipe_id(self):
        """Tests calling the queue recipe view without the required job type."""

        json_data = {"recipe_data": {}}

        url = rest_util.get_url("/queue/new-recipe/")
        response = self.client.generic("POST", url, json.dumps(json_data), "application/json")

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#40
0
    def test_time_field(self):
        """Tests successfully calling the source files view using the time_field parameter"""

        url = rest_util.get_url('/sources/?started=2016-02-01T00:00:00Z&time_field=data')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 1)
示例#41
0
    def test_bad_type_recipe_id(self):
        """Tests calling the queue recipe view with a string recipe ID (which is invalid)."""

        json_data = {"recipe_id": "BAD", "recipe_data": {}}

        url = rest_util.get_url("/queue/new-recipe/")
        response = self.client.generic("POST", url, json.dumps(json_data), "application/json")

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#42
0
    def test_groups(self):
        """Tests successfully calling the metric plot view with group filters."""

        url = rest_util.get_url('/metrics/job-types/plot-data/?group=overview')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 4)
示例#43
0
    def test_not_found(self):
        """Tests a Scan process launch where the id of Scan is missing."""

        url = rest_util.get_url('/scans/100/process/')
        response = self.client.generic('POST', url,
                                       json.dumps({'ingest': False}),
                                       'application/json')
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         response.content)
示例#44
0
    def test_successful(self):
        """Tests successfully calling the source files view."""

        url = rest_util.get_url('/sources/')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 2)
示例#45
0
    def test_success(self):
        """Test getting overall version/build information successfully"""
        url = rest_util.get_url('/version/')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK,
                         response.content)

        result = json.loads(response.content)
        self.assertIsNotNone(result['version'])
示例#46
0
    def test_no_changes(self):
        """Tests reprocessing a recipe that has not changed without specifying any jobs throws an error."""

        json_data = {}

        url = rest_util.get_url('/recipes/%i/reprocess/' % self.recipe1.id)
        response = self.client.generic('POST', url, json.dumps(json_data), 'application/json')

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST, response.content)
示例#47
0
    def test_columns(self):
        """Tests successfully calling the metric plot view with column filters."""

        url = rest_util.get_url('/metrics/job-types/plot-data/?column=completed_count&column=failed_count')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 2)
示例#48
0
    def test_successful_superseded(self):
        """Tests getting superseded recipes"""

        url = rest_util.get_url('/recipes/?include_superseded=true')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        results = json.loads(response.content)
        self.assertEqual(results['count'], 3)
示例#49
0
    def test_nodes_view(self):
        """ test the REST call to retrieve an empty list of nodes"""
        url = rest_util.get_url('/nodes/')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK,
                         response.content)

        results = json.loads(response.content)
        self.assertEqual(len(results['results']), 0)
示例#50
0
    def test_max_duration(self):
        """Tests calling the job load view with time values that define a range greater than 31 days"""

        url = rest_util.get_url(
            '/load/?started=2015-01-01T00:00:00Z&ended=2015-02-02T00:00:00Z')
        response = self.client.generic('GET', url)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.content)
示例#51
0
    def test_ingest_process_conflict(self):
        """Tests error response when calling the Scan process view for an ingest Scan when already processed."""

        self.scan.job = job_utils.create_job()
        self.scan.save()

        url = rest_util.get_url('/scans/%s/process/' % self.scan.id)
        response = self.client.generic('POST', url, json.dumps({ 'ingest': True }), 'application/json')
        self.assertEqual(response.status_code, status.HTTP_409_CONFLICT, response.content)
示例#52
0
文件: test_views.py 项目: sau29/scale
    def test_edit_user_staff_promote(self):
        """Validate a staff user can promote others to staff user"""
        self.user['is_staff'] = True

        rest.login_client(self.client, is_staff=True)
        url = rest_util.get_url('/accounts/users/%i/' % (self.user_id,))
        response = self.client.put(url, data=self.user, format='json')

        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)
示例#53
0
    def test_list_errors(self):
        """Tests successfully calling the get Errors method."""

        url = rest_util.get_url('/errors/')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 3)
示例#54
0
    def test_groups(self):
        """Tests successfully calling the metric plot view with group filters."""

        url = rest_util.get_url('/metrics/job-types/plot-data/?group=overview')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 4)
示例#55
0
    def test_columns(self):
        """Tests successfully calling the metric plot view with column filters."""

        url = rest_util.get_url('/metrics/job-types/plot-data/?column=completed_count&column=failed_count')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 2)
示例#56
0
    def test_superseded(self):
        """Tests successfully calling the recipe details view for superseded recipes."""

        graph1 = RecipeGraph()
        graph1.add_job('kml', self.job_type1.name, self.job_type1.version)
        graph2 = RecipeGraph()
        graph2.add_job('kml', self.job_type1.name, self.job_type1.version)
        delta = RecipeGraphDelta(graph1, graph2)

        superseded_jobs = {recipe_job.job_name: recipe_job.job for recipe_job in self.recipe1_jobs}
        new_recipe = recipe_test_utils.create_recipe_handler(
            recipe_type=self.recipe_type, superseded_recipe=self.recipe1, delta=delta, superseded_jobs=superseded_jobs
        ).recipe

        # Make sure the original recipe was updated
        url = rest_util.get_url('/recipes/%i/' % self.recipe1.id)
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertTrue(result['is_superseded'])
        self.assertIsNone(result['root_superseded_recipe'])
        self.assertIsNotNone(result['superseded_by_recipe'])
        self.assertEqual(result['superseded_by_recipe']['id'], new_recipe.id)
        self.assertIsNotNone(result['superseded'])
        self.assertEqual(len(result['jobs']), 1)
        for recipe_job in result['jobs']:
            self.assertTrue(recipe_job['is_original'])

        # Make sure the new recipe has the expected relations
        url = rest_util.get_url('/recipes/%i/' % new_recipe.id)
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertFalse(result['is_superseded'])
        self.assertIsNotNone(result['root_superseded_recipe'])
        self.assertEqual(result['root_superseded_recipe']['id'], self.recipe1.id)
        self.assertIsNotNone(result['superseded_recipe'])
        self.assertEqual(result['superseded_recipe']['id'], self.recipe1.id)
        self.assertIsNone(result['superseded'])
        self.assertEqual(len(result['jobs']), 1)
        for recipe_job in result['jobs']:
            self.assertFalse(recipe_job['is_original'])
示例#57
0
    def test_update_node_no_fields(self):
        """Test calling the Update Node method with no fields."""

        json_data = {}
        url = rest_util.get_url('/nodes/%d/' % self.node2.id)
        response = self.client.patch(url, json.dumps(json_data),
                                     'application/json')

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST,
                         response.content)
示例#58
0
    def test_successful(self, mock_msg_mgr):
        """Tests calling the view to create Scale Roulette jobs."""

        json_data = {'num': 10}

        url = rest_util.get_url('/diagnostics/job/roulette/')
        response = self.client.generic('POST', url, json.dumps(json_data),
                                       'application/json')
        self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED,
                         response.content)
示例#59
0
    def test_get_scheduler_not_found(self):
        """Test calling the Get Scheduler method when the database entry is missing."""

        Scheduler.objects.get_master().delete()

        url = rest_util.get_url('/scheduler/')
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                         response.content)
示例#60
0
    def test_aggregate_avg(self):
        """Tests successfully calling the metric plot view using an average aggregate."""

        url = rest_util.get_url('/metrics/job-types/plot-data/?column=job_time_avg')
        response = self.client.generic('GET', url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)

        result = json.loads(response.content)
        self.assertEqual(len(result['results']), 1)
        self.assertEqual(result['results'][0]['values'][0]['value'], 330)