コード例 #1
0
def before_all(context):
	cache_utils.clear_db()
	# __clear_all_account_data()
	# __create_system_user('jobs')
	# __create_system_user('bill')
	# __create_system_user('tom')

	weapp_working_dir = os.path.join(settings.WEAPP_DIR, 'weapp')
	if not os.path.exists(weapp_working_dir):
		info = '* ERROR: CAN NOT do bdd testing. Because bdd need %s be exists!!!' % weapp_working_dir
		info = info.replace(os.path.sep, '/')
		print('*' * 80)
		print(info)
		print('*' * 80)
		sys.exit(3)

	#创建test case,使用assert
	context.tc = unittest.TestCase('__init__')
	bdd_util.tc = context.tc

	#设置bdd模式
	settings.IS_UNDER_BDD = True

	#启动weapp下的bdd server
	#print u'TODO2: 启动weapp下的bdd server'
	watchdog.warning(u'TODO2: 启动weapp下的bdd server')

	#登录添加App
	#client = bdd_util.login('manager')

	# 让Celery以同步方式运行
	celeryconfig.CELERY_ALWAYS_EAGER = True
コード例 #2
0
ファイル: task.py プロジェクト: nuaays/apiserver
def __send_email(user_id, emails, content_described, content):
    try:
        for email in emails.split('|'):
            if email.find('@') > -1:
                sendmail(email, content_described, content)
    except:
        notify_message = u"发送邮件失败user_id({}), cause:\n{}".format(
            user_id, unicode_full_stack())
        watchdog.warning(notify_message)
コード例 #3
0
ファイル: utils.py プロジェクト: chengdg/weizoom
def watchdog_notice(message, type='WEB', user_id='0', db_name='default'):
    """
	用异步方式发watchdog

	异步方式调用 weapp.services.send_watchdog_service.send_watchdog()
	"""
    watchdog.warning(message=message,
                     log_type=type,
                     user_id=user_id,
                     server_name='weapp')
コード例 #4
0
ファイル: emojicons_util.py プロジェクト: nuaays/apiserver
def contains_emojicons(unicode_or_utf8str_with_decoded_emojicons,
                       is_hex_str=False):
    global ALL_EMOJICONS_UTF8_PRREFIX_SET

    if unicode_or_utf8str_with_decoded_emojicons is None:
        return False

    if isinstance(unicode_or_utf8str_with_decoded_emojicons, unicode):
        utf8str_with_decoded_emojicons = unicode_or_utf8str_with_decoded_emojicons.encode(
            'utf-8')
    else:
        utf8str_with_decoded_emojicons = unicode_or_utf8str_with_decoded_emojicons

    __build_all_emojicons_utf8_prefix_set()

    if is_hex_str:
        hex_str = utf8str_with_decoded_emojicons  #E59388681020
    else:
        hex_str = byte_to_hex(utf8str_with_decoded_emojicons)  #E59388681020

    if len(utf8str_with_decoded_emojicons) <= 2:
        return False

    if len(hex_str) % 2 != 0:
        watchdog.warning(u"hex_str长度不正确,hex_str:{}".format(hex_str))

        return False

    max_index = len(hex_str)

    part_start_index = 0
    emojicon_utf8_part_index = -1
    for index in xrange(0, max_index, 2):
        if emojicon_utf8_part_index == -1:
            maybe_prefix = hex_str[index:index + 2]
        else:
            maybe_prefix = hex_str[emojicon_utf8_part_index:index + 2]

        if not ALL_EMOJICONS_UTF8_PRREFIX_SET.has_key(maybe_prefix):
            if index > 2 and emojicon_utf8_part_index >= 0:
                maybe_emojiconutf8 = hex_str[emojicon_utf8_part_index:index]
                if UTF82EMOJIICONS.has_key(maybe_emojiconutf8):
                    return True
        else:
            if emojicon_utf8_part_index == -1:
                emojicon_utf8_part_index = index

    if emojicon_utf8_part_index != -1:
        maybe_emojiconutf8 = hex_str[emojicon_utf8_part_index:]
        if UTF82EMOJIICONS.has_key(maybe_emojiconutf8):
            return True

    return False
