示例#1
0
    def setUp(self):
        parms = settings.BITIA_TEST_ENHYDRIS_INSTALLATION
        self.cookies = enhydris_api.login(parms['base_url'],
                                          parms['user'],
                                          parms['password'])

        # Create two time series
        j = {
            'gentity': parms['station_id'],
            'variable': parms['variable_id'],
            'unit_of_measurement': parms['unit_of_measurement_id'],
            'time_zone': parms['time_zone_id'],
        }
        self.ts1_id = enhydris_api.post_model(
            parms['base_url'], self.cookies, 'Timeseries', j)
        self.ts2_id = enhydris_api.post_model(
            parms['base_url'], self.cookies, 'Timeseries', j)
        assert self.ts1_id != self.ts2_id

        # Add some data (all but the last record) to the database
        ts = Timeseries(self.ts1_id)
        ts.read(StringIO(self.timeseries1_top))
        enhydris_api.post_tsdata(parms['base_url'], self.cookies, ts)
        ts = Timeseries(self.ts2_id)
        ts.read(StringIO(self.timeseries2_top))
        enhydris_api.post_tsdata(parms['base_url'], self.cookies, ts)

        # Temporary directory for cache files
        self.tempdir = tempfile.mkdtemp()
示例#2
0
    def setUp(self):
        self.parms = json.loads(os.getenv('PTHELMA_TEST_ENHYDRIS_API'))
        self.cookies = enhydris_api.login(self.parms['base_url'],
                                          self.parms['user'],
                                          self.parms['password'])

        # Create two time series
        j = {
            'gentity': self.parms['station_id'],
            'variable': self.parms['variable_id'],
            'unit_of_measurement': self.parms['unit_of_measurement_id'],
            'time_zone': self.parms['time_zone_id'],
            'time_step': 3,
            'timestamp_offset_minutes': 0,
            'timestamp_offset_months': 0,
            'remarks': 'Très importante',
        }
        self.ts1_id = enhydris_api.post_model(
            self.parms['base_url'], self.cookies, 'Timeseries', j)
        self.ts2_id = enhydris_api.post_model(
            self.parms['base_url'], self.cookies, 'Timeseries', j)
        assert self.ts1_id != self.ts2_id

        # Add some data (all but the last record) to the database
        ts = Timeseries(self.ts1_id)
        ts.read(StringIO(self.timeseries1_top))
        enhydris_api.post_tsdata(self.parms['base_url'], self.cookies, ts)
        ts = Timeseries(self.ts2_id)
        ts.read(StringIO(self.timeseries2_top))
        enhydris_api.post_tsdata(self.parms['base_url'], self.cookies, ts)

        # Temporary directory for cache files
        self.tempdir = tempfile.mkdtemp()
        self.savedcwd = os.getcwd()
        os.chdir(self.tempdir)
示例#3
0
def create_timeseries(cookies, adict):
    # Create a timeseries on the server and return its id
    j = {'gentity': adict['station_id'],
         'variable': adict['variable_id'],
         'unit_of_measurement': adict['unit_of_measurement_id'],
         'time_zone': adict['time_zone_id'], }
    return enhydris_api.post_model(adict['base_url'], cookies, 'Timeseries', j)
示例#4
0
    def test_get_ts_end_date(self):
        v = json.loads(os.getenv('PTHELMA_TEST_ENHYDRIS_API'))
        cookies = enhydris_api.login(v['base_url'], v['user'], v['password'])

        # Create a time series in the database
        j = {
            'gentity': v['station_id'],
            'variable': v['variable_id'],
            'unit_of_measurement': v['unit_of_measurement_id'],
            'time_zone': v['time_zone_id'],
        }
        ts_id = enhydris_api.post_model(v['base_url'], cookies, 'Timeseries',
                                        j)

        # Get its last date while it has no data
        date = enhydris_api.get_ts_end_date(v['base_url'], cookies, ts_id)
        self.assertEqual(date.isoformat(), '0001-01-01T00:00:00')

        # Now upload some data
        ts = Timeseries(ts_id)
        ts.read(StringIO(self.test_timeseries))
        enhydris_api.post_tsdata(v['base_url'], cookies, ts)

        # Get its last date
        date = enhydris_api.get_ts_end_date(v['base_url'], cookies, ts_id)
        self.assertEqual(date.isoformat(), '2014-01-05T08:00:00')

        # Get the last date of a nonexistent time series
        self.assertRaises(requests.HTTPError, enhydris_api.get_ts_end_date,
                          v['base_url'], cookies, ts_id + 1)
