def test_update_metric_module_detail_ok(self):
        metric_id = '1'
        data = {'status': 'Stopped'}
        request = self.factory.post('/metrics/' + metric_id, data, format='json')
        response = metric_module_detail(request, metric_id)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # check the metric_module has been updated
        request = self.factory.get('/metrics/' + metric_id)
        response = metric_module_detail(request, metric_id)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        metric_data = json.loads(response.content)
        self.assertEqual(metric_data['status'], 'Stopped')
Exemple #2
0
    def test_update_metric_module_detail_ok(self):
        metric_id = '1'
        data = {'status': 'Stopped'}
        request = self.factory.post('/metrics/' + metric_id,
                                    data,
                                    format='json')
        response = metric_module_detail(request, metric_id)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # check the metric_module has been updated
        request = self.factory.get('/metrics/' + metric_id)
        response = metric_module_detail(request, metric_id)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        metric_data = json.loads(response.content)
        self.assertEqual(metric_data['status'], 'Stopped')
 def test_get_metric_module_detail_ok(self):
     metric_id = '1'
     request = self.factory.get('/metrics/' + metric_id)
     response = metric_module_detail(request, metric_id)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     metric_data = json.loads(response.content)
     self.assertEqual(metric_data['metric_name'], 'm1.py')
Exemple #4
0
 def test_get_metric_module_detail_ok(self):
     metric_id = '1'
     request = self.factory.get('/metrics/' + metric_id)
     response = metric_module_detail(request, metric_id)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     metric_data = json.loads(response.content)
     self.assertEqual(metric_data['metric_name'], 'm1.py')
Exemple #5
0
    def test_create_metric_module_ok(self, mock_rsync_dir):
        with open('test_data/test.py', 'r') as fp:
            metadata = {
                'class_name': 'Metric1',
                'execution_server': 'proxy',
                'out_flow': False,
                'in_flow': False,
                'status': 'Stopped'
            }
            request = self.factory.post('/metrics/data/', {
                'file': fp,
                'metadata': json.dumps(metadata)
            })
            response = MetricModuleData.as_view()(request)
            mock_rsync_dir.assert_called_with(settings.WORKLOAD_METRICS_DIR,
                                              settings.WORKLOAD_METRICS_DIR)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        metric = json.loads(response.content)
        self.assertEqual(metric['id'], 2)
        self.assertEqual(metric['metric_name'], 'test.py')
        self.assertEqual(metric['execution_server'], 'proxy')

        # check the metric module has been created
        metric_id = '2'
        request = self.factory.get('/metrics/' + metric_id)
        response = metric_module_detail(request, metric_id)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        metric_data = json.loads(response.content)
        self.assertEqual(metric_data['metric_name'], 'test.py')
    def test_delete_metric_module_detail_ok(self):
        metric_id = '1'
        request = self.factory.delete('/metrics/' + metric_id)
        response = metric_module_detail(request, metric_id)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # check the metric module has been deleted
        request = self.factory.get('/metrics')
        response = metric_module_list(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        metrics = json.loads(response.content)
        self.assertEqual(len(metrics), 0)
Exemple #7
0
    def test_delete_metric_module_detail_ok(self):
        metric_id = '1'
        request = self.factory.delete('/metrics/' + metric_id)
        response = metric_module_detail(request, metric_id)
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # check the metric module has been deleted
        request = self.factory.get('/metrics')
        response = metric_module_list(request)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        metrics = json.loads(response.content)
        self.assertEqual(len(metrics), 0)
    def test_update_metric_module_put_ok(self, mock_rsync_dir):
        metric_id = '1'
        with open('test_data/test.py', 'r') as fp:
            request = self.factory.put('/metrics/' + metric_id + '/data', {'file': fp})
            response = MetricModuleData.as_view()(request, metric_id)
            mock_rsync_dir.assert_called_with(settings.WORKLOAD_METRICS_DIR, settings.WORKLOAD_METRICS_DIR)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        # check the metric module has been updated
        request = self.factory.get('/metrics/' + metric_id)
        response = metric_module_detail(request, metric_id)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        metric_data = json.loads(response.content)
        self.assertEqual(metric_data['metric_name'], 'test.py')
Exemple #9
0
    def test_update_metric_module_put_ok(self, mock_rsync_dir):
        metric_id = '1'
        with open('test_data/test.py', 'r') as fp:
            request = self.factory.put('/metrics/' + metric_id + '/data',
                                       {'file': fp})
            response = MetricModuleData.as_view()(request, metric_id)
            mock_rsync_dir.assert_called_with(settings.WORKLOAD_METRICS_DIR,
                                              settings.WORKLOAD_METRICS_DIR)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        # check the metric module has been updated
        request = self.factory.get('/metrics/' + metric_id)
        response = metric_module_detail(request, metric_id)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        metric_data = json.loads(response.content)
        self.assertEqual(metric_data['metric_name'], 'test.py')
    def test_create_metric_module_ok(self, mock_rsync_dir):
        with open('test_data/test.py', 'r') as fp:
            metadata = {'class_name': 'Metric1', 'execution_server': 'proxy', 'out_flow': False,
                        'in_flow': False, 'status': 'Stopped'}
            request = self.factory.post('/metrics/data/', {'file': fp, 'metadata': json.dumps(metadata)})
            response = MetricModuleData.as_view()(request)
            mock_rsync_dir.assert_called_with(settings.WORKLOAD_METRICS_DIR, settings.WORKLOAD_METRICS_DIR)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        metric = json.loads(response.content)
        self.assertEqual(metric['id'], 2)
        self.assertEqual(metric['metric_name'], 'test.py')
        self.assertEqual(metric['execution_server'], 'proxy')

        # check the metric module has been created
        metric_id = '2'
        request = self.factory.get('/metrics/' + metric_id)
        response = metric_module_detail(request, metric_id)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        metric_data = json.loads(response.content)
        self.assertEqual(metric_data['metric_name'], 'test.py')