Exemplo n.º 1
0
    def setUp(self):
        django.setup()

        self.config = {
            'broker': {
                'type': 'host',
                'host_path': '/host/path',
            },
        }

        self.workspace = storage_test_utils.create_workspace(json_config=self.config)

        self.config2 = {
            "broker": {
                "type": "s3",
                "bucket_name": "my_bucket.domain.com",
                "credentials": {
                    "access_key_id": "secret",
                    "secret_access_key": "super-secret"
                },
                "host_path": "/my_bucket",
                "region_name": "us-east-1"
            }
        }

        self.secret_config = copy.deepcopy(self.config2)
        self.secret_config['broker']['credentials']['access_key_id'] = '************'
        self.secret_config['broker']['credentials']['secret_access_key'] = '************'

        self.workspace2 = storage_test_utils.create_workspace(json_config=self.config2)

        rest.login_client(self.client, is_staff=True)
Exemplo n.º 2
0
    def test_get_user_list_from_staff_user_successful(self):
        url = rest_util.get_url('/accounts/users/')
        rest.login_client(self.client, is_staff=True)
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)
        self.assertEqual(len(json.loads(response.content)['results']), 1)
Exemplo n.º 3
0
    def setUp(self):
        django.setup()

        self.workspace1 = storage_test_utils.create_workspace(name='ws1')
        self.workspace2 = storage_test_utils.create_workspace(name='ws2')

        rest.login_client(self.client)
Exemplo n.º 4
0
    def test_successful(self):
        """Tests successfully calling the get workspace details view."""

        url = '/%s/workspaces/%d/' % (self.api, self.workspace.id)
        response = self.client.get(url)
        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['name'], self.workspace.name)
        self.assertEqual(result['title'], self.workspace.title)
        self.assertIn('deprecated', result)

        url = '/%s/workspaces/%d/' % (self.api, self.workspace2.id)
        response = self.client.get(url)
        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.workspace2.id)
        self.assertEqual(result['name'], self.workspace2.name)
        self.assertEqual(result['title'], self.workspace2.title)
        self.assertDictEqual(result['configuration'], self.config2)
        self.assertIn('deprecated', result)

        # test credentials being masked to non-staff users
        rest.login_client(self.client, is_staff=False, username='******')

        url = '/%s/workspaces/%d/' % (self.api, self.workspace2.id)
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)
        result = json.loads(response.content)
        self.assertDictEqual(result['configuration'], self.secret_config)
Exemplo n.º 5
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client)

        self.node1 = node_test_utils.create_node()
        self.node2 = node_test_utils.create_node()
Exemplo n.º 6
0
    def test_get_current_user_staff(self):
        """Tests calling the GetUser view when authenticated as a staff user."""

        url = rest_util.get_url('/accounts/profile/')
        rest.login_client(self.client, is_staff=True)
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_200_OK, response.content)
Exemplo n.º 7
0
    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)
Exemplo n.º 8
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client)

        self.recipe_type_1 = recipe_test_utils.create_recipe_type_v6()
        self.batch_1 = batch_test_utils.create_batch(recipe_type=self.recipe_type_1, is_creation_done=False)

        self.recipe_type_2 = recipe_test_utils.create_recipe_type_v6()
        self.batch_2 = batch_test_utils.create_batch(recipe_type=self.recipe_type_2, is_creation_done=True)
Exemplo n.º 9
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client, is_staff=True)

        self.node1 = node_test_utils.create_node()
        self.node2 = node_test_utils.create_node()
        self.node3 = node_test_utils.create_node()

        Scheduler.objects.create(id=1)
Exemplo n.º 10
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client, is_staff=True)

        Error.objects.all().delete(
        )  # Need to remove initial errors loaded by fixtures
        self.error1 = error_test_utils.create_error(category='SYSTEM',
                                                    is_builtin=True)
        self.error2 = error_test_utils.create_error(category='ALGORITHM')
        self.error3 = error_test_utils.create_error(category='DATA')