コード例 #5
0
def encode_emojicons_for_html(unicode_or_utf8str_with_decoded_emojicons, is_hex_str=False):
    global ALL_EMOJICONS_UTF8_PRREFIX_SET

    if unicode_or_utf8str_with_decoded_emojicons is None:
        return ''

    if isinstance(unicode_or_utf8str_with_decoded_emojicons, unicode):
        utf8str_with_decoded_emojicons = unicode_or_utf8str_with_decoded_emojicons.encode('utf-8')
    else:
        utf8str_with_decoded_emojicons = unicode_or_utf8str_with_decoded_emojicons

    __build_all_emojicons_utf8_prefix_set()

    if is_hex_str:
        hex_str = utf8str_with_decoded_emojicons #E59388681020
    else:
        hex_str = byte_to_hex(utf8str_with_decoded_emojicons) #E59388681020

    if len(utf8str_with_decoded_emojicons) <= 2:
        if is_hex_str:
            return hex_to_byte(utf8str_with_decoded_emojicons)
        else:
            return utf8str_with_decoded_emojicons

    if len(hex_str) % 2 != 0:
        watchdog.warning(u"hex_str长度不正确,hex_str:{}".format(hex_str))

        if is_hex_str:
            return hex_to_byte(utf8str_with_decoded_emojicons)
        else:
            return utf8str_with_decoded_emojicons

    max_index = len(hex_str)
    parts = []

    part_start_index = 0
    emojicon_utf8_part_index = -1
    index = 0
    #for index in xrange(0, max_index, 2):
    #for循环改成while循环,来解决由不同表情有相同前缀码造成部分用户昵称里面的表情解析错误 by Eugene
    while index < max_index:
        if emojicon_utf8_part_index == -1:
            maybe_prefix = hex_str[index:index+2]
        else:
            maybe_prefix = hex_str[emojicon_utf8_part_index:index+2]
        if not ALL_EMOJICONS_UTF8_PRREFIX_SET.has_key(maybe_prefix):
            if index > 2 and emojicon_utf8_part_index >= 0:
                maybe_emojiconutf8 = hex_str[emojicon_utf8_part_index:index]
                if UTF82EMOJIICONS.has_key(maybe_emojiconutf8):
                    parts.append(hex_to_byte(hex_str[part_start_index:emojicon_utf8_part_index]))
                    parts.append(__complete_emojicon_html_content(maybe_emojiconutf8))

                    part_start_index = index
                    emojicon_utf8_part_index = -1
                    index -= 2
                else:
                    sub_str_len = len(maybe_emojiconutf8)
                    for sub_index in xrange(2, sub_str_len, 2):
                        if UTF82EMOJIICONS.has_key(maybe_emojiconutf8[:sub_str_len - sub_index]):
                            parts.append(hex_to_byte(hex_str[part_start_index:emojicon_utf8_part_index]))
                            parts.append(__complete_emojicon_html_content(maybe_emojiconutf8[:sub_str_len - sub_index]))

                            part_start_index = index - sub_index
                            index = part_start_index - 2
                            emojicon_utf8_part_index = -1
                            break
                    else:
                        parts.append(hex_to_byte(hex_str[part_start_index:index]))
                        part_start_index = index
                        emojicon_utf8_part_index = -1
                        index -= 2
        else:
            if emojicon_utf8_part_index == -1:
                emojicon_utf8_part_index = index

        index += 2

    if emojicon_utf8_part_index != -1:
        maybe_emojiconutf8 = hex_str[emojicon_utf8_part_index:]
        if UTF82EMOJIICONS.has_key(maybe_emojiconutf8):
            parts.append(hex_to_byte(hex_str[part_start_index:emojicon_utf8_part_index]))
            parts.append(__complete_emojicon_html_content(maybe_emojiconutf8))
        else:
            parts.append(hex_to_byte(hex_str[part_start_index:]))
    else:
        if part_start_index <= max_index:
            parts.append(hex_to_byte(hex_str[part_start_index:]))

    return ''.join(parts)
