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() 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 place_order(self, new_order, user): """ Build an order dictionary to be place into the system :param new_order: dictionary representation of the order received :param user: user information associated with the order :return: orderid to be used for tracking """ ts = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f') order_dict = {'orderid': Order.generate_order_id(user.email), 'user_id': user.id, 'order_type': 'level2_ondemand', 'status': 'ordered', 'product_opts': new_order, 'ee_order_id': '', 'order_source': 'espa', 'order_date': ts, 'priority': 'normal', 'note': new_order.get('note', None), 'email': user.email, 'product_options': ''} result = Order.create(order_dict) return result.orderid
def test_production_load_ee_orders_partial(self): order = Order.find(self.mock_order.generate_ee_testing_order(self.user_id, partial=True)) self.assertTrue(order.product_opts == {'format': 'gtiff', 'etm7': {'inputs': ['LE70900652008327EDC00'], 'products': ['sr']}}) production_provider.load_ee_orders() reorder = Order.find(order.id) self.assertTrue(reorder.product_opts == {'format': 'gtiff', 'etm7': {'inputs': ['LE70900652008327EDC00'], 'products': ['sr']}, 'tm5': {'inputs': ['LT50900652008327EDC00'], 'products': ['sr']}})
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 test_production_calc_scene_download_sizes(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scenes = order.scenes() Scene.bulk_update([s.id for s in scenes], {'status': 'complete', 'download_size': 0}) self.assertTrue(production_provider.calc_scene_download_sizes()) upscenes = Scene.where({'status': 'complete', 'download_size': 999}) self.assertEqual(len(upscenes), len(scenes))
def test_production_update_order_if_complete(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) Scene.bulk_update([s.id for s in order.scenes()], {'status': 'retry'}) order.order_source = 'espa' order.completion_email_sent = None order.save() self.assertTrue(production_provider.update_order_if_complete(order))
def names_tuple(self, number, user_id): order_id = self.generate_testing_order(user_id) order = Order.find(order_id) scene_names = [i.name for i in order.scenes()] scene_names = scene_names[0:number] list_of_tuples = [(order.orderid, s) for s in scene_names] return list_of_tuples
def test_production_mark_nlaps_unavailable(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.mark_nlaps_unavailable())
def test_update_product_details_set_product_unavailable(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes()[0] production_provider.update_product('set_product_unavailable', name=scene.name, orderid=order.orderid, processing_loc="L8SRLEXAMPLE", error='include_dswe is an unavailable product option for OLITIRS') self.assertTrue('unavailable' == Scene.get('ordering_scene.status', scene.name, order.orderid))
def test_production_handle_failed_ee_updates(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) for scene in order.scenes(): scene.update('failed_lta_status_update', 'C') production_provider.handle_failed_ee_updates() scenes = Scene.where({'failed_lta_status_update IS NOT': None}) self.assertTrue(len(scenes) == 0)
def test_production_get_contactids_for_submitted_landsat_products(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() response = production_provider.get_contactids_for_submitted_landsat_products() self.assertIsInstance(response, set) self.assertTrue(len(response) > 0)
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 send_all_initial(self): '''Finds all the orders that have not had their initial emails sent and sends them''' orders = Order.where({'status': 'ordered'}) for o in orders: if not o.initial_email_sent: self.send_initial(o.orderid) o.update('initial_email_sent', datetime.datetime.now()) return True
def test_production_handle_submitted_modis_products_input_missing(self): # handle unavailable scenario order = Order.find(self.mock_order.generate_testing_order(self.user_id)) for scene in order.scenes(): scene.status = 'submitted' scene.sensor_type = 'modis' scene.save() sid = scene.id self.assertTrue(production_provider.handle_submitted_modis_products()) self.assertEquals(Scene.find(sid).status, "unavailable")
def test_production_set_product_error_retry(self): """ Move a scene status from error to retry based on the error message """ order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes()[2] production_provider.set_product_error(scene.name, order.orderid, 'somewhere', 'Verify the missing auxillary data products') self.assertTrue('retry' == Scene.get('ordering_scene.status', scene.name, order.orderid))
def test_production_set_product_error_submitted(self): """ Move a scene status from error to submitted based on the error message """ order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes({'name !=': 'plot'})[0] production_provider.set_product_error(scene.name, order.orderid, 'get_products_to_process', 'BLOCK, COMING FROM LST AS WELL: No such file or directory') self.assertTrue('submitted' == Scene.get('ordering_scene.status', scene.name, order.orderid))
def test_production_set_product_error_unavailable(self): """ Move a scene status from error to unavailable based on the error message """ order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes({'name !=': 'plot'})[0] production_provider.set_product_error(scene.name, order.orderid, 'get_products_to_process', 'include_dswe is an unavailable product option for OLITIRS') self.assertTrue('unavailable' == Scene.get('ordering_scene.status', scene.name, order.orderid))
def test_update_product_details_update_status(self): """ Set a scene status to Queued """ order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes()[0] api.update_product_details('update_status', {'name': scene.name, 'orderid': order.orderid, 'processing_loc': 'L8SRLEXAMPLE', 'status': 'Queued'}) self.assertTrue(Scene.get('ordering_scene.status', scene.name, order.orderid) == 'Queued')
def test_update_product_details_set_product_error(self): """ Set a scene status to error :return: """ order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes()[0] production_provider.update_product('set_product_error', name=scene.name, orderid=order.orderid, processing_loc="L8SRLEXAMPLE", error='problems yo') self.assertTrue(Scene.find(scene.id).status == 'error')
def test_update_product_details_mark_product_complete(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes()[0] production_provider.update_product('mark_product_complete', name=scene.name, orderid=order.orderid, processing_loc='L8SRLEXAMPLE', completed_file_location='/some/loc', cksum_file_location='some checksum', log_file_contents='some log') self.assertTrue('complete' == Scene.get('ordering_scene.status', scene.name, order.orderid))
def test_fetch_production_products_plot(self): order_id = self.mock_order.generate_testing_order(self.user_id) self.mock_order.update_scenes(order_id, 'status', ['complete']) order = Order.find(order_id) plot_scene = order.scenes()[0] plot_scene.name = 'plot' plot_scene.sensor_type = 'plot' plot_scene.status = 'submitted' plot_scene.save() response = production_provider.handle_submitted_plot_products() pscene = order.scenes({'status': 'oncache', 'sensor_type': 'plot'}) self.assertTrue(response is True) self.assertEqual(len(pscene), 1)
def test_update_product_details_mark_product_complete(self): order = Order.find(self.mock_order.generate_testing_order( self.user_id)) scene = order.scenes()[0] production_provider.update_product('mark_product_complete', name=scene.name, orderid=order.orderid, processing_loc='L8SRLEXAMPLE', completed_file_location='/some/loc', cksum_file_location='some checksum', log_file_contents='some log') self.assertTrue('complete' == Scene.get('ordering_scene.status', scene.name, order.orderid))
def test_update_product_details_fail_lta_mark_product_complete(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes()[1] order.update('order_source', 'ee') production_provider.update_product('mark_product_complete', name=scene.name, orderid=order.orderid, processing_loc='L8SRLEXAMPLE', completed_file_location='/some/loc', cksum_file_location='some checksum', log_file_contents='some log') s = Scene.where({'name': scene.name, 'order_id': scene.order_id})[0] self.assertTrue('C' == s.failed_lta_status_update)
def test_update_product_details_set_product_error(self): """ Set a scene status to error :return: """ order = Order.find(self.mock_order.generate_testing_order( self.user_id)) scene = order.scenes()[0] production_provider.update_product('set_product_error', name=scene.name, orderid=order.orderid, processing_loc="L8SRLEXAMPLE", error='problems yo') self.assertTrue(Scene.find(scene.id).status == 'error')
def test_production_set_product_error_retry_missing_mtl(self): """ Move a scene status from error to retry based on the error message """ order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes({'sensor_type': 'landsat'})[-1] log_file_contents = ('BLAH BLAH BLAH ESPAException: Unable to ' 'locate the MTL file in ' '[a path to a mtl file somewhere] BLAH BLAH BLAH') production_provider.set_product_error(scene.name, order.orderid, 'somewhere', log_file_contents) self.assertTrue('retry' == Scene.get('ordering_scene.status', scene.name, order.orderid))
def test_production_handle_onorder_landsat_products(self): tram_order_ids = lta.sample_tram_order_ids()[0:3] scene_names = lta.sample_scene_names()[0:3] order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scenes = order.scenes()[0:3] for idx, scene in enumerate(scenes): scene.tram_order_id = tram_order_ids[idx] scene.status = 'onorder' # save() doesn't let you update name, # b/c updating a scene name is not acceptable # outside of testing scene.update('name', scene_names[idx]) scene.save() self.assertTrue(production_provider.handle_onorder_landsat_products())
def test_production_handle_onorder_landsat_products(self): tram_order_ids = lta.sample_tram_order_ids()[0:3] scene_names = lta.sample_scene_names()[0:3] order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scenes = order.scenes()[0:3] for idx, scene in enumerate(scenes): scene.tram_order_id = tram_order_ids[idx] scene.status = 'onorder' # save() doesn't let you update name, # b/c updating a scene name is not acceptable # outside of testing scene.update('name', scene_names[idx]) scene.save() self.assertTrue(production_provider.handle_onorder_landsat_products(scenes))
def test_production_set_product_error_unavailable_almost_night(self): """ Move a scene status from error to unavailable based on the solar zenith (SR) error message """ order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes({'name !=': 'plot'})[0] production_provider.set_product_error(name=scene.name, orderid=order.orderid, processing_loc='L8SRLEXAMPLE', error='solar zenith angle is too large') scene = Scene.by_name_orderid(name=scene.name, order_id=order.id) self.assertTrue('unavailable' == scene.status) self.assertTrue('Solar zenith angle is too large, cannot process scene to SR' in scene.note)
def test_production_set_product_retry(self): order_id = self.mock_order.generate_testing_order(self.user_id) order = Order.find(order_id) scene = order.scenes()[3] scene.update('retry_count', 4) processing_loc = "get_products_to_process" error = 'not available after EE call ' note = 'note this' retry_after = datetime.datetime.now() + datetime.timedelta(hours=1) retry_limit = 9 response = production_provider.set_product_retry(scene.name, order.orderid, processing_loc, error, note, retry_after, retry_limit) new = Scene.get('ordering_scene.status', scene.name, order.orderid) self.assertTrue('retry' == new)
def test_production_set_product_error_unavail_ncep(self): """ Move a scene status from error to unavailable based on the error message """ order = Order.find(self.mock_order.generate_testing_order(self.user_id)) scene = order.scenes({'sensor_type': 'landsat'})[-1] log_file_contents = ('BLAH BLAH BLAH Warning: lndpm : Could not find ' 'NCEP REANALYSIS auxiliary data: a_file_.hdf ' 'Check LEDAPS_AUX_DIR environment variable. ' 'Error: lndpm : Verify the missing auxiliary data products, ' 'then try reprocessing. BLAH BLAH BLAH') production_provider.set_product_error(scene.name, order.orderid, 'somewhere', log_file_contents) self.assertEqual('unavailable', Scene.get('ordering_scene.status', scene.name, order.orderid))
def test_production_set_product_error_unavail_reproject(self): """ Move a scene status from error to retry based on the error message """ order = Order.find(self.mock_order.generate_testing_order( self.user_id)) scene = order.scenes({'sensor_type': 'landsat'})[-1] log_file_contents = ('BLAH BLAH BLAH WarpVerificationError: Failed to ' 'compute statistics, no valid pixels found in ' 'sampling BLAH BLAH BLAH') production_provider.set_product_error(scene.name, order.orderid, 'somewhere', log_file_contents) self.assertEqual( 'unavailable', Scene.get('ordering_scene.status', scene.name, order.orderid))
def error_to(self, orderid, state): order = Order.find(orderid) err_scenes = order.scenes({'status': 'error'}) try: for scene in err_scenes: scene.update('status', state) if state == 'submitted': order.status = 'ordered' order.completion_email_sent = None order.save() return True except SceneException as e: logger.debug('ERR admin provider error_to\ntrace: {}'.format(e.message)) raise AdministrationProviderException('ERR updating with error_to')
def send_completion(self, order): if not isinstance(order, Order): order = Order.find(order) messages = {'complete': ['{orderid} is now complete and can be downloaded from {url}', '', '', 'For large orders, the ESPA Bulk Downloader is available {bdurl}', '', '', 'This order will remain available for 10 days. Any data not downloaded ' 'will need to be reordered after this time.', '', '', 'Please contact Customer Services at 1-800-252-4547 or ' 'email [email protected] with any questions.', '', '', 'Requested products', '-------------------------------------------' ], 'unsuccessful': ['{orderid} was unsuccessful, and the reason can be found at {url}', '', '', 'This order will remain available for 10 days.', '', '', 'Please contact Customer Services at 1-800-252-4547 or ' 'email [email protected] with any questions.', '', '', 'Requested products', '-------------------------------------------' ] } scenes = order.scenes({'status': 'complete'}) status = 'complete' if len(scenes) > 0 else 'unsuccessful' outmessage = messages[status] email = order.user_email() url = self.__order_status_url(order.orderid) bdl_url = "https://github.com/USGS-EROS/espa-bulk-downloader" scenes = order.scenes() pbs = order.products_by_sensor() for product in scenes: if product.sensor_type == 'plot': line = "plotting & statistics" else: if product.status == 'complete': line = "{}: {}".format(product.name, ", ".join(pbs[product.name])) else: line = "{}: {}".format(product.name, product.note.strip()) outmessage.append(line) outmessage.append(contact_footer) body = '\n'.join(outmessage).format(url=url, bdurl=bdl_url, orderid=order.orderid) subject = 'USGS ESPA Processing for {} {}'.format(order.orderid, status) return self.__send(recipient=email, subject=subject, body=body)
def test_update_product_details_update_status(self): """ Set a scene status to Queued """ order = Order.find(self.mock_order.generate_testing_order( self.user_id)) scene = order.scenes()[0] api.update_product_details( 'update_status', { 'name': scene.name, 'orderid': order.orderid, 'processing_loc': 'L8SRLEXAMPLE', 'status': 'Queued' }) self.assertTrue( Scene.get('ordering_scene.status', scene.name, order.orderid) == 'Queued')
def error_to(self, orderid, state): order = Order.find(orderid) err_scenes = order.scenes({'status': 'error'}) try: for scene in err_scenes: scene.update('status', state) if state == 'submitted': order.status = 'ordered' order.completion_email_sent = None order.save() return True except SceneException as e: logger.debug('ERR admin provider error_to\ntrace: {}'.format( e.message)) raise AdministrationProviderException('ERR updating with error_to')
def fetch_user_orders_ext(self, uid, filters={}): orders = self.fetch_user_orders(uid, filters=filters) if 'orders' not in orders.keys(): return orders orders_d = orders['orders'] output = [] for orderid in orders_d: order = Order.find(orderid) products_complete = order.scene_status_count('complete') products_error = order.scene_status_count('error') products_ordered = order.scene_status_count() out_d = {'orderid': orderid, 'products_ordered': products_ordered, 'products_complete': products_complete, 'products_error': products_error, 'order_status': order.status, 'order_note': order.note} output.append(out_d) return output
def fetch_user_orders(self, uid, filters=None): # deal with unicode uid if isinstance(uid, basestring): uid = str(uid) try: user = User.where({'username': uid}).pop() except IndexError: try: user = User.where({'email': uid}).pop() except IndexError: return {'msg': 'sorry, no user matched {0}'.format(uid)} if filters and not isinstance(filters, dict): raise OrderingProviderException('filters param must be of type dict') elif filters: params = dict(filters) params.update({'user_id': user.id}) else: params = {'user_id': user.id} return {'orders': [o.orderid for o in Order.where(params)]}
def send_initial(self, order_id): if isinstance(order_id, Order): order = order_id else: order = Order.find(order_id) if not isinstance(order, Order): msg = 'order must be str of orderid, int of pk or instance of Order' raise TypeError(msg) email = order.user_email() url = self.__order_status_url(order.orderid) m = list() m.append("Thank you for your order.\n\n") m.append("%s has been received and is currently " % order.orderid) m.append("being processed. ") m.append("Another email will be sent when this order is complete.\n\n") m.append("You may view the status of your order and download ") m.append("completed products directly from %s\n\n" % url) m.append("Requested products\n") m.append("-------------------------------------------\n") scenes = order.scenes() for product in scenes: name = product.name if name == 'plot': name = "Plotting & Statistics" m.append("%s\n" % name) m.append(contact_footer) email_msg = ''.join(m) subject = 'USGS ESPA Processing order %s received' % order.orderid return self.__send(recipient=email, subject=subject, body=email_msg)
def send_order_cancelled_email(self, order_id): if isinstance(order_id, Order): order = order_id else: order = Order.find(order_id) if not isinstance(order, Order): msg = 'order must be str of orderid, int of pk or instance of Order' raise TypeError(msg) email = order.user_email() orderid = str(order.orderid).strip() n_scenes_cancelled = len(order.scenes({'status': 'cancelled'})) n_scenes_running = len(order.scenes()) - n_scenes_cancelled email_template = ( "Your order {orderid} has been cancelled.\n" "A total of {n_scenes} scenes have been stopped.\n" "{running_message}\n\n\n\n" "Please contact Customer Services at 1-800-252-4547 or " "email [email protected] with any questions.\n\n" "This is an automated email.\n\n" "-------------------------------------------\n\n" "{contact_footer}" ) running_message = ('({n} scenes could not be immediately halted, but ' 'will finish in a cancelled state)' .format(n=n_scenes_running) if n_scenes_running else '') information = dict(n_scenes=n_scenes_cancelled, running_message=running_message, contact_footer=contact_footer, orderid=orderid) email_msg = email_template.format(**information) subject = ('USGS ESPA Processing order {orderid} cancelled' .format(orderid=orderid)) return self.__send(recipient=email, subject=subject, body=email_msg)
def send_initial(self, order_id): if isinstance(order_id, Order): order = order_id else: order = Order.find(order_id) if not isinstance(order, Order): msg = 'order must be str of orderid, int of pk or instance of Order' raise TypeError(msg) email = order.user_email() url = self.__order_status_url(order.orderid) m = list() m.append("Thank you for your order.\n\n") m.append("%s has been received and is currently " % order.orderid) m.append("being processed. ") m.append("Another email will be sent when this order is complete.\n\n") m.append("You may view the status of your order and download ") m.append("completed products directly from %s\n\n" % url) m.append("Requested products\n") m.append("-------------------------------------------\n") scenes = order.scenes() for product in scenes: name = product.name if name == 'plot': name = "Plotting & Statistics" m.append("%s\n" % name) m.append(contact_footer) email_msg = ''.join(m) subject = 'Processing order %s received' % order.orderid return self.__send(recipient=email, subject=subject, body=email_msg)
def send_completion(self, order): if not isinstance(order, Order): order = Order.find(order) email = order.user_email() url = self.__order_status_url(order.orderid) bdl_url = "https://github.com/USGS-EROS/espa-bulk-downloader" m = list() m.append("%s is now complete and can be downloaded " % order.orderid) m.append("from %s.\n\n" % url) m.append( "For large orders, the ESPA Bulk Downloader is available %s \n\n" % bdl_url) m.append("This order will remain available for 10 days. ") m.append("Any data not downloaded will need to be reordered ") m.append("after this time.\n\n") m.append("Please contact Customer Services at 1-800-252-4547 or ") m.append("email [email protected] with any questions.\n\n") m.append("Requested products\n") m.append("-------------------------------------------\n") scenes = order.scenes({"status": "complete"}) pbs = order.products_by_sensor() for product in scenes: if product.sensor_type == 'plot': line = "plotting & statistics" else: line = "{}: {}".format(product.name, ", ".join(pbs[product.name])) m.append("%s\n" % line) body = ''.join(m) subject = 'Processing for %s complete.' % order.orderid return self.__send(recipient=email, subject=subject, body=body)
def fetch_user_orders_feed(self, email): orders = self.fetch_user_orders(email) if 'orders' not in orders.keys(): return orders cache_key = "{0}_feed".format(email) outd = cache.get(cache_key) or {} if not outd: for orderid in orders['orders']: order = Order.find(orderid) scenes = order.scenes({"status": "complete"}) if scenes: outd[order.orderid] = {'orderdate': str(order.order_date)} scene_list = [] for scene in scenes: scene_list.append({'name': scene.name, 'url': scene.product_dload_url, 'status': scene.status}) outd[order.orderid]['scenes'] = scene_list cache.set(cache_key, outd) return outd
def test_get_scenes_for_new_user(self): """ Make sure that checking the number of open scenes for a new user with no orders will not raise an exception """ mock = MockOrder() user = MockUser() user_id = user.add_testing_user() user_id = user_id + random.randint(1, 200) user_orders = Order.where({'user_id': user_id}) self.assertTrue(len(user_orders) == 0) try: ordering_provider.check_open_scenes(order=mock.base_order, user_id=user_id, filters={'status': ('submitted', 'oncache', 'onorder', 'queued', 'processing')}) except: self.fail('ordering_provider.check_open_scenes() raised Exception for new user')
def test_production_handle_submitted_plot_products(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) order.status = 'ordered' order.order_type = 'lpcs' order.save() plot_id = None for idx, scene in enumerate(order.scenes()): # at the moment, mock_order.generate_testing_order # creates 21 products for the order. divvy those # up between 'complete' and 'unavailable', setting # one aside as the 'plot' product if idx % 2 == 0: if idx == 0: # need to define a plot product scene.update('status', 'submitted') scene.update('sensor_type', 'plot') plot_id = scene.id else: scene.update('status', 'complete') else: scene.update('status', 'unavailable') self.assertTrue(production_provider.handle_submitted_plot_products()) self.assertEqual(Scene.find(plot_id).status, "oncache")
def test_production_finalize_orders(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) order.update('status', 'ordered') self.assertTrue(production_provider.finalize_orders())
def test_production_set_products_unavailable(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) self.assertTrue(production_provider.set_products_unavailable(order.scenes(), "you want a reason?"))
def test_production_send_initial_emails(self): order = Order.find(self.mock_order.generate_testing_order(self.user_id)) order.update('status', 'ordered') self.assertTrue(emails.Emails().send_all_initial())
def test_production_purge_orders(self): new_completion_date = datetime.datetime.now() - datetime.timedelta(days=12) order = Order.find(self.mock_order.generate_testing_order(self.user_id)) order.update('status', 'complete') order.update('completion_date', new_completion_date) self.assertTrue(production_provider.purge_orders())
def test_production_handle_submitted_landsat_products(self): orders = Order.find( self.mock_order.generate_testing_order(self.user_id)) scenes = orders.scenes({'sensor_type': 'landsat'}) self.assertTrue( production_provider.handle_submitted_landsat_products(scenes))
def fetch_order(self, ordernum): orders = Order.where({'orderid': ordernum}) return orders
def cancel_order(cls, orderid, request_address): order = Order.find(orderid) order.status = 'cancelled' order.save() return order