Exemplo n.º 11
0
    def test_create_user_by_id_regular_user_unauthorized(self):
        user = {
            'username': '******',
            'password': '******',
            'email': '*****@*****.**'
        }

        url = rest_util.get_url('/accounts/users/')
        rest.login_client(self.client, is_staff=False)
        response = self.client.post(url, data=user, format='json')

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN, response.content)
Exemplo n.º 12
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client, is_staff=True)

        Error.objects.all().delete(
        )  # Need to remove initial errors loaded by fixtures
        error_test_utils.create_error(category='SYSTEM', is_builtin=True)
        error_test_utils.create_error(category='ALGORITHM')
        error_test_utils.create_error(name='data',
                                      category='DATA',
                                      job_type_name='type-1')
Exemplo n.º 13
0
    def test_create_user_from_staff_user_successful(self):
        user = {
            'username': '******',
            'password': '******',
            'email': '*****@*****.**'
        }

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

        self.assertEqual(response.status_code, status.HTTP_201_CREATED, response.content)
Exemplo n.º 14
0
    def setUp(self):
        django.setup()

        self.config = {
            'broker': {
                'type': 'host',
                'host_path': '/host/path',
            },
        }

        self.workspace = storage_test_utils.create_workspace(json_config=self.config)

        rest.login_client(self.client, is_staff=True)
Exemplo n.º 15
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client)

        self.job_type1 = job_test_utils.create_seed_job_type()
        metrics_test_utils.create_job_type(job_type=self.job_type1, completed_count=8, failed_count=2, total_count=10)

        self.job_type2 = job_test_utils.create_seed_job_type()
        metrics_test_utils.create_job_type(job_type=self.job_type2, job_time_sum=220, job_time_min=20, job_time_max=200,
                                           job_time_avg=110)

        self.job_type3 = job_test_utils.create_seed_job_type()
        metrics_test_utils.create_job_type(job_type=self.job_type3, job_time_sum=1100, job_time_min=100,
                                           job_time_max=1000, job_time_avg=550)
Exemplo n.º 16
0
    def setUp(self):
        django.setup()

        self.workspace1 = storage_test_utils.create_workspace(name='ws1')
        self.country = storage_test_utils.create_country()
        manifest = copy.deepcopy(job_test_utils.COMPLETE_MANIFEST)
        manifest['job']['name'] = 'test1'
        self.job_type1 = job_test_utils.create_seed_job_type(manifest=manifest)
        self.job1 = job_test_utils.create_job(job_type=self.job_type1)
        self.job_exe1 = job_test_utils.create_job_exe(job=self.job1)
        self.recipe_type1 = recipe_test_utils.create_recipe_type_v6()
        self.recipe1 = recipe_test_utils.create_recipe(
            recipe_type=self.recipe_type1)
        self.batch1 = batch_test_utils.create_batch(
            recipe_type=self.recipe_type1, is_creation_done=True)
        self.file = storage_test_utils.create_file(
            file_name='test.txt',
            file_type='SOURCE',
            media_type='image/png',
            file_size=1000,
            data_type_tags=['png'],
            file_path='/test/path',
            workspace=self.workspace1,
            is_deleted=False,
            last_modified='',
            data_started='2017-01-01T00:00:00Z',
            data_ended='2017-01-01T00:00:00Z',
            source_started='2017-01-01T00:00:00Z',
            source_ended='2017-01-01T00:00:00Z',
            geometry='',
            center_point='',
            meta_data='',
            countries=[self.country],
            job_exe=self.job_exe1,
            job_output='output_name_1',
            recipe=self.recipe1,
            recipe_node='my-recipe',
            batch=self.batch1,
            is_superseded=True,
            superseded='2017-01-01T00:00:00Z')

        rest.login_client(self.client)
