Exemple #1
0
    def test_create_job_with_tags(self, create_run_mock, pickup_mock):
        create_run_mock.return_value = "some_run_uid"

        # config_uid = self.config.uid
        url = reverse('api:jobs-list')
        formats = [export_format.slug for export_format in ExportFormat.objects.all()]
        request_data = {
            'name': 'TestJob',
            'description': 'Test description',
            'event': 'Test Activation',
            'selection': bbox_to_geojson([-3.9, 16.1, 7.0, 27.6]),
            'provider_tasks': [{'provider': 'OpenStreetMap Data (Generic)', 'formats': formats}],
            # 'preset': config_uid,
            'transform': '',
            'translate': '',
            'tags': self.tags
        }
        response = self.client.post(url, request_data, format='json')
        job_uid = response.data['uid']
        # test that the mock methods get called.
        create_run_mock.assert_called_once_with(job_uid=job_uid)
        pickup_mock.delay.assert_called_once_with(run_uid="some_run_uid")

        # test the response headers
        self.assertEquals(response.status_code, status.HTTP_202_ACCEPTED)
        self.assertEquals(response['Content-Type'], 'application/json')
        self.assertEquals(response['Content-Language'], 'en')

        # test significant response content
        self.assertEqual(response.data['exports'][0]['formats'][0]['slug'],
                         request_data['provider_tasks'][0]['formats'][0])
        self.assertEqual(response.data['exports'][0]['formats'][1]['slug'],
                         request_data['provider_tasks'][0]['formats'][1])
        self.assertEqual(response.data['name'], request_data['name'])
        self.assertEqual(response.data['description'], request_data['description'])
Exemple #2
0
 def setUp(self,):
     url = reverse('api:jobs-list')
     # create dummy user
     Group.objects.create(name='TestDefaultExportExtentGroup')
     self.user = User.objects.create_user(
         username='******', email='*****@*****.**', password='******'
     )
     # setup token authentication
     token = Token.objects.create(user=self.user)
     self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key,
                             HTTP_ACCEPT='application/json; version=1.0',
                             HTTP_ACCEPT_LANGUAGE='en',
                             HTTP_HOST='testserver')
     # pull out the formats
     formats = [export_format.slug for export_format in ExportFormat.objects.all()]
     # create test jobs
     extents = [(-3.9, 16.1, 7.0, 27.6), (36.90, 13.54, 48.52, 20.24),
                (-71.79, -49.57, -67.14, -46.16), (-61.27, -6.49, -56.20, -2.25),
                (-11.61, 32.07, -6.42, 36.31), (-10.66, 5.81, -2.45, 11.83),
                (47.26, 34.58, 52.92, 39.15), (90.00, 11.28, 95.74, 17.02)]
     for extent in extents:
         request_data = {
             'name': 'TestJob',
             'description': 'Test description',
             'event': 'Test Activation',
             'selection': bbox_to_geojson(extent),
             'provider_tasks': [{'provider': 'OpenStreetMap Data (Generic)', 'formats': formats}]
         }
         response = self.client.post(url, request_data, format='json')
         self.assertEquals(status.HTTP_202_ACCEPTED, response.status_code, response.content)
     self.assertEquals(8, len(Job.objects.all()))
     LinkHeaderPagination.page_size = 2
Exemple #3
0
    def test_make_job_with_export_providers(self,):
        """tests job creation with export providers"""
        export_providers = ExportProvider.objects.all()
        export_providers_start_len = len(export_providers)
        config_uid = self.config.uid
        formats = [export_format.slug for export_format in ExportFormat.objects.all()]

        request_data = {
            'name': 'TestJob',
            'description': 'Test description',
            'event': 'Test Activation',
            'selection': bbox_to_geojson([-3.9, 16.1, 7.0, 27.6]),
            'provider_tasks': [{'provider': 'test', 'formats': formats}],
            'export_providers': [{'name': 'test', 'level_from': 0, 'level_to': 0,
                                  'url': 'http://coolproviderurl.to',
                                  'preview_url': 'http://coolproviderurl.to'}],
            'preset': str(config_uid),
            'transform': '',
            'translation': ''
        }
        url = reverse('api:jobs-list')
        response = self.client.post(url, data=json.dumps(request_data), content_type='application/json; version=1.0')
        export_providers = ExportProvider.objects.all()
        self.assertEqual(len(export_providers), export_providers_start_len + 1)
        response = json.loads(response.content)
        self.assertEqual(response['exports'][0]['provider'], 'test')

        request_data['export_providers'][0]['name'] = 'test 2'
        # should be idempotent
        self.client.post(url, data=json.dumps(request_data), content_type='application/json; version=1.0')
        export_providers = ExportProvider.objects.all()
        self.assertEqual(len(export_providers), export_providers_start_len + 1)
Exemple #4
0
 def setUp(self,):
     group, created = Group.objects.get_or_create(name='TestDefaultExportExtentGroup')
     with patch('eventkit_cloud.jobs.signals.Group') as mock_group:
         mock_group.objects.get.return_value = group
         self.user = User.objects.create_user(
             username='******', email='*****@*****.**', password='******'
         )
     self.extents = (13.473475, 7.441068, 24.002661, 23.450369)
     self.selection = bbox_to_geojson(self.extents)
Exemple #5
0
 def setUp(self):
     group, created = Group.objects.get_or_create(
         name="TestDefaultExportExtentGroup")
     with patch("eventkit_cloud.jobs.signals.Group") as mock_group:
         mock_group.objects.get.return_value = group
         self.user = User.objects.create_user(username="******",
                                              email="*****@*****.**",
                                              password="******")
     self.extents = (13.473475, 7.441068, 24.002661, 23.450369)
     self.selection = bbox_to_geojson(self.extents)
     self.bbox_geom = GEOSGeometry(Polygon.from_bbox(self.extents).wkt,
                                   srid=4326)