示例#5
0
 def setUp(self):
     # Create two stations, each one with a time series
     parms = settings.BITIA_TEST_ENHYDRIS_INSTALLATION
     self.cookies = enhydris_api.login(parms['base_url'],
                                       parms['user'],
                                       parms['password'])
     self.station1_id = enhydris_api.post_model(
         parms['base_url'], self.cookies, 'Station',
         {'name': 'station1',
          'srid': 4326,
          'point': 'POINT (23.78743 37.97385)',
          'copyright_holder': 'Joe User',
          'copyright_years': '2014',
          'stype': 1,
          'owner': parms['owner_id'],
          })
     self.timeseries1_id = enhydris_api.post_model(
         parms['base_url'], self.cookies, 'Timeseries',
         {'gentity': self.station1_id,
          'variable': parms['variable_id'],
          'unit_of_measurement': parms['unit_of_measurement_id'],
          'time_zone': parms['time_zone_id']})
     self.station2_id = enhydris_api.post_model(
         parms['base_url'], self.cookies, 'Station',
         {'name': 'station1',
          'srid': 4326,
          'point': 'POINT (24.56789 38.76543)',
          'copyright_holder': 'Joe User',
          'copyright_years': '2014',
          'stype': 1,
          'owner': parms['owner_id'],
          })
     self.timeseries2_id = enhydris_api.post_model(
         parms['base_url'], self.cookies, 'Timeseries',
         {'gentity': self.station2_id,
          'variable': parms['variable_id'],
          'unit_of_measurement': parms['unit_of_measurement_id'],
          'time_zone': parms['time_zone_id']})
示例#6
0
    def test_post_tsdata(self):
        v = json.loads(os.getenv('PTHELMA_TEST_ENHYDRIS_API'))
        cookies = enhydris_api.login(v['base_url'], v['user'], v['password'])

        # Create a time series in the database
        j = {
            'gentity': v['station_id'],
            'variable': v['variable_id'],
            'unit_of_measurement': v['unit_of_measurement_id'],
            'time_zone': v['time_zone_id'],
        }
        ts_id = enhydris_api.post_model(v['base_url'], cookies, 'Timeseries',
                                        j)

        # Now upload some data
        ts = Timeseries(ts_id)
        ts.read(StringIO(self.test_timeseries_top))
        enhydris_api.post_tsdata(v['base_url'], cookies, ts)

        # Read and check the time series
        url = enhydris_api.urljoin(v['base_url'],
                                   'timeseries/d/{}/download/'.format(ts.id))
        r = requests.get(url, cookies=cookies)
        r.raise_for_status()
        self.assertEqual(get_after_blank_line(r.text),
                         self.test_timeseries_top)

        # Upload more data
        ts = Timeseries(ts_id)
        ts.read(StringIO(self.test_timeseries_bottom))
        enhydris_api.post_tsdata(v['base_url'], cookies, ts)

        # Read and check the time series
        url = enhydris_api.urljoin(v['base_url'],
                                   'timeseries/d/{}/download/'.format(ts.id))
        r = requests.get(url, cookies=cookies)
        r.raise_for_status()
        self.assertEqual(get_after_blank_line(r.text),
                         self.test_timeseries)
示例#7
0
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.config_file = os.path.join(self.tempdir, 'enhydris_cache.conf')
        self.saved_argv = sys.argv
        sys.argv = ['enhydris_cache', '--traceback', self.config_file]
        self.savedcwd = os.getcwd()

        # Create two stations, each one with a time series
        self.parms = json.loads(os.getenv('PTHELMA_TEST_ENHYDRIS_API'))
        self.cookies = enhydris_api.login(self.parms['base_url'],
                                          self.parms['user'],
                                          self.parms['password'])
        self.station1_id = enhydris_api.post_model(
            self.parms['base_url'], self.cookies, 'Station',
            {'name': 'station1',
             'srid': 4326,
             'point': 'POINT (23.78743 37.97385)',
             'copyright_holder': 'Joe User',
             'copyright_years': '2014',
             'stype': 1,
             'owner': self.parms['owner_id'],
             })
        self.timeseries1_id = enhydris_api.post_model(
            self.parms['base_url'], self.cookies, 'Timeseries',
            {'gentity': self.station1_id,
             'variable': self.parms['variable_id'],
             'unit_of_measurement': self.parms['unit_of_measurement_id'],
             'time_zone': self.parms['time_zone_id']})
        self.station2_id = enhydris_api.post_model(
            self.parms['base_url'], self.cookies, 'Station',
            {'name': 'station1',
             'srid': 4326,
             'point': 'POINT (24.56789 38.76543)',
             'copyright_holder': 'Joe User',
             'copyright_years': '2014',
             'stype': 1,
             'owner': self.parms['owner_id'],
             })
        self.timeseries2_id = enhydris_api.post_model(
            self.parms['base_url'], self.cookies, 'Timeseries',
            {'gentity': self.station2_id,
             'variable': self.parms['variable_id'],
             'unit_of_measurement': self.parms['unit_of_measurement_id'],
             'time_zone': self.parms['time_zone_id']})

        # Prepare a configuration file (some tests override it)
        with open(self.config_file, 'w') as f:
            f.write(textwrap.dedent('''\
                [General]
                cache_dir = {self.tempdir}

                [timeseries1]
                base_url = {base_url}
                id = {self.timeseries1_id}
                file = file1
                user = {self.parms[user]}
                password = {self.parms[password]}

                [timeseries2]
                base_url = {base_url}
                id = {self.timeseries2_id}
                file = file2
                user = {self.parms[user]}
                password = {self.parms[password]}
                ''').format(self=self, base_url=self.parms['base_url']))