Exemplo n.º 17
0
    def setUp(self):
        django.setup()

        self.country = storage_test_utils.create_country()
        manifest = copy.deepcopy(job_test_utils.COMPLETE_MANIFEST)
        manifest['job']['name'] = 'test1'
        self.job_type1 = job_test_utils.create_seed_job_type(manifest=manifest)
        self.job1 = job_test_utils.create_job(job_type=self.job_type1)
        self.job_exe1 = job_test_utils.create_job_exe(job=self.job1)
        self.f1_source_started = dt.datetime(2016, 1, 1, tzinfo=utc)
        self.f1_source_ended = dt.datetime(2016, 1, 2, tzinfo=utc)
        self.source_sensor_class = 'classA'
        self.source_sensor = '1'
        self.source_collection = '12345'
        self.source_task = 'test-task'
        self.file1 = storage_test_utils.create_file(
            job_exe=self.job_exe1,
            job_output='out_name',
            file_name='test.txt',
            countries=[self.country],
            recipe_node='test-recipe-node',
            source_started=self.f1_source_started,
            source_ended=self.f1_source_ended,
            source_sensor_class=self.source_sensor_class,
            source_sensor=self.source_sensor,
            source_collection=self.source_collection,
            source_task=self.source_task,
            data_type_tags=['type1', 'type2'])

        manifest['job']['name'] = 'test2'
        self.job_type2 = job_test_utils.create_seed_job_type(manifest=manifest)
        self.job2 = job_test_utils.create_job(job_type=self.job_type2)
        self.job_exe2 = job_test_utils.create_job_exe(job=self.job2)
        self.f2_source_started = dt.datetime(2016, 1, 2, tzinfo=utc)
        self.f2_source_ended = dt.datetime(2016, 1, 3, tzinfo=utc)
        self.file2 = storage_test_utils.create_file(
            job_exe=self.job_exe2,
            countries=[self.country],
            source_started=self.f2_source_started,
            source_ended=self.f2_source_ended)

        rest.login_client(self.client)
Exemplo n.º 18
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client, is_staff=True)

        self.recipe_type_1 = recipe_test_utils.create_recipe_type_v6()
        self.batch_1 = batch_test_utils.create_batch(recipe_type=self.recipe_type_1, is_creation_done=False)

        self.recipe_type_2 = recipe_test_utils.create_recipe_type_v6()
        self.batch_2 = batch_test_utils.create_batch(recipe_type=self.recipe_type_2, is_creation_done=True)

        self.job_type1 = job_test_utils.create_seed_job_type(manifest=job_test_utils.MINIMUM_MANIFEST)

        self.sub_definition = copy.deepcopy(recipe_test_utils.SUB_RECIPE_DEFINITION)
        self.sub_definition['nodes']['node_a']['node_type']['job_type_name'] = self.job_type1.name
        self.sub_definition['nodes']['node_a']['node_type']['job_type_version'] = self.job_type1.version
        self.sub_definition['nodes']['node_a']['node_type']['job_type_revision'] = self.job_type1.revision_num

        self.recipe_type_3 = recipe_test_utils.create_recipe_type_v6(definition=self.sub_definition)
        self.batch_3 = batch_test_utils.create_batch(recipe_type=self.recipe_type_3, is_creation_done=True)
        recipe_test_utils.create_recipe(recipe_type=self.recipe_type_3, batch=self.batch_3)
Exemplo n.º 19
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client, is_staff=True)

        Scheduler.objects.create(id=1)
Exemplo n.º 20
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client)
Exemplo n.º 21
0
    def setUp(self):
        django.setup()
        Scheduler.objects.create(id=1)

        rest.login_client(self.client)
Exemplo n.º 22
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client, is_staff=True)
Exemplo n.º 23
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client)

        job_test_utils.create_seed_job_type()
