Example #1
0
    def test_get_latest_lighning_data_returns_json_feature_collection(self):
        if self.skip_tests:
            return

        # Act
        json_feature_collection, metadata = EarthNetworksService.get_latest_lightning_data(
        )

        # Assert
        self.assertTrue(json_feature_collection,
                        'Json str should be available')
        self.assertTrue(metadata, 'Metadata should be available')

        # Clean up
        EarthNetworksService.clean_up_weather_dir(self.weather_dir, 0)
Example #2
0
    def test_clean_up_removes_files(self):
        # Arrange
        test_file_name = 'a_test.csv'
        test_file_location = os.path.join(self.weather_dir, test_file_name)

        # Generate a test file for deletion
        f = open(test_file_location, 'w')
        f.write('Test\n')
        f.close()

        # Act
        EarthNetworksService.clean_up_weather_dir(self.weather_dir, 0)

        # Assert
        self.assertFalse(os.path.exists(test_file_location),
                         'Test file should have been deleted')
Example #3
0
    def test_lightning_data_can_be_downloaded_from_s3(self):
        if self.skip_tests:
            return

        # Arrange
        test_date = datetime.strptime('20180125', '%Y%m%d')

        # Act
        lightning_file = EarthNetworksService.get_latest_daily_lighting_file(
            test_date)

        # Assert
        self.assertTrue(lightning_file,
                        'Should have downloaded a lightning file')

        # Clean up
        EarthNetworksService.clean_up_weather_dir(self.weather_dir, 0)
Example #4
0
    def test_can_retrieve_metadata_from_filename(self):
        # Arrange
        filename = 'pplnneed2_lx_20180125_200059.csv'

        # Act
        metadata = EarthNetworksService.get_lightning_file_meta_data(filename)

        # Assert
        self.assertEqual(metadata, '25-Jan-2018 20:00:59')
Example #5
0
    def test_valid_lightning_file_returns_feature_collection(self):
        if self.skip_tests:
            return

        # Arrange
        lightning_file = os.path.join(self.weather_dir, 'test_lightning.csv')

        # Act
        valid_feature_collection, metadata = EarthNetworksService.convert_lightning_data_to_geojson(
            lightning_file)

        self.assertEqual(332, len(valid_feature_collection['features']),
                         'Valid file should have 332 features')
Example #6
0
    def test_no_lightning_data_returns_empty_geojson(self):
        # Arrange
        no_lightning_file = os.path.join(self.weather_dir,
                                         'test_lightning_no_data.csv')

        # Act
        empty_feature_collection, metadata = EarthNetworksService.convert_lightning_data_to_geojson(
            no_lightning_file)

        # Assert
        self.assertEqual(metadata, 'No updates since 8/8/2017 3:23:56 PM')
        self.assertTrue(
            type(empty_feature_collection) is FeatureCollection,
            'Must be a feature collection object')
Example #7
0
    def test_get_file_location_returns_expected_path(self):
        # Arrange
        test_file = 'test.csv'
        weather_found = False
        file_found = False

        # Act
        file_location = EarthNetworksService.get_local_file_location(test_file)

        # Assert
        if 'weather' in file_location:
            weather_found = True

        if test_file in file_location:
            file_found = True

        self.assertTrue(weather_found)
        self.assertTrue(file_found)
Example #8
0
    def get_earthnetworks_lightning_response():
        """ Get the EarthNetworks lightning response """
        try:
            feature_collection_json, last_updated = EarthNetworksService.get_latest_lightning_data(
            )
        except EarthNetworksError:
            raise MapServiceServerError(
                'Error occurred attempting to get EarthNetworks Lightning Data'
            )

        response_headers = Headers()
        response_headers.add('Last-Modified', last_updated)

        flask_response = Response(feature_collection_json,
                                  status=200,
                                  mimetype='application/json',
                                  headers=response_headers)
        return flask_response