コード例 #6
0
ファイル: simple_products.py プロジェクト: nuaays/apiserver
        def inner_func():
            webapp_owner_id = webapp_owner.id
            watchdog.warning({
                'uuid': 'product_list_cahce',
                'hint': '商品列表页未命中缓存',
                'woid': webapp_owner_id
            })

            product_models = self.__get_products(webapp_owner_id, 0)

            categories = mall_models.ProductCategory.select().dj_where(
                owner=webapp_owner_id)

            product_ids = [
                product_model.id for product_model in product_models
            ]
            category_has_products = mall_models.CategoryHasProduct.select(
            ).dj_where(product__in=product_ids)
            product2categories = dict()
            for relation in category_has_products:
                product2categories.setdefault(relation.product_id,
                                              set()).add(relation.category_id)

            try:
                categories = [{
                    "id": category.id,
                    "name": category.name
                } for category in categories]

                # Fill detail
                product_datas = []
                # jz 2015-11-26
                # member = webapp_user.member

                products = Product.from_models({
                    'webapp_owner': webapp_owner,
                    'models': product_models,
                    'fill_options': {
                        "with_price": True,
                        "with_product_promotion": True,
                        "with_selected_category": True
                    }
                })
                # for product_model in product_models:
                # 	product = Product.from_model({
                # 		'webapp_owner': webapp_owner,
                # 		'model': product_model,
                # 		'fill_options': {
                # 			"with_price": True,
                # 			"with_product_promotion": True,
                # 			"with_selected_category": True
                # 		}
                # 	})
                #
                for product in products:
                    product_datas.append({
                        "id":
                        product.id,
                        "name":
                        product.name,
                        "is_member_product":
                        product.is_member_product,
                        "display_price":
                        product.price_info['display_price'],
                        "promotion_js":
                        json.dumps(product.promotion.to_dict())
                        if product.promotion else json.dumps(None),
                        "thumbnails_url":
                        product.thumbnails_url,
                        "supplier":
                        product.supplier,
                        "categories":
                        list(product2categories.get(product.id, []))
                    })

                # delete by bert at 2016715
                # for product_data in product_datas:
                # 	product_data['categories'] = list(product2categories.get(product_data['id'], []))

                return {
                    'value': {
                        "products": product_datas,
                        "categories": categories
                    }
                }
            except:
                from eaglet.core.exceptionutil import unicode_full_stack
                msg = {
                    'traceback': unicode_full_stack(),
                    'hint': u'获取商品列表mysql数据失败',
                    'msg_id': 'spdb123',
                    'woid': webapp_owner_id
                }
                watchdog.alert(msg)
                if settings.DEBUG:
                    raise
                else:
                    return None
コード例 #7
0
def watchdog_warning(message, log_type="WEB"):
    eaglet_watchdog.warning(message,
                            log_type=log_type,
                            server_name=settings.SERVICE_NAME)
