Commit 2b11025da0e9cbd23de4150a103c3e9797361dbe

Authored by hitier
1 parent 9b97b286
Exists in rhitier-dev and in 1 other branch DEV

Add 2 more tests

Showing 1 changed file with 35 additions and 5 deletions   Show diff stats
tests/BackendTests.py
1 1 import sys
2 2 import unittest
3   -from datetime import datetime as ddatetime
  3 +from datetime import datetime as ddatetime, datetime
4 4 from pprint import pprint
5 5  
6   -from web.run import retrieve_amda_netcdf
  6 +from web.run import retrieve_amda_netcdf, get_data_for_target, _sta_sto
  7 +
  8 +FILE_DATE_FMT = "%Y-%m-%d %H:%M:%S"
7 9  
8 10  
9 11 class BaseTestCase(unittest.TestCase):
... ... @@ -29,12 +31,40 @@ class BaseTestCase(unittest.TestCase):
29 31 class AmdaTestCase(BaseTestCase):
30 32  
31 33 def test_amda_retrieve(self):
32   - FILE_DATE_FMT = "%Y-%m-%d %H:%M:%S"
33 34 started_at = ddatetime.strptime("2021-12-17 00:00:00", FILE_DATE_FMT)
34 35 stopped_at = ddatetime.strptime("2021-12-18 00:00:00", FILE_DATE_FMT)
35 36 amda_list = retrieve_amda_netcdf("earth", "omni_hour_all", started_at, stopped_at)
36 37 self.assertEqual(1, len(amda_list))
37 38 self.assertIn('amda-irap-omp-eu-ddservice-base-data-omni-hour-omni202107010-nc', amda_list[0])
38 39  
39   - def test_projects(self):
40   - self.assertTrue(False)
  40 + def test_get_data_for_target(self):
  41 + target_config = {'type': 'planet', 'slug': 'earth', 'name': 'Earth', 'title': 'Earth', 'orbit': {'models': []},
  42 + 'models': {
  43 + 'om': [{'slug': 'omni_hour_all', 'parameters': {'pdyn': 'RamP'}},
  44 + {'slug': 'ace_swepam_real_1h',
  45 + 'parameters': {'dens': 'Dens', 'vtot': 'Vel', 'temp': 'Temp'}}],
  46 + 'sa': [{'slug': 'omni_hour_all', 'parameters': {'pdyn': 'RamP'}},
  47 + {'slug': 'ace_swepam_real_1h',
  48 + 'parameters': {'dens': 'Dens', 'vtot': 'Vel', 'temp': 'Temp'}}],
  49 + 'sb': [{'slug': 'omni_hour_all', 'parameters': {'pdyn': 'RamP'}},
  50 + {'slug': 'ace_swepam_real_1h',
  51 + 'parameters': {'dens': 'Dens', 'vtot': 'Vel', 'temp': 'Temp'}}]},
  52 + 'locked': False, 'default': True, 'catalog_layers': {'cmecatalogs': []}}
  53 +
  54 + started_at = ddatetime.strptime("2021-12-17 00:00:00", FILE_DATE_FMT)
  55 + stopped_at = ddatetime.strptime("2021-12-18 00:00:00", FILE_DATE_FMT)
  56 + model = {'parameters': {'dens': 'Dens', 'temp': 'Temp', 'vtot': 'Vel'}, 'slug': 'ace_swepam_real_1h'}
  57 + s0, s1 = _sta_sto(model, started_at, stopped_at)
  58 + all_data = get_data_for_target(target_config, 'om', s0, s1 )
  59 + self.assertEqual(1, len(all_data))
  60 +
  61 + def test_sta_sto(self):
  62 + started_at = ddatetime.strptime("2021-12-17 00:00:00", FILE_DATE_FMT)
  63 + stopped_at = ddatetime.strptime("2021-12-18 00:00:00", FILE_DATE_FMT)
  64 + model = {'parameters': {'dens': 'Dens', 'temp': 'Temp', 'vtot': 'Vel'}, 'slug': 'ace_swepam_real_1h'}
  65 +
  66 + s0, s1 = _sta_sto(model, started_at, stopped_at)
  67 +
  68 + self.assertIsInstance(s0, datetime)
  69 + self.assertIsInstance(s1, datetime)
  70 +
... ...