def setUp(self): logger.warning('Testing API started...') os.environ['espa_api_testing'] = 'True' # create a user self.mock_user = MockUser() self.mock_order = MockOrder() user_id = self.mock_user.add_testing_user() order_id = self.mock_order.generate_testing_order(user_id) self.order = Order.find(order_id) self.user = User.find(user_id) self.product_id = 'LT05_L1TP_032028_20120425_20160830_01_T1' self.sensor_id = 'tm5_collection' self.staff_product_id = 'LE07_L1TP_010028_20050420_20160925_01_T1' self.staff_sensor = 'etm7_collection' self.global_product_id = 'LE70450302003206EDC01' staff_user_id = self.mock_user.add_testing_user() self.staff_user = User.find(staff_user_id) self.staff_user.update('is_staff', True) staff_order_id = self.mock_order.generate_testing_order(staff_user_id) staff_order = Order.find(staff_order_id) staff_scene = staff_order.scenes()[0] staff_scene.update('name', self.staff_product_id) user_scene = self.order.scenes()[0] user_scene.update('name', self.staff_product_id) with open(os.path.join(__location__, 'domain/restricted.yaml')) as f: self.restricted = yaml.load(f.read()) self.restricted['all']['role'].remove('restricted_prod')
def setUp(self): os.environ['espa_api_testing'] = 'True' # create a user self.mock_user = MockUser() self.mock_order = MockOrder() user_id = self.mock_user.add_testing_user() order_id = self.mock_order.generate_testing_order(user_id) self.order = Order.find(order_id) self.user = User.find(user_id) self.product_id = 'LT50150401987120XXX02' self.staff_product_id = 'LE70450302003206EDC01' staff_user_id = self.mock_user.add_testing_user() self.staff_user = User.find(staff_user_id) self.staff_user.update('is_staff', True) staff_order_id = self.mock_order.generate_testing_order(staff_user_id) staff_order = Order.find(staff_order_id) staff_scene = staff_order.scenes()[0] staff_scene.update('name', self.staff_product_id) user_scene = self.order.scenes()[0] user_scene.update('name', self.staff_product_id) with open('api/domain/restricted.yaml') as f: self.restricted = yaml.load(f.read()) self.restricted['all']['role'].remove('restricted_prod')
def setUp(self): os.environ['espa_api_testing'] = 'True' # create a user self.mock_user = MockUser() self.mock_order = MockOrder() user_id = self.mock_user.add_testing_user() order_id = self.mock_order.generate_testing_order(user_id) self.order = Order.find(order_id) self.user = User.find(user_id) self.product_id = 'LT50150401987120XXX02' self.staff_product_id = 'LE70450302003206EDC01' staff_user_id = self.mock_user.add_testing_user() self.staff_user = User.find(staff_user_id) self.staff_user.update('is_staff', True) staff_order_id = self.mock_order.generate_testing_order(staff_user_id) staff_order = Order.find(staff_order_id) staff_scene = staff_order.scenes()[0] staff_scene.update('name', self.staff_product_id) user_scene = self.order.scenes()[0] user_scene.update('name', self.staff_product_id) with open('api/domain/restricted.yaml') as f: self.restricted = yaml.load(f.read()) self.restricted['all']['role'].remove('restricted_prod')
def test_production_update_landsat_product_status(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) for scene in order.scenes(): scene.status = 'submitted' scene.sensor_type = 'landsat' scene.save() self.assertTrue(production_provider.update_landsat_product_status(User.find(self.user_id).contactid))
def setUp(self): os.environ['espa_api_testing'] = 'True' # create a user self.mock_user = MockUser() self.mock_order = MockOrder() self.user = User.find(self.mock_user.add_testing_user()) self.order_id = self.mock_order.generate_testing_order(self.user.id) self.app = http.app.test_client() self.app.testing = True self.sceneids = self.mock_order.scene_names_list(self.order_id)[0:2] token = ''.format(self.user.username, 'foo') auth_string = "Basic {}".format(base64.b64encode(token)) self.headers = {"Authorization": auth_string} with db_instance() as db: uidsql = "select user_id, orderid from ordering_order limit 1;" db.select(uidsql) self.userid = db[0]['user_id'] self.orderid = db[0]['orderid'] itemsql = "select name, order_id from ordering_scene limit 1;" db.select(itemsql) self.itemid = db[0][0] itemorderid = db[0][1] ordersql = "select orderid from ordering_order where id = {};".format(itemorderid) db.select(ordersql) self.itemorderid = db[0][0] self.base_order = lowercase_all(testorders.build_base_order())
def generate_ee_testing_order(self, user_id, partial=False): ee_order = mock_lta.get_available_orders_partial(partial) # Have to emulate a bunch of load_ee_orders for eeorder, email_addr, contactid in ee_order: order_id = Order.generate_ee_order_id(email_addr, eeorder) scene_info = ee_order[eeorder, email_addr, contactid] user = User.find(user_id) ts = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') order_dict = {'orderid': order_id, 'user_id': user.id, 'order_type': 'level2_ondemand', 'status': 'ordered', 'note': 'EarthExplorer order id: {}'.format(eeorder), 'ee_order_id': eeorder, 'order_source': 'ee', 'order_date': ts, 'priority': 'normal', 'email': user.email, 'product_options': 'include_sr: true', 'product_opts': Order.get_default_ee_options(scene_info)} order = Order.create(order_dict) self.production_provider.load_ee_scenes(scene_info, order.id) return order.id
def setUp(self): os.environ['espa_api_testing'] = 'True' # create a user self.mock_user = MockUser() self.mock_order = MockOrder() self.user = User.find(self.mock_user.add_testing_user()) self.order_id = self.mock_order.generate_testing_order(self.user.id) self.app = http.app.test_client() self.app.testing = True self.sceneids = self.mock_order.scene_names_list(self.order_id)[0:2] token = ''.format(self.user.username, 'foo') auth_string = "Basic {}".format(base64.b64encode(token)) self.headers = {"Authorization": auth_string} with db_instance() as db: uidsql = "select user_id, orderid from ordering_order limit 1;" db.select(uidsql) self.userid = db[0]['user_id'] self.orderid = db[0]['orderid'] itemsql = "select name, order_id from ordering_scene limit 1;" db.select(itemsql) self.itemid = db[0][0] itemorderid = db[0][1] ordersql = "select orderid from ordering_order where id = {};".format( itemorderid) db.select(ordersql) self.itemorderid = db[0][0] self.base_order = lowercase_all(testorders.build_base_order())
def test_production_update_landsat_product_status(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) for scene in order.scenes(): scene.status = 'submitted' scene.sensor_type = 'landsat' scene.save() self.assertTrue(production_provider.update_landsat_product_status(User.find(self.user_id).contactid))
def generate_ee_testing_order(self, user_id, partial=False): ee_order = mock_lta.get_available_orders_partial(partial) # Have to emulate a bunch of load_ee_orders for eeorder, email_addr, contactid in ee_order: order_id = Order.generate_ee_order_id(email_addr, eeorder) scene_info = ee_order[eeorder, email_addr, contactid] user = User.find(user_id) ts = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') order_dict = { 'orderid': order_id, 'user_id': user.id, 'order_type': 'level2_ondemand', 'status': 'ordered', 'note': 'EarthExplorer order id: {}'.format(eeorder), 'ee_order_id': eeorder, 'order_source': 'ee', 'order_date': ts, 'priority': 'normal', 'email': user.email, 'product_options': 'include_sr: true', 'product_opts': Order.get_default_ee_options(scene_info) } order = Order.create(order_dict) self.production_provider.load_ee_scenes(scene_info, order.id) return order.id
def generate_testing_order(self, user_id): user = User.find(user_id) # need to monkey with the email, otherwise we get collisions with each # test creating a new scratch order with the same user rand = str(random.randint(1, 99)) user.email = rand + user.email order = self.ordering_provider.place_order(self.base_order, user) return order.id
def test_fetch_production_products_landsat(self): order_id = self.mock_order.generate_testing_order(self.user_id) # need scenes with statuses of 'processing' and 'ordered' self.mock_order.update_scenes(order_id, 'status', ['processing','oncache','ordered']) user = User.find(self.user_id) params = {'for_user': user.username, 'product_types': ['landsat']} response = api.fetch_production_products(params) self.assertTrue('bilbo' in response[0]['orderid'])
def test_fetch_production_products_landsat(self): order_id = self.mock_order.generate_testing_order(self.user_id) # need scenes with statuses of 'processing' and 'ordered' self.mock_order.update_scenes(order_id, 'status', ['processing','oncache','ordered']) user = User.find(self.user_id) params = {'for_user': user.username, 'product_types': ['landsat']} response = api.fetch_production_products(params) self.assertTrue('bilbo' in response[0]['orderid'])
def setUp(self): os.environ['espa_api_testing'] = 'True' self.mock_user = MockUser() self.staffuser = User.find(self.mock_user.add_testing_user()) self.staffuser.update('is_staff', True) self.base_order = lowercase_all(testorders.build_base_order()) self.base_schema = BaseValidationSchema.request_schema
def generate_testing_order(self, user_id): user = User.find(user_id) # need to monkey with the email, otherwise we get collisions with each # test creating a new scratch order with the same user rand = str(random.randint(1, 99)) user.email = rand + user.email orderid = self.ordering_provider.place_order(self.base_order, user) order = Order.find(orderid) return order.id
def setUp(self): os.environ['espa_api_testing'] = 'True' self.mock_user = MockUser() self.staffuser = User.find(self.mock_user.add_testing_user()) self.staffuser.update('is_staff', True) self.base_order = lowercase_all(testorders.build_base_order()) self.base_schema = BaseValidationSchema.request_schema
def test_fetch_production_products_sentinel(self): order_id = self.mock_order.generate_testing_order(self.user_id) # need scenes with statuses of 'processing' scenes = Scene.where({'order_id': order_id, 'sensor_type': 'sentinel'}) self.mock_order.update_scenes(order_id, 'sentinel', 'status', ['processing', 'oncache']) user = User.find(self.user_id) params = {'for_user': user.username, 'product_types': ['sentinel']} response = api.fetch_production_products(params) self.assertTrue('bilbo' in response[0]['orderid'])
def test_fetch_production_products_landsat(self): os.environ['ESPA_M2M_MODE'] = 'LANDSAT,MODIS,URLS' order_id = self.mock_order.generate_testing_order(self.user_id) # need scenes with statuses of 'processing' self.mock_order.update_scenes(order_id, 'landsat', 'status', ['processing', 'oncache']) user = User.find(self.user_id) params = {'for_user': user.username, 'product_types': ['landsat']} response = api.fetch_production_products(params) self.assertTrue('bilbo' in response[0]['orderid']) os.environ['ESPA_M2M_MODE'] = ''
def test_fetch_production_products_landsat(self): cfg.put('system.m2m_url_enabled', 'True') cfg.put('system.m2m_val_enabled', 'True') order_id = self.mock_order.generate_testing_order(self.user_id) # need scenes with statuses of 'processing' self.mock_order.update_scenes(order_id, 'landsat', 'status', ['processing', 'oncache']) user = User.find(self.user_id) params = {'for_user': user.username, 'product_types': ['landsat']} response = api.fetch_production_products(params) self.assertTrue('bilbo' in response[0]['orderid']) cfg.put('system.m2m_url_enabled', 'False') cfg.put('system.m2m_val_enabled', 'False')
def setUp(self): os.environ['espa_api_testing'] = 'True' # create a user self.mock_user = MockUser() self.mock_order = MockOrder() self.user = User.find(self.mock_user.add_testing_user()) self.order_id = self.mock_order.generate_testing_order(self.user.id) self.app = http.app.test_client() self.app.testing = True self.sceneids = self.mock_order.scene_names_list(self.order_id)[0:2] token = ':'.join((self.user.username, 'foo')) auth_string = "Basic {}".format(base64.b64encode(token)) self.headers = {"Authorization": auth_string} with db_instance() as db: uidsql = "select user_id, orderid from ordering_order limit 1;" db.select(uidsql) self.userid = db[0]['user_id'] self.orderid = db[0]['orderid'] itemsql = "select name, order_id from ordering_scene limit 1;" db.select(itemsql) self.itemid = db[0][0] itemorderid = db[0][1] ordersql = "select orderid from ordering_order where id = {};".format( itemorderid) db.select(ordersql) self.itemorderid = db[0][0] self.base_order = lowercase_all(testorders.build_base_order()) self.sensors = [ k for k in self.base_order.keys() if isinstance(self.base_order[k], dict) and 'inputs' in self.base_order[k] ] self.inputs = {s: self.base_order[s]['inputs'] for s in self.sensors} self.input_names_all = set([ i for sublist in [s for k, s in self.inputs.items()] for i in sublist ])
def test_handle_orders_success(self): _ = self.mock_order.generate_testing_order(self.user_id) self.assertTrue( api.handle_orders({'username': User.find(self.user_id)}))