From e180b413664759c9b4acf4f005b4eb449a2c602c Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 11 Jun 2018 17:19:59 +0530 Subject: [PATCH] [fix] [test] for notification --- .../email/doctype/notification/notification.py | 2 +- .../doctype/stripe_settings/stripe_settings.py | 3 ++- frappe/patches/v5_0/fix_email_alert.py | 18 +++++++++--------- frappe/patches/v5_0/rename_table_fieldnames.py | 2 +- frappe/patches/v5_0/v4_to_v5.py | 2 +- frappe/utils/install.py | 4 ++++ 6 files changed, 18 insertions(+), 13 deletions(-) diff --git a/frappe/email/doctype/notification/notification.py b/frappe/email/doctype/notification/notification.py index 899c035f41..f48c20628a 100644 --- a/frappe/email/doctype/notification/notification.py +++ b/frappe/email/doctype/notification/notification.py @@ -42,9 +42,9 @@ class Notification(Document): self.validate_forbidden_types() self.validate_condition() self.validate_standard() + frappe.cache().hdel('notifications', self.document_type) def on_update(self): - frappe.cache().hdel('email_alerts', self.document_type) path = export_module_json(self, self.is_standard, self.module) if path: # js diff --git a/frappe/integrations/doctype/stripe_settings/stripe_settings.py b/frappe/integrations/doctype/stripe_settings/stripe_settings.py index 1fbcb60ba7..90bb84533e 100644 --- a/frappe/integrations/doctype/stripe_settings/stripe_settings.py +++ b/frappe/integrations/doctype/stripe_settings/stripe_settings.py @@ -9,7 +9,6 @@ from frappe import _ from six.moves.urllib.parse import urlencode from frappe.utils import get_url, call_hook_method, cint, flt from frappe.integrations.utils import make_get_request, make_post_request, create_request_log, create_payment_gateway -import stripe class StripeSettings(Document): supported_currencies = [ @@ -58,6 +57,7 @@ class StripeSettings(Document): return get_url("./integrations/stripe_checkout?{0}".format(urlencode(kwargs))) def create_request(self, data): + import stripe self.data = frappe._dict(data) stripe.api_key = self.get_password(fieldname="secret_key", raise_exception=False) stripe.default_http_client = stripe.http_client.RequestsClient() @@ -74,6 +74,7 @@ class StripeSettings(Document): } def create_charge_on_stripe(self): + import stripe try: charge = stripe.Charge.create(amount=cint(flt(self.data.amount)*100), currency=self.data.currency, source=self.data.stripe_token_id, description=self.data.description) diff --git a/frappe/patches/v5_0/fix_email_alert.py b/frappe/patches/v5_0/fix_email_alert.py index 5c7b198dad..0676f50a9c 100644 --- a/frappe/patches/v5_0/fix_email_alert.py +++ b/frappe/patches/v5_0/fix_email_alert.py @@ -3,14 +3,14 @@ from __future__ import unicode_literals import frappe def execute(): - frappe.reload_doctype("Email Alert") - for e in frappe.get_all("Email Alert"): - email_alert = frappe.get_doc("Email Alert", e.name) - if email_alert.event == "Date Change": - if email_alert.days_in_advance < 0: - email_alert.event = "Days After" - email_alert.days_in_advance = -email_alert.days_in_advance + frappe.reload_doctype("Notification") + for e in frappe.get_all("Notification"): + notification = frappe.get_doc("Notification", e.name) + if notification.event == "Date Change": + if notification.days_in_advance < 0: + notification.event = "Days After" + notification.days_in_advance = -email_alert.days_in_advance else: - email_alert.event = "Days Before" + notification.event = "Days Before" - email_alert.save() + notification.save() diff --git a/frappe/patches/v5_0/rename_table_fieldnames.py b/frappe/patches/v5_0/rename_table_fieldnames.py index af571c37d5..79703bbba2 100644 --- a/frappe/patches/v5_0/rename_table_fieldnames.py +++ b/frappe/patches/v5_0/rename_table_fieldnames.py @@ -20,7 +20,7 @@ rename_map = { def execute(): frappe.reload_doc("custom", "doctype", "customize_form") - frappe.reload_doc("email", "doctype", "email_alert") + frappe.reload_doc("email", "doctype", "notification") frappe.reload_doc("desk", "doctype", "event") frappe.reload_doc("workflow", "doctype", "workflow") diff --git a/frappe/patches/v5_0/v4_to_v5.py b/frappe/patches/v5_0/v4_to_v5.py index 44ab0f8d2e..cd34f04c97 100644 --- a/frappe/patches/v5_0/v4_to_v5.py +++ b/frappe/patches/v5_0/v4_to_v5.py @@ -9,7 +9,7 @@ def execute(): ("desk", ("feed", "event", "todo", "note")), ("custom", ("custom_field", "custom_script", "customize_form", "customize_form_field", "property_setter")), - ("email", ("email_queue", "email_alert", "email_alert_recipient", "standard_reply")), + ("email", ("email_queue", "notification", "notification_recipient", "standard_reply")), ("geo", ("country", "currency")), ("print", ("letter_head", "print_format", "print_settings")) ) diff --git a/frappe/utils/install.py b/frappe/utils/install.py index 8dd06194eb..b84e292397 100644 --- a/frappe/utils/install.py +++ b/frappe/utils/install.py @@ -39,6 +39,10 @@ def after_install(): # setup wizard now in frappe frappe.db.set_default('desktop:home_page', 'setup-wizard') + # clear test log + with open(frappe.get_site_path('.test_log'), 'w') as f: + f.write('') + frappe.db.commit() def install_basic_docs():