Exemple #6
0
 def test_missing_format_param(self,):
     url = reverse('api:jobs-list')
     request_data = {
         'name': 'TestJob',
         'description': 'Test description',
         'event': 'Test Activation',
         'selection': bbox_to_geojson([-3.9, 16.1, 7.0, 27.6]),
         'provider_tasks': [{'provider': 'OpenStreetMap Data (Generic)'}]  # 'formats': formats}]# missing
     }
     response = self.client.post(url, data=json.dumps(request_data), content_type='application/json; version=1.0')
     self.assertEquals(response['Content-Type'], 'application/json')
     self.assertEquals(response['Content-Language'], 'en')
     self.assertEquals(response.data['provider_tasks'][0]['formats'], ['This field is required.'])
Exemple #7
0
 def test_invalid_format_param(self,):
     url = reverse('api:jobs-list')
     request_data = {
         'name': 'TestJob',
         'description': 'Test description',
         'event': 'Test Activation',
         'selection':  bbox_to_geojson([-3.9, 16.1, 7.0, 27.6]),
         'provider_tasks': [{'provider': 'OpenStreetMap Data (Generic)', 'formats': ''}]  # invalid
     }
     response = self.client.post(url, request_data, format='json')
     self.assertEquals(status.HTTP_400_BAD_REQUEST, response.status_code)
     self.assertEquals(response['Content-Type'], 'application/json')
     self.assertEquals(response['Content-Language'], 'en')
     self.assertIsNotNone(response.data.get('provider_tasks')[0].get('formats'))
Exemple #8
0
 def test_empty_string_param(self,):
     url = reverse('api:jobs-list')
     formats = [export_format.slug for export_format in ExportFormat.objects.all()]
     request_data = {
         'name': 'TestJob',
         'description': '',  # empty
         'event': 'Test Activation',
         'selection': bbox_to_geojson([-3.9, 16.1, 7.0, 27.6]),
         'formats': formats
     }
     response = self.client.post(url, data=json.dumps(request_data), content_type='application/json; version=1.0')
     self.assertEquals(status.HTTP_400_BAD_REQUEST, response.status_code)
     self.assertEquals(response['Content-Type'], 'application/json')
     self.assertEquals(response['Content-Language'], 'en')
     self.assertEquals(['This field may not be blank.'], response.data['description'])
Exemple #9
0
    def test_no_matching_format_slug(self,):
        url = reverse('api:jobs-list')
        request_data = {
            'name': 'TestJob',
            'description': 'Test description',
            'event': 'Test Activation',
            'selection':  bbox_to_geojson([-3.9, 16.1, 7.0, 27.6]),
            'provider_tasks': [
                {'provider': 'OpenStreetMap Data (Generic)', 'formats': ['broken-format-one', 'broken-format-two']}]
        }
        response = self.client.post(url, request_data, format='json')

        self.assertEquals(status.HTTP_400_BAD_REQUEST, response.status_code)
        self.assertEquals(response['Content-Type'], 'application/json')
        self.assertEquals(response['Content-Language'], 'en')
        self.assertEquals(response.data['provider_tasks'][0]['formats'],
                          ['Object with slug=broken-format-one does not exist.'])
Exemple #10
0
    def test_extents_too_large(self,):
        url = reverse('api:jobs-list')
        formats = [export_format.slug for export_format in ExportFormat.objects.all()]
        # job outside any region
        request_data = {
            'name': 'TestJob',
            'description': 'Test description',
            'event': 'Test Activation',
            'selection':  bbox_to_geojson([-180, -90, 180, 90]),
            'provider_tasks': [{'provider': 'OpenStreetMap Data (Generic)', 'formats': formats}]
        }

        with self.settings(JOB_MAX_EXTENT=100000):
            response = self.client.post(url, data=json.dumps(request_data), content_type='application/json; version=1.0')

        self.assertEquals(status.HTTP_400_BAD_REQUEST, response.status_code)
        self.assertEquals(response['Content-Type'], 'application/json')
        self.assertEquals(response['Content-Language'], 'en')
        self.assertEquals(['invalid_extents'], response.data['id'])
Exemple #11
0
    def test_create_zipfile(self):
        formats = [export_format.slug for export_format in ExportFormat.objects.all()]
        config_uid = self.config.uid
        request_data = {
            'name': 'TestJob',
            'description': 'Test description',
            'event': 'Test Activation',
            'selection':  bbox_to_geojson([-3.9, 16.1, 7.0, 27.6]),
            'provider_tasks': [{'provider': 'OpenStreetMap Data (Generic)', 'formats': formats}],
            'preset': config_uid,
            'published': True,
            'tags': self.tags,
            'include_zipfile': True
        }
        url = reverse('api:jobs-list')
        response = self.client.post(url, request_data, format='json')
        msg = 'status_code {} != {}: {}'.format(200, response.status_code, response.content)
        self.assertEqual(202, response.status_code, msg)
        job_uid = response.data['uid']

        job = Job.objects.get(uid=job_uid)
        self.assertEqual(job.include_zipfile, True)
 def setUp(self, ):
     self.user = User.objects.create_user(username='******',
                                          email='*****@*****.**',
                                          password='******')
     self.extents = (13.473475, 7.441068, 24.002661, 23.450369)
     self.selection = bbox_to_geojson(self.extents)