def orders_invalidate(self, uts=uts_now(), report_format='csv', report_name=None): """ orders cleanup based on expiry date""" self.logger.debug('Housekeeping.orders_invalidate({0})'.format(uts)) with Order(self.debug, None, self.logger) as order: # get expired orders (field_list, order_list) = order.invalidate(timestamp=uts) # normalize lists (field_list, order_list) = self._lists_normalize(field_list, order_list, 'order') # convert dates into human readable format order_list = self._convert_data(order_list) if report_name: if order_list: # dump report to file if report_format == 'csv': self.logger.debug('Housekeeping.orders_invalidate(): Dump in csv-format') csv_list = self._to_list(field_list, order_list) self._csv_dump('{0}.{1}'.format(report_name, report_format), csv_list) elif report_format == 'json': self.logger.debug('Housekeeping.orders_invalidate(): Dump in json-format') self._json_dump('{0}.{1}'.format(report_name, report_format), order_list) else: self.logger.debug('Housekeeping.orders_invalidate(): No dump just return report') else: self.logger.debug('Housekeeping.orders_invalidate(): No orders to dump') return order_list
def neworders(request): """ new account """ if request.method == 'POST': with Order(DEBUG, get_url(request.META), LOGGER) as norder: response_dic = norder.new(request.body) # create the response response = JsonResponse(status=response_dic['code'], data=response_dic['data']) # generate additional header elements for element in response_dic['header']: response[element] = response_dic['header'][element] if 'Replay-Nonce' not in response: response['Replay-Nonce'] = '' # logging logger_info(LOGGER, request.META['REMOTE_ADDR'], request.META['PATH_INFO'], {'header': { 'Replay-Nonce': response['Replay-Nonce'] }}) # send response return response else: return JsonResponse(status=405, data={ 'status': 405, 'message': 'Method Not Allowed', 'detail': 'Wrong request type. Expected POST.' })
def order(environ, start_response): """ order_handler """ if environ['REQUEST_METHOD'] == 'POST': with Order(DEBUG, get_url(environ), LOGGER) as eorder: request_body = get_request_body(environ) response_dic = eorder.parse(request_body) # create header headers = create_header(response_dic) start_response( '{0} {1}'.format(response_dic['code'], HTTP_CODE_DIC[response_dic['code']]), headers) # logging logger_info(LOGGER, environ['REMOTE_ADDR'], environ['PATH_INFO'], response_dic) return [json.dumps(response_dic['data']).encode('utf-8')] else: start_response('405 {0}'.format(HTTP_CODE_DIC[405]), [('Content-Type', 'application/json')]) return [ json.dumps({ 'status': 405, 'message': HTTP_CODE_DIC[405], 'detail': 'Wrong request type. Expected POST.' }).encode('utf-8') ]
def setUp(self): """ setup unittest """ models_mock = MagicMock() models_mock.acme_srv.db_handler.DBstore.return_value = FakeDBStore modules = {'acme_srv.db_handler': models_mock} patch.dict('sys.modules', modules).start() import logging logging.basicConfig(level=logging.CRITICAL) self.logger = logging.getLogger('test_a2c') from acme_srv.trigger import Trigger from acme_srv.order import Order self.order = Order(False, 'http://tester.local', self.logger) self.trigger = Trigger(False, 'http://tester.local', self.logger)
def order(request): """ order request """ if request.method == 'POST': with Order(DEBUG, get_url(request.META), LOGGER) as eorder: response_dic = eorder.parse(request.body) # create the response response = JsonResponse(status=response_dic['code'], data=response_dic['data']) # generate additional header elements for element in response_dic['header']: response[element] = response_dic['header'][element] # logging logger_info(LOGGER, request.META['REMOTE_ADDR'], request.META['PATH_INFO'], response_dic) # send response return response else: return JsonResponse(status=405, data={'status': 405, 'message': 'Method Not Allowed', 'detail': 'Wrong request type. Expected POST.'})