コード例 #8
0
		def inner_func():
			#user profile
			user_profile = account_models.UserProfile.get(user=webapp_owner_id)
			webapp_id = user_profile.webapp_id

			#mpuser preview info
			try:
				mpuser = weixin_user_models.WeixinMpUser.get(owner=webapp_owner_id)
				mpuser_preview_info = weixin_user_models.MpuserPreviewInfo.get(mpuser=mpuser.id)
				try:
					weixin_mp_user_access_token = weixin_user_models.WeixinMpUserAccessToken.get(mpuser=mpuser.id)
				except:
					weixin_mp_user_access_token = weixin_user_models.WeixinMpUserAccessToken()
			except:
				error_msg = u"获得user('{}')对应的mpuser_preview_info构建cache失败, cause:\n{}"\
						.format(webapp_owner_id, unicode_full_stack())
				watchdog.warning(error_msg, user_id=webapp_owner_id)
				mpuser_preview_info = weixin_user_models.MpuserPreviewInfo()
				weixin_mp_user_access_token = weixin_user_models.WeixinMpUserAccessToken()
				mpuser = weixin_user_models.WeixinMpUser()

			#webapp
			try:
				webapp = webapp_models.WebApp.get(owner=webapp_owner_id)
			except:
				error_msg = u"获得user('{}')对应的webapp构建cache失败, cause:\n{}"\
						.format(webapp_owner_id, unicode_full_stack())
				watchdog.error(error_msg, user_id=webapp_owner_id )
				webapp = webapp_models.WebApp()

			#integral strategy
			try:
				integral_strategy_settings = member_models.IntegralStrategySttings.get(webapp_id=webapp_id)
			except:
				error_msg = u"获得user('{}')对应的IntegralStrategySttings构建cache失败, cause:\n{}"\
						.format(webapp_owner_id, unicode_full_stack())
				watchdog.error(error_msg, user_id=webapp_owner_id )
				integral_strategy_settings = member_models.IntegralStrategySttings()

			#member grade
			try:
				member_grades = [member_grade.to_dict() for member_grade in member_models.MemberGrade.select().dj_where(webapp_id=webapp_id)]
			except:
				error_msg = u"获得user('{}')对应的MemberGrade构建cache失败, cause:\n{}"\
						.format(webapp_owner_id, unicode_full_stack())
				watchdog.error(error_msg, user_id=webapp_owner_id )
				member_grades = []

			#pay interface
			try:
				all_pay_interfaces = [pay_interface.to_dict() for pay_interface in mall_models.PayInterface.select().dj_where(owner_id=webapp_owner_id)]
				pay_interfaces = filter(lambda x: x['is_active'], all_pay_interfaces)

			except:
				error_msg = u"获得user('{}')对应的PayInterface构建cache失败, cause:\n{}"\
						.format(webapp_owner_id, unicode_full_stack())
				watchdog.error(error_msg, user_id=webapp_owner_id )
				all_pay_interfaces = []
				pay_interfaces = []

			account_has_weizoom_card_permission = account_models.AccountHasWeizoomCardPermissions.select().dj_where(owner_id=webapp_owner_id).first()
			if account_has_weizoom_card_permission and account_has_weizoom_card_permission.is_can_use_weizoom_card:
				has_permission = True
			else:
				has_permission = False

			try:
				if account_models.OperationSettings.select().dj_where(owner_id=webapp_owner_id).count() == 0:
					operation_settings = account_models.OperationSettings.create(owner=webapp_owner_id)
				else:
					operation_settings = account_models.OperationSettings.select().dj_where(owner_id=webapp_owner_id).first()
			except:
				error_msg = u"获得user('{}')对应的OperationSettings构建cache失败, cause:\n{}"\
						.format(webapp_owner_id, unicode_full_stack())
				watchdog.error(error_msg, user_id=webapp_owner_id )
				operation_settings = account_models.OperationSettings()

			#全局导航
			try:
				global_navbar = account_models.TemplateGlobalNavbar.select().dj_where(owner_id=webapp_owner_id).first()
			except:
				global_navbar = account_models.TemplateGlobalNavbar()

			try:
				auth_appid = weixin_user_models.ComponentAuthedAppid.select().dj_where(user_id=webapp_owner_id)[0]
				auth_appid_info = weixin_user_models.ComponentAuthedAppidInfo.select().dj_where(auth_appid=auth_appid)[0]
			except:
				auth_appid_info = weixin_user_models.ComponentAuthedAppidInfo()
			
			#member default tags
			try:
				try:
					default_member_tag = member_models.MemberTag.get(webapp_id=webapp_id, name="未分组")
				except:
					default_member_tag = member_models.MemberTag.create(webapp_id=webapp_id, name="未分组")
			except:
				default_member_tag = member_models.MemberTag()
			
			return {
				'value': {
					'weixin_mp_user_access_token': weixin_mp_user_access_token.to_dict(),
					"mpuser_preview_info": mpuser_preview_info.to_dict(),
					'webapp': webapp.to_dict(),
					'user_profile': user_profile.to_dict(),
					'mpuser': mpuser.to_dict(),
					'integral_strategy_settings': integral_strategy_settings.to_dict(),
					'member_grades': member_grades,
					'pay_interfaces': pay_interfaces,
					'all_pay_interfaces': all_pay_interfaces,
					'has_permission': has_permission,
					'operation_settings': operation_settings.to_dict(),
					# 'global_navbar': {
					# 	'id': global_navbar.id,
					# 	'owner_id': global_navbar.owner_id,
					# 	'is_enable': global_navbar.is_enable
					# },
					'global_navbar': global_navbar.to_dict() if global_navbar else {},
					'auth_appid_info': auth_appid_info.to_dict(),
					'default_member_tag': default_member_tag.to_dict()
				}
			}