Exemplo n.º 24
0
    def setUp(self):
        django.setup()

        rest.login_client(self.client, is_staff=True)

        # create a couple job types
        manifest = copy.deepcopy(job_test_utils.COMPLETE_MANIFEST)
        manifest['job']['name'] = 'test-job-1'
        manifest['job']['interface']['inputs'] = {
            'files': [{
                'name': 'INPUT_FILE',
                'required': True,
                'mediaTypes': ['image/png'],
                'partial': False
            }]
        }
        self.job_type_1 = job_test_utils.create_seed_job_type(
            manifest=manifest)

        manifest = copy.deepcopy(job_test_utils.COMPLETE_MANIFEST)
        manifest['job']['name'] = 'test-job-2'
        manifest['job']['interface']['inputs'] = {
            'files': [{
                'name': 'INPUT_FILE',
                'required': True,
                'mediaTypes': ['image/png'],
                'partial': False
            }]
        }
        self.job_type_2 = job_test_utils.create_seed_job_type(
            manifest=manifest)

        # create recipe types
        recipe_def = {
            'version': '7',
            'input': {
                'files': [{
                    'name': 'INPUT_FILE',
                    'media_types': ['image/png'],
                    'required': True,
                    'multiple': False
                }],
                'json': []
            },
            'nodes': {
                'node_a': {
                    'dependencies': [],
                    'input': {
                        'INPUT_FILE': {
                            'type': 'recipe',
                            'input': 'INPUT_FILE'
                        }
                    },
                    'node_type': {
                        'node_type': 'job',
                        'job_type_name': self.job_type_1.name,
                        'job_type_version': self.job_type_1.version,
                        'job_type_revision': self.job_type_1.revision_num
                    }
                }
            }
        }
        self.recipe_type_1 = recipe_test_utils.create_recipe_type_v6(
            definition=recipe_def)

        recipe_def = {
            'version': '7',
            'input': {
                'files': [{
                    'name': 'INPUT_FILE',
                    'media_types': ['image/png'],
                    'required': True,
                    'multiple': False
                }],
                'json': []
            },
            'nodes': {
                'node_a': {
                    'dependencies': [],
                    'input': {
                        'INPUT_FILE': {
                            'type': 'recipe',
                            'input': 'INPUT_FILE'
                        }
                    },
                    'node_type': {
                        'node_type': 'job',
                        'job_type_name': self.job_type_2.name,
                        'job_type_version': self.job_type_2.version,
                        'job_type_revision': self.job_type_2.revision_num
                    }
                },
                'node_b': {
                    'dependencies': [],
                    'input': {
                        'INPUT_FILE': {
                            'type': 'recipe',
                            'input': 'INPUT_FILE'
                        }
                    },
                    'node_type': {
                        'node_type': 'job',
                        'job_type_name': self.job_type_1.name,
                        'job_type_version': self.job_type_1.version,
                        'job_type_revision': self.job_type_1.revision_num
                    }
                }
            }
        }
        self.recipe_type_2 = recipe_test_utils.create_recipe_type_v6(
            definition=recipe_def)

        # create recipes & jobs
        self.workspace = storage_test_utils.create_workspace()
        for i in range(1, 7):
            date_1 = datetime.datetime(2020, 1, i, tzinfo=utc)
            date_2 = datetime.datetime(2020, 1, i + 1, tzinfo=utc)
            date_3 = datetime.datetime(2020, i, i + 1, tzinfo=utc)
            file_1 = storage_test_utils.create_file(workspace=self.workspace,
                                                    file_size=104857600.0,
                                                    source_started=date_1,
                                                    source_ended=date_2)

            input_data = {
                'version': '1.0',
                'input_data': [{
                    'name': 'INPUT_FILE',
                    'file_id': file_1.id
                }]
            }
            # Recipe 1's jobs
            recipe_1 = recipe_test_utils.create_recipe(
                recipe_type=self.recipe_type_1, input=input_data)
            job_1 = job_test_utils.create_job(job_type=self.job_type_1,
                                              status='COMPLETED',
                                              started=date_1,
                                              ended=date_1)
            job_1.recipe_id = recipe_1.id
            job_1.save()
            # Recipe 2s jobs
            recipe_2 = recipe_test_utils.create_recipe(
                recipe_type=self.recipe_type_2, input=input_data)
            job_2 = job_test_utils.create_job(job_type=self.job_type_2,
                                              status='COMPLETED',
                                              started=date_2,
                                              ended=date_2)
            job_2.recipe_id = recipe_2.id
            job_2.save()
            job_3 = job_test_utils.create_job(job_type=self.job_type_1,
                                              status='COMPLETED',
                                              started=date_3,
                                              ended=date_3)
            job_3.recipe_id = recipe_2.id
            job_3.save()
Exemplo n.º 25
0
    def test_get_user_list_regular_user_unauthorized(self):
        url = rest_util.get_url('/accounts/users/')
        rest.login_client(self.client, is_staff=False)
        response = self.client.get(url)

        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN, response.content)
Exemplo n.º 26
0
    def test_delete_user_other_staff_user(self):
        rest.login_client(self.client, is_staff=True)
        url = rest_util.get_url('/accounts/users/%i/' % (self.user_id,))
        response = self.client.delete(url)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT, response.content)