From e25805dbb9ea0a07baec03338c86cc5695af7810 Mon Sep 17 00:00:00 2001 From: Karthikeyan Y Date: Sun, 25 Sep 2022 11:14:25 +0530 Subject: [PATCH] Optimizations and Fixes --- README.md | 163 +--- barista/__init__.py | 20 + .../error_statistics => api}/__init__.py | 0 barista/barista/api/barista_trigger.py | 533 +++++++++++++ .../barista/doctype/assertion/assertion.json | 465 +---------- .../barista/doctype/barista_app/__init__.py | 0 .../doctype/barista_app/barista_app.json | 92 +++ .../doctype/barista_app/barista_app.py | 10 + .../doctype/barista_job_setting/__init__.py | 0 .../barista_job_setting.js | 14 + .../barista_job_setting.json | 750 ++++++++++++++++++ .../barista_job_setting.py | 10 + .../test_barista_job_setting.js | 23 + .../test_barista_job_setting.py | 10 + .../barista/doctype/barista_suite/__init__.py | 0 .../doctype/barista_suite/barista_suite.json | 93 +++ .../doctype/barista_suite/barista_suite.py | 10 + .../barista/doctype/cc_email_id/__init__.py | 0 .../doctype/cc_email_id/cc_email_id.json | 92 +++ .../doctype/cc_email_id/cc_email_id.py | 10 + .../barista/doctype/from_email_id/__init__.py | 0 .../doctype/from_email_id/from_email_id.json | 129 +++ .../doctype/from_email_id/from_email_id.py | 10 + .../function_parameter.json | 180 ++++- barista/barista/doctype/run_name/__init__.py | 0 barista/barista/doctype/run_name/run_name.js | 8 + .../barista/doctype/run_name/run_name.json | 45 ++ barista/barista/doctype/run_name/run_name.py | 8 + .../barista/doctype/run_name/test_run_name.py | 8 + .../test_case/templates/test_case_info.html | 145 ++++ .../barista/doctype/test_case/test_case.js | 22 +- .../barista/doctype/test_case/test_case.json | 341 +++++++- .../barista/doctype/test_case/test_case.py | 59 +- .../doctype/test_case/test_case_execution.py | 199 +++-- .../barista/doctype/test_data/test_data.js | 120 ++- .../barista/doctype/test_data/test_data.json | 260 ++++-- .../barista/doctype/test_data/test_data.py | 35 +- .../doctype/test_data/test_data_generator.py | 323 +++++--- .../doctype/test_data_condition/__init__.py | 0 .../test_data_condition.json | 278 +++++++ .../test_data_condition.py | 10 + .../doctype/test_run_log/test_run_log.json | 245 +----- .../barista/doctype/test_suite/run_test.py | 179 +++-- .../barista/doctype/test_suite/test_suite.js | 67 +- .../doctype/test_suite/test_suite.json | 203 ++--- .../barista/doctype/test_suite/test_suite.py | 12 +- .../doctype/testdatafield/testdatafield.json | 101 ++- .../barista/doctype/to_email_id/__init__.py | 0 .../doctype/to_email_id/to_email_id.json | 92 +++ .../doctype/to_email_id/to_email_id.py | 10 + barista/barista/doctype/workgroup/__init__.py | 0 .../doctype/workgroup/test_workgroup.py | 8 + .../barista/doctype/workgroup/workgroup.js | 8 + .../barista/doctype/workgroup/workgroup.json | 49 ++ .../barista/doctype/workgroup/workgroup.py | 8 + .../barista_error_statistics/__init__.py | 0 .../barista_error_statistics.json} | 6 +- .../test_execution_statistics.json | 13 +- barista/commands.py | 18 +- barista/config/desktop.py | 4 +- barista/hooks.py | 34 +- requirements.txt | 4 +- 62 files changed, 4163 insertions(+), 1373 deletions(-) rename barista/barista/{report/error_statistics => api}/__init__.py (100%) create mode 100644 barista/barista/api/barista_trigger.py create mode 100644 barista/barista/doctype/barista_app/__init__.py create mode 100644 barista/barista/doctype/barista_app/barista_app.json create mode 100644 barista/barista/doctype/barista_app/barista_app.py create mode 100644 barista/barista/doctype/barista_job_setting/__init__.py create mode 100644 barista/barista/doctype/barista_job_setting/barista_job_setting.js create mode 100644 barista/barista/doctype/barista_job_setting/barista_job_setting.json create mode 100644 barista/barista/doctype/barista_job_setting/barista_job_setting.py create mode 100644 barista/barista/doctype/barista_job_setting/test_barista_job_setting.js create mode 100644 barista/barista/doctype/barista_job_setting/test_barista_job_setting.py create mode 100644 barista/barista/doctype/barista_suite/__init__.py create mode 100644 barista/barista/doctype/barista_suite/barista_suite.json create mode 100644 barista/barista/doctype/barista_suite/barista_suite.py create mode 100644 barista/barista/doctype/cc_email_id/__init__.py create mode 100644 barista/barista/doctype/cc_email_id/cc_email_id.json create mode 100644 barista/barista/doctype/cc_email_id/cc_email_id.py create mode 100644 barista/barista/doctype/from_email_id/__init__.py create mode 100644 barista/barista/doctype/from_email_id/from_email_id.json create mode 100644 barista/barista/doctype/from_email_id/from_email_id.py create mode 100644 barista/barista/doctype/run_name/__init__.py create mode 100644 barista/barista/doctype/run_name/run_name.js create mode 100644 barista/barista/doctype/run_name/run_name.json create mode 100644 barista/barista/doctype/run_name/run_name.py create mode 100644 barista/barista/doctype/run_name/test_run_name.py create mode 100644 barista/barista/doctype/test_case/templates/test_case_info.html create mode 100644 barista/barista/doctype/test_data_condition/__init__.py create mode 100644 barista/barista/doctype/test_data_condition/test_data_condition.json create mode 100644 barista/barista/doctype/test_data_condition/test_data_condition.py create mode 100644 barista/barista/doctype/to_email_id/__init__.py create mode 100644 barista/barista/doctype/to_email_id/to_email_id.json create mode 100644 barista/barista/doctype/to_email_id/to_email_id.py create mode 100644 barista/barista/doctype/workgroup/__init__.py create mode 100644 barista/barista/doctype/workgroup/test_workgroup.py create mode 100644 barista/barista/doctype/workgroup/workgroup.js create mode 100644 barista/barista/doctype/workgroup/workgroup.json create mode 100644 barista/barista/doctype/workgroup/workgroup.py create mode 100644 barista/barista/report/barista_error_statistics/__init__.py rename barista/barista/report/{error_statistics/error_statistics.json => barista_error_statistics/barista_error_statistics.json} (83%) diff --git a/README.md b/README.md index bd4d491..47c570e 100644 --- a/README.md +++ b/README.md @@ -1,131 +1,32 @@ -While developing an application using a framework like Frappe which adds most of the required paraphernalia automatically the developer is mainly required to code the business logic. And hence making functional testing one of the most important aspects. - - -We have developed a frappe application, named BARISTA, which automates testing of server-side code for all our frappe apps. - - - -

Overview

- - - -A simple manual test would require a test suite, usually a spreadsheet, on which the tester adds test cases. Each test case defines: - -* Test case Name and description - -* Test case Steps – Each test case would layout detailed steps to create the test data with field values and required action to test. - -* Expected result - Based on the field values, expected result is specified for the tester to validate. - -* Actual result - Following the steps the tester runs the test case and publishes the actual test result. - -* Finally the test case is passed or failed based on actual results. -![Manual testing sample](/images/sample-manual-testcase.png) - - -Similarly in Barista there are four doctypes: - -* **Test Suite** – declare a test suite here and select the set of test cases to run under that suite. One or more test suites can be executed based on the test scope. - - * **Test Data** – declare the application doctype here and required field values. Barista will create the record using values mentioned here while executing the test case. It also lets you select option to generate random value for the field. - -* **Test Case** – Select the test data, specify the action to be triggerred like save, workflow change etc. and define assertions here like validate value of a field which is expected to change or expected error message etc. - -* **Test Result** – Barista executes the test cases in a suite and publishes the result of each test case. Whether a test case passed or failed and what is the actual result for defect analysis. - -![Dashboard](/images/dashboard.png) - - -

How it works

- - - -Barista is installed on the same bench where the application to be tested is installed. This gives it access to the metadata of the application and its methods. While execution, it first creates the test record using values provided on test data and saves document name for further execution and assertion validation. It then triggers the action on the test data using respective frappe methods like save(). Finally, fetches all assertions (child table in Test case) of the test case and validates with the actual record. - - - -**Create test data** - - -Simply select the doctype on which the test case has to execute. Declare required field values which will be used to create the record/document while executing the test case. - - -![test-data](/images/td.gif) - - -**Create test case** - - - -Test case creation has three steps: - - - -* Select the action like create a document or update or change workflow state etc. - -* Select the test data on which the above action will be triggered. - -* Declare assertions to validate. When test cases are executed each assertion is validated and if any assertion fails, Barista marks test case status as failed with the details of the actual result found. Assertions can validate field value of a doctype, validate a record, validate workflow state, validate error and error message or validate response of a method. - -**Create test case** - - - -Test case creation has three steps: - - - -* Select the action like create a document or update or change workflow state etc. - -* Select the test data on which the above action will be triggered. - -* Declare assertions to validate. When test cases are executed each assertion is validated and if any assertion fails, Barista marks test case status as failed with the details of the actual result found. Assertions can validate field value of a doctype, validate a record, validate workflow state, validate error and error message or validate response of a method. - -![test-result](/images/tc.gif) - -**Execute and view the results** - - -Barista executes all test cases and saves the test results for further analysis. - -**Execute and view the results** - - -Barista executes all test cases and saves the test results for further analysis. - -![test-result](/images/test-result.gif) - -

Test Effectiveness

- - - -**Overall Code Coverage** - - - -Barista uses Coverage.py to track the coverage while test execution and publishes the detailed report which can be used to ensure test effectiveness. Higher the coverage higher is the effectiveness of the test. - - -**Incremental code coverage** - - - -Code coverage of the new change which is going to be released is important information to verify. To achieve this we are integrating with repositories like Gitlab from where we can get details of the change in a merge request and cross verify it with the test code coverage. This can ensure the change which is getting released has been tested and is part of the test cases. - - - - -**Overall Code Coverage** - - - -Barista uses Coverage.py to track the coverage while test execution and publishes the detailed report which can be used to ensure test effectiveness. Higher the coverage higher is the effectiveness of the test. - - -**Incremental code coverage** - - - -Code coverage of the new change which is going to be released is important information to verify. To achieve this we are integrating with repositories like Gitlab from where we can get details of the change in a merge request and cross verify it with the test code coverage. This can ensure the change which is getting released has been tested and is part of the test cases. - - +

BARISTA

+
Frappe App Testing Framework
+ +--- +## Table of contents : +- [Installation](#installation) +- [Getting Started](#getting-started) +- [Material](#material) +- [License](#license) + +#### Installation +- Clone : `bench get-app https://engg.elasticrun.in/sancharun/barista.git --branch=master` +- Install : `bench install-app barista` +- Confirm Installation : `./env/bin/pip install -e apps/barista` +- Wrapping up Installation : + - `bench build` + - `bench setup requirements` + - `bench migrate` + +### Getting Started +- Basic Structure : Add Test Case(s) to Test Suite. Test Data or Pre-Test Data are optional. Test Results + Test Run Log is connected to Test Suite. +- Command to execute : `bench run-barista -s ` *Not setting the '-s' arg will run all the available Test Suites.* +- Debugging : Test Run Log (Barista Module), Test Result (Barista Module), Error Log +- For detailed documentation [Check the Wiki for this project.](https://engg.elasticrun.in/sudhanshu.kulkarni/barista/-/wikis/home) +### Material +- [Official Overview](https://discuss.erpnext.com/t/automating-functional-testing-of-frappe-apps-by-frappe-app/60274) +- [Frappe Developer API docs](https://frappeframework.com/docs/user/en/api) +- [Frappe Developer Cheatsheet](https://github.com/frappe/frappe/wiki/Developer-Cheatsheet) + +#### License + +MIT diff --git a/barista/__init__.py b/barista/__init__.py index 4ef7022..22dde3f 100644 --- a/barista/__init__.py +++ b/barista/__init__.py @@ -3,6 +3,7 @@ import time import sys import frappe +from frappe.model.rename_doc import rename_doc from barista.barista.doctype.test_suite.run_test import RunTest, resolve_run_name @@ -219,3 +220,22 @@ def get_commands(): commands = get_commands() + + +def update_series(): + # bench execute barista.update_series + bs = '' + if frappe.conf.get('barista_series'): + bs = f"{frappe.conf.get('barista_series')}-" + + test_data_lst = frappe.get_all('Test Data') + for test_data in test_data_lst: + rename_doc( + 'Test Data', test_data['name'], f"{bs}{test_data['name']}", force=True) + + test_case_lst = frappe.get_all('Test Case') + for test_case in test_case_lst: + rename_doc( + 'Test Case', test_case['name'], f"{bs}{test_case['name']}", force=True) + + frappe.db.commit() diff --git a/barista/barista/report/error_statistics/__init__.py b/barista/barista/api/__init__.py similarity index 100% rename from barista/barista/report/error_statistics/__init__.py rename to barista/barista/api/__init__.py diff --git a/barista/barista/api/barista_trigger.py b/barista/barista/api/barista_trigger.py new file mode 100644 index 0000000..2894d20 --- /dev/null +++ b/barista/barista/api/barista_trigger.py @@ -0,0 +1,533 @@ +import frappe +import os +import math +import coverage +import shutil +import warnings +from barista.barista.doctype.test_suite.run_test import resolve_run_name +import itertools +from barista.barista.doctype.test_suite.run_test import RunTest +from frappe.desk.query_report import run +from frappe.utils.password import get_decrypted_password +import datetime + +import smtplib + +from email.mime.multipart import MIMEMultipart +from email.mime.text import MIMEText + +def truncate(number, decimals=0): + """ + Returns a value truncated to a specific number of decimal places. + """ + if not isinstance(decimals, int): + raise TypeError("decimal places must be an integer.") + elif decimals < 0: + raise ValueError("decimal places has to be 0 or more.") + elif decimals == 0: + return math.trunc(number) + + factor = 10.0 ** decimals + return math.trunc(number * factor) / factor + +@frappe.whitelist() +def barista_job(): + + disable_execution = frappe.utils.cint(frappe.db.get_value('Barista Job Setting','Barista Job Setting','disable_execution')) + + if disable_execution: + return + + # send do not refresh email + send_do_not_refresh_mail() + + print("Barista Job Started") + if not frappe.local.conf.developer_mode: + return + + run_name = 'Pass-1' + barista_job_setting = frappe.get_single("Barista Job Setting") + app_name = [app.app_name for app in barista_job_setting.barista_app] or [] + + suite = [suite.barista_suite for suite in barista_job_setting.barista_suite] or [] + + run_name = resolve_run_name(run_name) + run_name_path = run_name.replace(' ', '__').replace('-', '_') + barista_app_path = f'{frappe.get_site_path()}/public/files/test-coverage/{run_name_path}/' + # data_file_path = os.path.abspath(str(f"{barista_app_path}{app_name[0]}.coverage")) + source_app_path = frappe.get_app_path(app_name[0]) + + warnings.filterwarnings("ignore") + + shutil.rmtree('{barista_app_path}', ignore_errors=True) + objCoverage = coverage.Coverage(source=[source_app_path], + omit=['*test_*'], + config_file=False, + debug=[], + data_file=None) + + objCoverage.erase() + objCoverage.start() + + RunTest().run_complete_suite(app_name[0], list(suite), run_name) + + objCoverage.stop() + objCoverage.save() + objCoverage.html_report(directory=barista_app_path, + skip_empty=True, + omit=['*test_*']) + + print("Barista Job Ended") + + send_report(run_name) + +def send_report(run_name): + + disable_report = frappe.utils.cint(frappe.db.get_value('Barista Job Setting','Barista Job Setting','disable_report')) + + if disable_report: + return + + today = datetime.date.today().strftime("%d-%b-%Y") + barista_job_setting = frappe.get_single("Barista Job Setting") + app_name = [app.app_name for app in barista_job_setting.barista_app] or [] + + report_name = 'Test Execution Statistics' + filters = {"app_name":app_name[0],"run_name":run_name} + + data = run(report_name, filters) + data_list = data.get('result') + + # Get URL and name of environment + url = barista_job_setting.url or '' + env = barista_job_setting.platform or '' + + # Get sorting attribute to sort the test suites + sort_att = barista_job_setting.sort_using + + if sort_att == 'Module': + col = 1 + module_tup = frappe.db.sql("""SELECT DISTINCT ts.module AS 'Module' FROM `tabTest Suite` ts INNER JOIN `tabTest Result` tr ON ts.name=tr.test_suite AND tr.test_run_name='{run_name}' WHERE ts.module IS NOT NULL AND ts.module != '';""".format(run_name = run_name)) + elif sort_att == 'Workgroup': + col = 6 + module_tup = frappe.db.sql("""SELECT DISTINCT ts.workgroup AS 'Workgroup' FROM `tabTest Suite` ts INNER JOIN `tabTest Result` tr ON ts.name=tr.test_suite AND tr.test_run_name='{run_name}' WHERE ts.workgroup IS NOT NULL AND ts.workgroup != '';""".format(run_name = run_name)) + elif sort_att == 'SPOC': + col = 7 + module_tup = frappe.db.sql("""SELECT DISTINCT ts.spoc AS 'SPOC' FROM `tabTest Suite` ts INNER JOIN `tabTest Result` tr ON ts.name=tr.test_suite AND tr.test_run_name='{run_name}' WHERE ts.spoc IS NOT NULL AND ts.spoc != '';""".format(run_name = run_name)) + + module_list = list(itertools.chain(*module_tup)) + module_cnt = len(module_list) + + # Collect the report data + d1 = [] + d2 = [] + d3 = [] + d4 = [] + d5 = [] + + suites = {} + tc = {} + pc = {} + fc = {} + per = {} + + for x in range(module_cnt): + suites["module{0}".format(x)] = 0 + tc["module{0}".format(x)] = 0 + pc["module{0}".format(x)] = 0 + fc["module{0}".format(x)] = 0 + per["module{0}".format(x)] = 0 + + for i in range(len(data_list)): + d1.append(data_list[i][0]) + if d1[i] == None or d1[i] == '': + d1[i] = 0 + + d2.append(data_list[i][2]) + if d2[i] == None or d2[i] == '': + d2[i] = 0 + else: + d2[i] = round(d2[i],2) + + for x in range(module_cnt): + if data_list[i][col] == module_list[x].upper(): + tc["module{0}".format(x)] += d2[i] + suites["module{0}".format(x)] += 1 + break + + d3.append(data_list[i][3]) + if d3[i] == None or d3[i] == '': + d3[i] = 0 + else: + d3[i] = round(d3[i],2) + + for x in range(module_cnt): + if data_list[i][col] == module_list[x].upper(): + pc["module{0}".format(x)] += d3[i] + break + + d4.append(data_list[i][4]) + if d4[i] == None or d4[i] == '': + d4[i] = 0 + else: + d4[i] = round(d4[i],2) + + for x in range(module_cnt): + if data_list[i][col] == module_list[x].upper(): + fc["module{0}".format(x)] += d4[i] + break + + d5.append(data_list[i][5]) + if d5[i] == None or d5[i] == '': + d5[i] = 0 + else: + d5[i] = round(d5[i],2) + + # Collect data for the summary table + data_list_len = len(data_list) + + if data_list[data_list_len - 1][2] == '': + total_tc = 0 + else: + total_tc = 0 + for x in range(module_cnt): + total_tc += tc["module{0}".format(x)] + + + if data_list[data_list_len - 1][3] == '': + passed_tc = 0 + else: + passed_tc = 0 + for x in range(module_cnt): + passed_tc += pc["module{0}".format(x)] + + if data_list[data_list_len - 1][4] == '': + failed_tc = 0 + else: + failed_tc = 0 + for x in range(module_cnt): + failed_tc += fc["module{0}".format(x)] + + for x in range(len(tc)): + if tc["module{0}".format(x)]: + per["module{0}".format(x)] = round((pc["module{0}".format(x)]/tc["module{0}".format(x)])*100,2) + + percentage_tot = 0 + for x in range(module_cnt): + percentage_tot += per["module{0}".format(x)] + + percentage_fin_tot = 0 + for x in range(data_list_len): + if data_list[x][col] in module_list: + percentage_fin_tot += d5[x] + + suites_tot = 0 + for x in range(module_cnt): + suites_tot += suites["module{0}".format(x)] + + percentage = round(percentage_tot / module_cnt, 2) + + percentage_fin = round(percentage_fin_tot / suites_tot, 2) + + pass_name = barista_job_setting.from_email_id[0].name + + # me == my email address + # you == recipient's email address + me = barista_job_setting.from_email_id[0].from_email_id + me1 = ((me.split('@')[0]).replace('.',' ')).title() + password = get_decrypted_password('From Email ID', pass_name, fieldname='password') + you = [to.to_email_id for to in barista_job_setting.to_email_id] or [] + cc = [cc.cc_email_id for cc in barista_job_setting.cc_email_id] or [] + + # Create message container - the correct MIME type is multipart/alternative. + msg = MIMEMultipart('alternative') + msg['Subject'] = "{env} Barista Test Suites Execution Report - {today} , {run_name}".format(env = env, today = today, run_name = run_name) + msg['From'] = me1 + msg['To'] = ", ".join(you) + msg['Cc'] = ", ".join(cc) + + # Create the body of the message (a plain-text and an HTML version). + text = "" + html = """ + + + + + + + + Hi all,

+ Below is the {sort_att} wise summary of today's execution.

+ + + + + + + + + + + + + + + + + + """.format(sort_att = sort_att,module = module_list[0].upper(),tc = tc["module0"],pc = pc["module0"],fc = fc["module0"],per = per["module0"]) + + for x in range(1,module_cnt): + html += """ + + + + + + + """.format(module = module_list[x].upper(),tc = tc["module{0}".format(x)],pc = pc["module{0}".format(x)],fc = fc["module{0}".format(x)],per = per["module{0}".format(x)]) + + html += """ + + + + + + + +
{sort_att}Total Test CasesPassed Test CasesFailed Test CasesPercentage Passed
{module}{tc}{pc}{fc}{per}%
{module}{tc}{pc}{fc}{per}%
Total{total_tc}{passed_tc}{failed_tc}{percentage}%


+ Below is the detailed execution result of Barista Automation as of today

+ Click here for the Test Execution Statistics.
Set App as {app_name} and Test Run Name as {run_name} in filters of the report for the details.

+ + + + + + + + + + + + + """.format(total_tc = total_tc, passed_tc = passed_tc, failed_tc = failed_tc, percentage = percentage, url = url, app_name = app_name[0], run_name = run_name, sort_att = sort_att) + + for x in range(module_cnt): + if tc["module{0}".format(x)]: + html += """""".format(ts = suites["module{0}".format(x)],module = module_list[x]) + + for i in range(len(data_list)): + if data_list[i][col] == module_list[x].upper(): + if 100 > d5[i] >= 50: + tdc = '#FFB997' + elif d5[i] < 50: + tdc = '#F04E4C' + else: + tdc = '#FFFFFF' + if i != len(data_list) - 1: + html += """ + + + + + + + + """%(tdc, url ,d1[i], d1[i], tdc, truncate(d2[i]), tdc, truncate(d3[i]), tdc, truncate(d4[i]), tdc, d5[i]) + + for i in range(len(data_list)): + if i == len(data_list) - 1: + tdc = '#D3D3D3' + html += """ + + + + + + + + + """%(tdc, tdc, d1[i],tdc, total_tc,tdc, passed_tc,tdc, failed_tc,tdc, percentage_fin) + + html += """ +
{sort_att}Test SuiteTotal Test CasesPassed Test CasesFailed Test CasesPercentage Passed
{module}%s%s%s%s%s%%
-%s%s%s%s%s%%
+ + + """ + + # html = report.get_html() + + + # Record the MIME types of both parts - text/plain and text/html. + part1 = MIMEText(text, 'plain') + part2 = MIMEText(html, 'html') + + # Attach parts into message container. + # According to RFC 2046, the last part of a multipart message, in this case + # the HTML message, is best and preferred. + msg.attach(part1) + msg.attach(part2) + + # Send the message via local SMTP server. + mail = smtplib.SMTP('smtp.gmail.com', 587) + + mail.ehlo() + + mail.starttls() + + mail.login(me, password) + mail.send_message(msg) + mail.quit() + + print('------------------Report sent-------------------') + +def send_do_not_refresh_mail(): + + barista_job_setting = frappe.get_single("Barista Job Setting") + pass_name = barista_job_setting.from_email_id[0].name + + disable_email = frappe.utils.cint(frappe.db.get_value('Barista Job Setting','Barista Job Setting','disable_request')) + + if disable_email: + return + + # me == my email address + # you == recipient's email address + # me = [from_email.from_email_id for from_email in barista_job_setting.from_email_id] or [] + me = barista_job_setting.from_email_id[0].from_email_id + me1 = ((me.split('@')[0]).replace('.',' ')).title() + password = get_decrypted_password('From Email ID', pass_name, fieldname='password') + you = [to.to_email_id for to in barista_job_setting.to_email_id] or [] + cc = [cc.cc_email_id for cc in barista_job_setting.cc_email_id] or [] + + # Create message container - the correct MIME type is multipart/alternative. + msg = MIMEMultipart('alternative') + msg['Subject'] = "Please do not Refresh Doha Environment for an Hour " + msg['From'] = me1 + msg['To'] = ", ".join(you) + msg['Cc'] = ", ".join(cc) + + # Send the message via local SMTP server. + mail = smtplib.SMTP('smtp.gmail.com', 587) + mail.ehlo() + + mail.starttls() + + mail.login(me, password) + mail.send_message(msg) + mail.quit() + + print('------------------Request email sent-------------------') + +# Create Test-Data from document +@frappe.whitelist() +def create_test_data_from_doc(doctype, docname): + # DocFields to ignore: + no_value_fieldtypes = ( + "Section Break", + "Column Break", + "Fold", + "Button", + "Heading", + "Read Only" + ) + + # DocFields to iterate and create separate Test Data for each entry: + childtable_fieldtypes = ( + "Table", + "Table Multiselect" + ) + + # Create basic Test Data doc: + doc = frappe.get_doc(doctype, docname) + test_data_doc = frappe.get_doc({ + "doctype": "Test Data", + "doctype_name": doctype, + "is_standard": "Yes", + "app_name": frappe.db.get_value("Module Def", doc.meta.module, "app_name"), + "doctype_type": "Master", + "create_using": "Data" + }) + + # Check each field of document and add in Test Data doc: + for row in doc.meta.fields: + # Handle Child Tables: + if row.fieldtype in childtable_fieldtypes: + for table_entry in doc.get(row.fieldname): + test_data = create_test_data_from_doc(row.options, table_entry.name) + test_data_doc.append("docfield_value", { + "doctype_name": doctype, + "docfield_fieldname": row.fieldname, + "docfield_code_value": "Fixed Value", + "linkfield_name": test_data.get('name', ''), + "linkfield_key": "name" + }) + elif row.fieldtype not in no_value_fieldtypes: + # Handle Links: + if row.fieldtype == "Link" and doc.get(row.fieldname) and row.options!= "DocType": + link_test_data = create_test_data_from_doc(row.options, doc.get(row.fieldname)) + test_data_doc.append("docfield_value", { + "doctype_name": doctype, + "docfield_fieldname": row.fieldname, + "docfield_code_value": "Fixed Value", + "linkfield_name": link_test_data.get('name', ''), + "linkfield_key": "name" + }) + # Handle Dynamic Links: + elif row.fieldtype == "Dynamic Link" and doc.get(row.fieldname) and doc.get(row.options) != "DocType": + dl_test_data = create_test_data_from_doc(doc.get(row.options), doc.get(row.fieldname)) + test_data_doc.append("docfield_value", { + "doctype_name": doctype, + "docfield_fieldname": row.fieldname, + "docfield_code_value": "Fixed Value", + "linkfield_name": dl_test_data.get('name', ''), + "linkfield_key": "name" + }) + # Normal DocField: + test_data_doc.append("docfield_value", { + "doctype_name": doctype, + "docfield_fieldname": row.fieldname, + "docfield_code_value": "Fixed Value", + "docfield_value": doc.get(row.fieldname), + }) + test_data_doc.save(True) + + return test_data_doc diff --git a/barista/barista/doctype/assertion/assertion.json b/barista/barista/doctype/assertion/assertion.json index 0ea2796..2708da2 100644 --- a/barista/barista/doctype/assertion/assertion.json +++ b/barista/barista/doctype/assertion/assertion.json @@ -1,529 +1,134 @@ { - "allow_copy": 0, - "allow_events_in_timeline": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, - "autoname": "", - "beta": 0, + "actions": [], "creation": "2019-12-17 17:39:44.639480", - "custom": 0, - "docstatus": 0, "doctype": "DocType", - "document_type": "", - "editable_grid": 0, "engine": "InnoDB", + "field_order": [ + "assertion_type", + "module", + "doctype_name", + "column_break_11", + "reference_field", + "docfield_name", + "error_message", + "value_type", + "response_regex", + "docfield_value", + "workflow_state", + "workflow_action", + "code", + "record_count" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, "fieldname": "assertion_type", "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Assertion Type", - "length": 0, - "no_copy": 0, - "options": "Field Value\nRecord Validation\nWorkflow\nResponse\nError", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Field Value\nRecord Validation\nWorkflow\nResponse\nError" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "default": "", "depends_on": "eval:(doc.assertion_type != \"RESPONSE\" || doc.assertion_type != \"ERROR\")", "fetch_from": "doctype_name.module", "fetch_if_empty": 1, "fieldname": "module", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Module", - "length": 0, - "no_copy": 0, "options": "Module Def", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:(doc.assertion_type != \"RESPONSE\" || doc.assertion_type != \"ERROR\")", - "fetch_if_empty": 0, "fieldname": "doctype_name", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, "label": "Doctype Name", - "length": 0, - "no_copy": 0, - "options": "DocType", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "DocType" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, "fieldname": "column_break_11", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:(doc.assertion_type != \"Response\" || doc.assertion_type != \"Error\")", - "fetch_if_empty": 0, "fieldname": "reference_field", "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, - "label": "Reference Field", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Reference Field" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:(doc.assertion_type == \"Field Value\" || doc.assertion_type == \"Record Validation\")", - "fetch_if_empty": 0, "fieldname": "docfield_name", - "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, + "fieldtype": "Select", "in_list_view": 1, - "in_standard_filter": 0, - "label": "Docfield Name", - "length": 0, - "no_copy": 0, - "options": "", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Docfield Name" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:(doc.assertion_type == \"Error\")", - "fetch_if_empty": 0, "fieldname": "error_message", "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Error Message", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Error Message" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "default": "Fixed Value", "depends_on": "eval:(doc.assertion_type==='Field Value' || doc.assertion_type==='Response' )", - "fetch_if_empty": 0, "fieldname": "value_type", "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Value Type", - "length": 0, - "no_copy": 0, - "options": "Fixed Value\nCode", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Fixed Value\nCode" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:(doc.assertion_type == \"Response\" && doc.value_type=='Fixed Value')", - "fetch_if_empty": 0, "fieldname": "response_regex", "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Response regex", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Response regex" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:(doc.assertion_type == \"Field Value\" && doc.value_type=='Fixed Value')", - "fetch_if_empty": 0, "fieldname": "docfield_value", "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Docfield Value", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Docfield Value" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:doc.assertion_type == \"Workflow\"", - "fetch_if_empty": 0, "fieldname": "workflow_state", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Workflow State", - "length": 0, - "no_copy": 0, - "options": "Workflow State", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Workflow State" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:doc.assertion_type == \"Workflow\"", - "fetch_if_empty": 0, "fieldname": "workflow_action", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Workflow Action", - "length": 0, - "no_copy": 0, "options": "Workflow Action", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "depends_on": "eval:(\ndoc.value_type=='Code' && (doc.assertion_type=='Field Value' || doc.assertion_type=='Response' )\n)", "description": "Use 'result' variable in your code for checking any condition.", - "fetch_if_empty": 0, "fieldname": "code", "fieldtype": "Code", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Code", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Code" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "default": "1", "depends_on": "eval:(doc.assertion_type==='Record Validation')", - "fetch_if_empty": 0, "fieldname": "record_count", "fieldtype": "Int", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "Record Count", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "Record Count" } ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, "istable": 1, - "max_attachments": 0, - "modified": "2020-05-14 16:10:29.391437", + "links": [], + "modified": "2022-06-27 17:34:25.204178", "modified_by": "Administrator", "module": "Barista", "name": "Assertion", - "name_case": "", "owner": "Administrator", "permissions": [], "quick_entry": 1, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 + "track_changes": 1 } \ No newline at end of file diff --git a/barista/barista/doctype/barista_app/__init__.py b/barista/barista/doctype/barista_app/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/barista/barista/doctype/barista_app/barista_app.json b/barista/barista/doctype/barista_app/barista_app.json new file mode 100644 index 0000000..ad1691b --- /dev/null +++ b/barista/barista/doctype/barista_app/barista_app.json @@ -0,0 +1,92 @@ +{ + "allow_copy": 0, + "allow_events_in_timeline": 0, + "allow_guest_to_view": 0, + "allow_import": 0, + "allow_rename": 0, + "app": "", + "autoname": "", + "beta": 0, + "color": "", + "creation": "2020-10-26 19:45:15.248081", + "custom": 0, + "default_print_format": "", + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "app_name", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "App Name", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 1, + "width": "" + } + ], + "has_web_view": 0, + "hide_heading": 0, + "hide_toolbar": 0, + "icon": "", + "idx": 0, + "image_field": "", + "image_view": 0, + "in_create": 0, + "is_published_field": "", + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "max_attachments": 0, + "modified": "2021-03-24 11:59:28.656888", + "modified_by": "Administrator", + "module": "Barista", + "name": "Barista App", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "restrict_to_domain": "", + "route": "", + "search_fields": "", + "show_name_in_global_search": 0, + "sort_field": "modified", + "sort_order": "ASC", + "timeline_field": "", + "title_field": "", + "track_changes": 1, + "track_seen": 0, + "track_views": 0 +} \ No newline at end of file diff --git a/barista/barista/doctype/barista_app/barista_app.py b/barista/barista/doctype/barista_app/barista_app.py new file mode 100644 index 0000000..ef48253 --- /dev/null +++ b/barista/barista/doctype/barista_app/barista_app.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, elasticrun and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class BaristaApp(Document): + pass diff --git a/barista/barista/doctype/barista_job_setting/__init__.py b/barista/barista/doctype/barista_job_setting/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/barista/barista/doctype/barista_job_setting/barista_job_setting.js b/barista/barista/doctype/barista_job_setting/barista_job_setting.js new file mode 100644 index 0000000..0ce017b --- /dev/null +++ b/barista/barista/doctype/barista_job_setting/barista_job_setting.js @@ -0,0 +1,14 @@ +// Copyright (c) 2020, ElasticRun and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Barista Job Setting', { + refresh: run_job, +}); +function run_job(frm) { + frm.add_custom_button("Run Barista", () => { + frappe.dom.freeze() + frappe.call('barista.barista.api.barista_trigger.barista_job').then(() => frappe.dom.unfreeze()); + }) + frm.custom_buttons["Run Barista"].addClass("btn-danger"); + +} diff --git a/barista/barista/doctype/barista_job_setting/barista_job_setting.json b/barista/barista/doctype/barista_job_setting/barista_job_setting.json new file mode 100644 index 0000000..3dccc2c --- /dev/null +++ b/barista/barista/doctype/barista_job_setting/barista_job_setting.json @@ -0,0 +1,750 @@ +{ + "allow_copy": 0, + "allow_events_in_timeline": 0, + "allow_guest_to_view": 0, + "allow_import": 0, + "allow_rename": 0, + "app": "", + "autoname": "", + "beta": 0, + "color": "", + "creation": "2020-10-26 19:55:44.900295", + "custom": 0, + "default_print_format": "", + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "email_configuration_section", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Email Configuration", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "from_email_id", + "fieldtype": "Table", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "From", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "From Email ID", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "cc_email_id", + "fieldtype": "Table", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Cc", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Cc Email ID", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "column_break_email", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "to_email_id", + "fieldtype": "Table", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "To", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "To Email ID", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "disable_request", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Disable Request Email", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "disable_report", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Disable Report", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "", + "fetch_if_empty": 0, + "fieldname": "disable_execution", + "fieldtype": "Check", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Disable Execution", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "app_configuration_section", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "App Configuration", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "barista_app", + "fieldtype": "Table", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Barista App", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Barista App", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "sorting_configuration_section", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Sorting Configuration", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "", + "description": "Test Suites will get sorted according to this field value", + "fetch_if_empty": 0, + "fieldname": "sort_using", + "fieldtype": "Select", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Sort Using", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Module\nWorkgroup\nSPOC", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "barista_test_suite_configuration_section", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Barista Test Suite Configuration", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "barista_suite", + "fieldtype": "Table", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Barista Suite", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Barista Suite", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "environment", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Environment", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "url", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "URL", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "column_break_env", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "platform", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Platform", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + } + ], + "has_web_view": 0, + "hide_heading": 0, + "hide_toolbar": 0, + "icon": "", + "idx": 0, + "image_field": "", + "image_view": 0, + "in_create": 0, + "is_published_field": "", + "is_submittable": 0, + "issingle": 1, + "istable": 0, + "max_attachments": 0, + "modified": "2021-07-15 13:26:29.494513", + "modified_by": "Administrator", + "module": "Barista", + "name": "Barista Job Setting", + "name_case": "", + "owner": "Administrator", + "permissions": [ + { + "amend": 0, + "cancel": 0, + "create": 1, + "delete": 1, + "email": 1, + "export": 0, + "if_owner": 0, + "import": 0, + "permlevel": 0, + "print": 1, + "read": 1, + "report": 0, + "role": "System Manager", + "set_user_permissions": 0, + "share": 1, + "submit": 0, + "write": 1 + } + ], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "restrict_to_domain": "", + "route": "", + "search_fields": "", + "show_name_in_global_search": 0, + "sort_field": "modified", + "sort_order": "ASC", + "timeline_field": "", + "title_field": "", + "track_changes": 1, + "track_seen": 0, + "track_views": 0 +} \ No newline at end of file diff --git a/barista/barista/doctype/barista_job_setting/barista_job_setting.py b/barista/barista/doctype/barista_job_setting/barista_job_setting.py new file mode 100644 index 0000000..592622f --- /dev/null +++ b/barista/barista/doctype/barista_job_setting/barista_job_setting.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, elasticrun and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class BaristaJobSetting(Document): + pass diff --git a/barista/barista/doctype/barista_job_setting/test_barista_job_setting.js b/barista/barista/doctype/barista_job_setting/test_barista_job_setting.js new file mode 100644 index 0000000..37f5ad0 --- /dev/null +++ b/barista/barista/doctype/barista_job_setting/test_barista_job_setting.js @@ -0,0 +1,23 @@ +/* eslint-disable */ +// rename this file from _test_[name] to test_[name] to activate +// and remove above this line + +QUnit.test("test: Barista Job Setting", function (assert) { + let done = assert.async(); + + // number of asserts + assert.expect(1); + + frappe.run_serially([ + // insert a new Barista Job Setting + () => frappe.tests.make('Barista Job Setting', [ + // values to be set + {key: 'value'} + ]), + () => { + assert.equal(cur_frm.doc.key, 'value'); + }, + () => done() + ]); + +}); diff --git a/barista/barista/doctype/barista_job_setting/test_barista_job_setting.py b/barista/barista/doctype/barista_job_setting/test_barista_job_setting.py new file mode 100644 index 0000000..c09c78e --- /dev/null +++ b/barista/barista/doctype/barista_job_setting/test_barista_job_setting.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, elasticrun and Contributors +# See license.txt +from __future__ import unicode_literals + +import frappe +import unittest + +class TestBaristaJobSetting(unittest.TestCase): + pass diff --git a/barista/barista/doctype/barista_suite/__init__.py b/barista/barista/doctype/barista_suite/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/barista/barista/doctype/barista_suite/barista_suite.json b/barista/barista/doctype/barista_suite/barista_suite.json new file mode 100644 index 0000000..1d10025 --- /dev/null +++ b/barista/barista/doctype/barista_suite/barista_suite.json @@ -0,0 +1,93 @@ +{ + "allow_copy": 0, + "allow_events_in_timeline": 0, + "allow_guest_to_view": 0, + "allow_import": 0, + "allow_rename": 0, + "app": "", + "autoname": "", + "beta": 0, + "color": "", + "creation": "2021-01-14 15:35:08.654585", + "custom": 0, + "default_print_format": "", + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "barista_suite", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Barista Suite", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Test Suite", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 1, + "width": "" + } + ], + "has_web_view": 0, + "hide_heading": 0, + "hide_toolbar": 0, + "icon": "", + "idx": 0, + "image_field": "", + "image_view": 0, + "in_create": 0, + "is_published_field": "", + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "max_attachments": 0, + "modified": "2021-06-18 14:19:27.375443", + "modified_by": "Administrator", + "module": "Barista", + "name": "Barista Suite", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "restrict_to_domain": "", + "route": "", + "search_fields": "", + "show_name_in_global_search": 0, + "sort_field": "modified", + "sort_order": "ASC", + "timeline_field": "", + "title_field": "", + "track_changes": 1, + "track_seen": 0, + "track_views": 0 +} \ No newline at end of file diff --git a/barista/barista/doctype/barista_suite/barista_suite.py b/barista/barista/doctype/barista_suite/barista_suite.py new file mode 100644 index 0000000..1f2080a --- /dev/null +++ b/barista/barista/doctype/barista_suite/barista_suite.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, elasticrun and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class BaristaSuite(Document): + pass diff --git a/barista/barista/doctype/cc_email_id/__init__.py b/barista/barista/doctype/cc_email_id/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/barista/barista/doctype/cc_email_id/cc_email_id.json b/barista/barista/doctype/cc_email_id/cc_email_id.json new file mode 100644 index 0000000..76cb560 --- /dev/null +++ b/barista/barista/doctype/cc_email_id/cc_email_id.json @@ -0,0 +1,92 @@ +{ + "allow_copy": 0, + "allow_events_in_timeline": 0, + "allow_guest_to_view": 0, + "allow_import": 0, + "allow_rename": 0, + "app": "", + "autoname": "", + "beta": 0, + "color": "", + "creation": "2021-01-14 13:34:29.982661", + "custom": 0, + "default_print_format": "", + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "cc_email_id", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Cc Email ID", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 1, + "width": "" + } + ], + "has_web_view": 0, + "hide_heading": 0, + "hide_toolbar": 0, + "icon": "", + "idx": 0, + "image_field": "", + "image_view": 0, + "in_create": 0, + "is_published_field": "", + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "max_attachments": 0, + "modified": "2021-02-23 16:18:55.499572", + "modified_by": "Administrator", + "module": "Barista", + "name": "Cc Email ID", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "restrict_to_domain": "", + "route": "", + "search_fields": "", + "show_name_in_global_search": 0, + "sort_field": "modified", + "sort_order": "ASC", + "timeline_field": "", + "title_field": "", + "track_changes": 1, + "track_seen": 0, + "track_views": 0 +} \ No newline at end of file diff --git a/barista/barista/doctype/cc_email_id/cc_email_id.py b/barista/barista/doctype/cc_email_id/cc_email_id.py new file mode 100644 index 0000000..b8cded7 --- /dev/null +++ b/barista/barista/doctype/cc_email_id/cc_email_id.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, elasticrun and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class CcEmailID(Document): + pass diff --git a/barista/barista/doctype/from_email_id/__init__.py b/barista/barista/doctype/from_email_id/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/barista/barista/doctype/from_email_id/from_email_id.json b/barista/barista/doctype/from_email_id/from_email_id.json new file mode 100644 index 0000000..e7c71ab --- /dev/null +++ b/barista/barista/doctype/from_email_id/from_email_id.json @@ -0,0 +1,129 @@ +{ + "allow_copy": 0, + "allow_events_in_timeline": 0, + "allow_guest_to_view": 0, + "allow_import": 0, + "allow_rename": 0, + "app": "", + "autoname": "", + "beta": 0, + "color": "", + "creation": "2021-01-14 13:33:25.363180", + "custom": 0, + "default_print_format": "", + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "from_email_id", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "From Email ID", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 1, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "password", + "fieldtype": "Password", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Password", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + } + ], + "has_web_view": 0, + "hide_heading": 0, + "hide_toolbar": 0, + "icon": "", + "idx": 0, + "image_field": "", + "image_view": 0, + "in_create": 0, + "is_published_field": "", + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "max_attachments": 0, + "modified": "2021-02-23 16:18:39.994198", + "modified_by": "Administrator", + "module": "Barista", + "name": "From Email ID", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "restrict_to_domain": "", + "route": "", + "search_fields": "", + "show_name_in_global_search": 0, + "sort_field": "modified", + "sort_order": "ASC", + "timeline_field": "", + "title_field": "", + "track_changes": 1, + "track_seen": 0, + "track_views": 0 +} \ No newline at end of file diff --git a/barista/barista/doctype/from_email_id/from_email_id.py b/barista/barista/doctype/from_email_id/from_email_id.py new file mode 100644 index 0000000..e22e2bd --- /dev/null +++ b/barista/barista/doctype/from_email_id/from_email_id.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, elasticrun and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class FromEmailID(Document): + pass diff --git a/barista/barista/doctype/function_parameter/function_parameter.json b/barista/barista/doctype/function_parameter/function_parameter.json index 1a5a1c6..b81f4a1 100644 --- a/barista/barista/doctype/function_parameter/function_parameter.json +++ b/barista/barista/doctype/function_parameter/function_parameter.json @@ -4,9 +4,13 @@ "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 0, + "app": "", + "autoname": "", "beta": 0, + "color": "", "creation": "2020-03-02 17:27:48.714245", "custom": 0, + "default_print_format": "", "docstatus": 0, "doctype": "DocType", "document_type": "", @@ -33,10 +37,13 @@ "label": "Parameter Name", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -44,7 +51,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -53,7 +61,44 @@ "bold": 0, "collapsible": 0, "columns": 0, - "depends_on": "eval:(doc.value===undefined || doc.value==='')", + "fetch_if_empty": 0, + "fieldname": "column_break_5", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "depends_on": "", "fetch_if_empty": 0, "fieldname": "test_data", "fieldtype": "Link", @@ -67,11 +112,14 @@ "label": "Test Data", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "Test Data", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -79,7 +127,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -88,7 +137,7 @@ "bold": 0, "collapsible": 0, "columns": 0, - "depends_on": "eval:(doc.test_data !== undefined && doc.test_data !== '' && doc.is_object===0)", + "depends_on": "eval:( doc.is_object===0)", "fetch_if_empty": 0, "fieldname": "field", "fieldtype": "Select", @@ -102,10 +151,13 @@ "label": "Doctype Field", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -113,7 +165,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -123,7 +176,7 @@ "collapsible": 0, "columns": 0, "default": "0", - "depends_on": "eval:(doc.test_data !== undefined && doc.test_data !== '')", + "depends_on": "", "fetch_if_empty": 0, "fieldname": "is_object", "fieldtype": "Check", @@ -137,10 +190,13 @@ "label": "Pass whole doc as object", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -148,7 +204,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -157,9 +214,87 @@ "bold": 0, "collapsible": 0, "columns": 0, + "default": "json", + "depends_on": "eval:( doc.is_object===1)", "fetch_if_empty": 0, - "fieldname": "column_break_5", - "fieldtype": "Column Break", + "fieldname": "object_type", + "fieldtype": "Select", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Object Type", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "json\ndict", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "section_break_6", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "json", + "fetch_if_empty": 0, + "fieldname": "type", + "fieldtype": "Select", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -167,12 +302,17 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "Paramter Type", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "json\ndata\neval", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -180,7 +320,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -189,7 +330,8 @@ "bold": 0, "collapsible": 0, "columns": 0, - "depends_on": "eval:(doc.test_data===undefined || doc.test_data==='')", + "depends_on": "", + "description": " Use \"doc\" variable to access the intended document.\nExample-\n{\n'doctype': 'DocType',\n'txt': '',\n'searchfield': '{{doc.name}}'\n}\n\nIn case more than one TestData to be used, use the jinja as {{Test_Data_ID.field}} (Ex:- TestData-00001.workflow_state)", "fetch_if_empty": 0, "fieldname": "value", "fieldtype": "Long Text", @@ -203,10 +345,13 @@ "label": "Parameter Value", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -214,20 +359,24 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" } ], "has_web_view": 0, "hide_heading": 0, "hide_toolbar": 0, + "icon": "", "idx": 0, + "image_field": "", "image_view": 0, "in_create": 0, + "is_published_field": "", "is_submittable": 0, "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2020-05-14 18:44:27.203669", + "modified": "2021-05-16 21:05:38.039186", "modified_by": "Administrator", "module": "Barista", "name": "Function Parameter", @@ -237,9 +386,14 @@ "quick_entry": 0, "read_only": 0, "read_only_onload": 0, + "restrict_to_domain": "", + "route": "", + "search_fields": "", "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", + "timeline_field": "", + "title_field": "", "track_changes": 1, "track_seen": 0, "track_views": 0 diff --git a/barista/barista/doctype/run_name/__init__.py b/barista/barista/doctype/run_name/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/barista/barista/doctype/run_name/run_name.js b/barista/barista/doctype/run_name/run_name.js new file mode 100644 index 0000000..adfcbae --- /dev/null +++ b/barista/barista/doctype/run_name/run_name.js @@ -0,0 +1,8 @@ +// Copyright (c) 2022, elasticrun and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Run Name', { + // refresh: function(frm) { + + // } +}); diff --git a/barista/barista/doctype/run_name/run_name.json b/barista/barista/doctype/run_name/run_name.json new file mode 100644 index 0000000..7fbc839 --- /dev/null +++ b/barista/barista/doctype/run_name/run_name.json @@ -0,0 +1,45 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "field:run_name", + "creation": "2022-06-27 16:10:11.581215", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "run_name" + ], + "fields": [ + { + "fieldname": "run_name", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Run Name", + "reqd": 1, + "unique": 1 + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2022-06-27 16:10:11.581215", + "modified_by": "Administrator", + "module": "Barista", + "name": "Run Name", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/barista/barista/doctype/run_name/run_name.py b/barista/barista/doctype/run_name/run_name.py new file mode 100644 index 0000000..fbd3e3c --- /dev/null +++ b/barista/barista/doctype/run_name/run_name.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, elasticrun and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class RunName(Document): + pass diff --git a/barista/barista/doctype/run_name/test_run_name.py b/barista/barista/doctype/run_name/test_run_name.py new file mode 100644 index 0000000..d34095f --- /dev/null +++ b/barista/barista/doctype/run_name/test_run_name.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, elasticrun and Contributors +# See license.txt + +# import frappe +import unittest + +class TestRunName(unittest.TestCase): + pass diff --git a/barista/barista/doctype/test_case/templates/test_case_info.html b/barista/barista/doctype/test_case/templates/test_case_info.html new file mode 100644 index 0000000..efb002b --- /dev/null +++ b/barista/barista/doctype/test_case/templates/test_case_info.html @@ -0,0 +1,145 @@ + +
+
+ +
+
+ +
+ +
+ +
+
+ +
+
+ {{ test_case_doc.testcase_desc or ''}} +
+
+
+
+ +
+
+ +
+
+ {{ test_case_doc.testcase_type or ''}} +
+
+ +
+
+ +
+
+ {{ test_case_doc.testcase_doctype or ''}} +
+
+
+
+ +
+ + +
+
+ +
+
+ {% if test_data_name %} + + {% else %} + + {% endif%} +
+
+ +
+ + + +
+{% if assertions %} + {% for assertion in assertions %} +
+
+ +
+
+
+ +
+
+ {{assertion.assertion_type}} +
+
+
+
+ +
+
+ {{assertion.doctype_name}} +
+
+
+ + +
+ + {% set assertion_type = assertion.assertion_type %} + + {% if assertion_type in ["Field Value", "Record Validation"] %} + {% set assertion_label = "DocField Name" %} + {% set assertion_value = assertion.docfield_name %} + + {% elif assertion_type == "Workflow" %} + {% set assertion_label = "Workflow State" %} + {% set assertion_value = assertion.workflow_state %} + + {% elif assertion_type == "Response" %} + {% set assertion_label = "Response Regex" %} + {% set assertion_value = assertion.response_regex %} + + {% elif assertion_type == "Error" %} + {% set assertion_label = "Error Message" %} + {% set assertion_value = assertion.error_message %} + {% endif %} +
+
+ +
+
+ {{assertion_value}} +
+
+ + + {% if assertion_type in ["Field Value", "Record Validation"] %} +
+
+ +
+
+ {{assertion.docfield_value}} +
+
+ {% endif %} +
+
+
+ {% endfor %} + +{% else %} +
+ No assertion added! +
+{% endif %} + +
+ + + diff --git a/barista/barista/doctype/test_case/test_case.js b/barista/barista/doctype/test_case/test_case.js index f928daa..c4932db 100644 --- a/barista/barista/doctype/test_case/test_case.js +++ b/barista/barista/doctype/test_case/test_case.js @@ -15,6 +15,8 @@ frappe.ui.form.on('Test Case', { return d.fieldname; } else if (d.fieldname && d.fieldtype == 'Table') { return d.fieldname; + } else if (d.fieldname && d.fieldtype == 'Table MultiSelect') { + return d.fieldname; } return null; } @@ -53,15 +55,16 @@ frappe.ui.form.on('Test Case', { return d.fieldname; } else if (d.fieldname && d.fieldtype == 'Table') { return d.fieldname; + } else if (d.fieldname && d.fieldtype == 'Table MultiSelect') { + return d.fieldname; } return null; } ); options.push("docstatus"); options.push("name"); - - frappe.meta.get_docfield("Assertion", "reference_field", cur_frm.doc.name).options = options; - frappe.meta.get_docfield("Assertion", "docfield_name", cur_frm.doc.name).options = options; + cur_frm.fields_dict.assertion.grid.update_docfield_property('reference_field', 'options', options); + cur_frm.fields_dict.assertion.grid.update_docfield_property('docfield_name', 'options', options); }); cur_frm.refresh_fields(); } @@ -108,6 +111,8 @@ frappe.ui.form.on('Testdatafield', { return d.fieldname; } else if (d.fieldname && d.fieldtype == 'Table') { return d.fieldname; + } else if (d.fieldname && d.fieldtype == 'Table MultiSelect') { + return d.fieldname; } return null; @@ -138,6 +143,8 @@ frappe.ui.form.on("Assertion", { return d.fieldname; } else if (d.fieldname && d.fieldtype == 'Table') { return d.fieldname; + } else if (d.fieldname && d.fieldtype == 'Table MultiSelect') { + return d.fieldname; } return null; } @@ -145,8 +152,8 @@ frappe.ui.form.on("Assertion", { options.push("docstatus"); options.push("name"); options.push("parent"); - frappe.meta.get_docfield("Assertion", "reference_field", cur_frm.doc.name).options = options; - frappe.meta.get_docfield("Assertion", "docfield_name", cur_frm.doc.name).options = options; + cur_frm.fields_dict.assertion.grid.update_docfield_property('reference_field', 'options', options); + cur_frm.fields_dict.assertion.grid.update_docfield_property('docfield_name', 'options', options); }); cur_frm.refresh_fields(); } @@ -161,12 +168,15 @@ function addTestCaseDocFields(cur_frm) { return d.fieldname; } else if (d.fieldname && d.fieldtype == 'Table') { return d.fieldname; + } else if (d.fieldname && d.fieldtype == 'Table MultiSelect') { + return d.fieldname; } return null; } ); options.push("name"); cur_frm.fields_dict.test_case_docfield.df.options = options; + cur_frm.fields_dict.update_fields.grid.update_docfield_property('docfield_fieldname', 'options', options); cur_frm.refresh_field("test_case_docfield") }); @@ -192,6 +202,8 @@ function addTestDataDocFields(cur_frm) { return d.fieldname; } else if (d.fieldname && d.fieldtype == 'Table') { return d.fieldname; + } else if (d.fieldname && d.fieldtype == 'Table MultiSelect') { + return d.fieldname; } return null; } diff --git a/barista/barista/doctype/test_case/test_case.json b/barista/barista/doctype/test_case/test_case.json index 9c5f3f6..509cf06 100644 --- a/barista/barista/doctype/test_case/test_case.json +++ b/barista/barista/doctype/test_case/test_case.json @@ -4,10 +4,13 @@ "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 0, - "autoname": "TestCase-.####", + "app": "", + "autoname": "naming_series:", "beta": 0, + "color": "", "creation": "2019-12-26 07:06:48.459977", "custom": 0, + "default_print_format": "", "docstatus": 0, "doctype": "DocType", "document_type": "", @@ -34,10 +37,13 @@ "label": "Test Case Name", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -45,7 +51,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -64,15 +71,18 @@ "in_filter": 0, "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, + "in_standard_filter": 1, "label": "Test Case Type", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "Create\nUpdate\nRead\nDelete\nWorkflow\nFunction", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -80,7 +90,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -99,12 +110,55 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "No", + "fetch_if_empty": 0, + "fieldname": "is_standard", + "fieldtype": "Select", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "is Standarad", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Yes\nNo", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -112,7 +166,47 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "Administrator", + "fetch_if_empty": 0, + "fieldname": "run_as", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Run As", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "User", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -134,10 +228,13 @@ "label": "Test Case Description", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -145,7 +242,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -168,11 +266,14 @@ "label": "Workflow Action", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "Workflow Action Master", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -180,7 +281,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -199,12 +301,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -212,7 +318,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -231,15 +338,18 @@ "in_filter": 0, "in_global_search": 0, "in_list_view": 1, - "in_standard_filter": 0, + "in_standard_filter": 1, "label": "Test Case Doctype", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "DocType", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -247,7 +357,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -271,10 +382,13 @@ "label": "Is Test Data on Different DocType", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -282,7 +396,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -305,11 +420,14 @@ "label": "Test Data", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "Test Data", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -317,7 +435,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -336,12 +455,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -349,7 +472,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -373,11 +497,14 @@ "label": "Test Case DocField ", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -385,7 +512,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -408,10 +536,13 @@ "label": " ", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 1, "remember_last_selected_value": 0, "report_hide": 0, @@ -419,7 +550,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -443,11 +575,14 @@ "label": "Get Value of Test Data DocField", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -455,7 +590,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -475,12 +611,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -488,7 +628,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -511,10 +652,13 @@ "label": "Function name", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -522,7 +666,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -532,7 +677,7 @@ "collapsible": 0, "columns": 0, "depends_on": "eval:(doc.testcase_type === \"Function\")", - "description": "Example-\n{\n'doctype': 'DocType',\n'txt': '',\n'searchfield': '{{doc.name}}'\n}\n Use \"doc\" variable to access the intended document.", + "description": " Use \"doc\" variable to access the intended document.\nExample-\n{\n'doctype': 'DocType',\n'txt': '',\n'searchfield': '{{doc.name}}'\n}", "fetch_if_empty": 0, "fieldname": "json_parameter", "fieldtype": "Code", @@ -546,11 +691,14 @@ "label": "JSON Parameter", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -558,7 +706,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -578,13 +727,17 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "Function Parameter", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -592,7 +745,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -616,10 +770,13 @@ "label": "Update Fields", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -627,7 +784,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -650,11 +808,14 @@ "label": "Update Fields", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "Testdatafield", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -662,7 +823,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -684,10 +846,13 @@ "label": "Assertions", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -695,7 +860,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -717,11 +883,126 @@ "label": "Assertion", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "Assertion", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "naming_series", + "fieldtype": "Select", + "hidden": 1, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "TestCase-", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "section_break_25", + "fieldtype": "Section Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "wait_for", + "fieldtype": "Int", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Wait For(in seconds)", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -729,20 +1010,24 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" } ], "has_web_view": 0, "hide_heading": 0, "hide_toolbar": 0, + "icon": "", "idx": 0, + "image_field": "", "image_view": 0, "in_create": 0, + "is_published_field": "", "is_submittable": 0, "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2020-05-14 15:18:38.681984", + "modified": "2020-08-26 16:39:52.386969", "modified_by": "Administrator", "module": "Barista", "name": "Test Case", @@ -772,10 +1057,14 @@ "quick_entry": 0, "read_only": 0, "read_only_onload": 0, + "restrict_to_domain": "", + "route": "", "search_fields": "testcase_name,testcase_desc", "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", + "timeline_field": "", + "title_field": "", "track_changes": 1, "track_seen": 0, "track_views": 0 diff --git a/barista/barista/doctype/test_case/test_case.py b/barista/barista/doctype/test_case/test_case.py index 31dff26..cf37322 100644 --- a/barista/barista/doctype/test_case/test_case.py +++ b/barista/barista/doctype/test_case/test_case.py @@ -5,18 +5,51 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document - +from frappe.modules.export_file import export_to_files class TestCase(Document): - def validate(self): - if self.testcase_doctype: - docfields = [docfield.fieldname for docfield in frappe.get_meta( - self.testcase_doctype).fields] - docfields.append('docstatus') - docfields.append('name') - docfields.append('parent') - - for row in self.update_fields: - if row.docfield_fieldname not in docfields: - frappe.throw( - f"Invalid DocField {row.docfield_fieldname} in {self.testcase_doctype} of Test Case {self.name}") + def autoname(self): + bs = '' + if frappe.conf.get('barista_series'): + bs = f"{frappe.conf.get('barista_series')}-" + + self.naming_series = 'TestCase-' + + self.naming_series = f"{bs}{self.naming_series}" + + def validate(self): + if self.testcase_doctype: + docfields = [docfield.fieldname for docfield in frappe.get_meta( + self.testcase_doctype).fields] + docfields.append('docstatus') + docfields.append('name') + docfields.append('parent') + + for row in self.update_fields: + if row.docfield_fieldname not in docfields: + frappe.throw( + f"Invalid DocField {row.docfield_fieldname} in {self.testcase_doctype} of Test Case {self.name}") + + def on_update(self): + if self.is_standard == "Yes" and frappe.local.conf.developer_mode and not frappe.flags.in_migrate: + export_to_files(record_list=[[self.doctype, self.name]], record_module="barista", create_init=True) + + +# Get data for test-case-info: +@frappe.whitelist() +def get_test_case_info(test_case): + # Get relevant data to pass to the template: + test_case_doc = frappe.get_doc("Test Case", test_case).as_dict() + assertions = test_case_doc.get("assertion", {}) + test_data_name, test_data_description = '', '' + if test_case_doc.test_data: + test_data_name, test_data_description = frappe.get_value("Test Data", test_case_doc.test_data, ['name', 'description']) + + # render template and fill JINJA values: + rendered_info = frappe.render_template('barista/barista/doctype/test_case/templates/test_case_info.html', + {'test_case_doc': test_case_doc, + 'test_data_name': test_data_name, + 'test_data_description': test_data_description, + 'assertions': assertions}) + + return rendered_info \ No newline at end of file diff --git a/barista/barista/doctype/test_case/test_case_execution.py b/barista/barista/doctype/test_case/test_case_execution.py index ed937f0..ec3fead 100644 --- a/barista/barista/doctype/test_case/test_case_execution.py +++ b/barista/barista/doctype/test_case/test_case_execution.py @@ -39,6 +39,8 @@ import datetime import dateutil import time +import string +import random urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) @@ -47,16 +49,22 @@ class TestCaseExecution(): def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, suite_srno, total_suites, run_name): + error_message = '' + test_result_doc = frappe.get_doc({"doctype":"Test Result"}) + new_record_doc = frappe._dict() + testdata_doc = frappe._dict() + testdata_doc_test_record_name = None try: start_time = time.time() function_result = None - + # Populate generic test result fields - test_result_doc = frappe.new_doc("Test Result") + test_result_doc.test_run_name = run_name test_result_doc.test_suite = test_suite test_result_doc.action = "Test Case" testcase_doc = frappe.get_doc("Test Case", testcase) + frappe.set_user(testcase_doc.run_as or 'Administrator') testcase_doc.testcase_type = testcase_doc.testcase_type.upper() test_result_doc.test_case = testcase_doc.name test_result_doc.test_data_id = testcase_doc.test_data @@ -71,7 +79,7 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui testdata_doc = frappe.get_doc( "Test Data", testcase_doc.test_data) # cannot use insert scripts in test case data generation as doctype.name will not be recorded - if (testdata_doc.use_script == 1): + if (testdata_doc.create_using == 'Sql Script'): test_result_doc.test_case_execution = "Execution Failed" test_result_doc.execution_result = "The test data - " + testdata_doc.name + \ " selected is genereted using script for which record name cannot be recorded" @@ -85,44 +93,41 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui testdata_doc_test_record_name = None create_test_run_log(run_name, testcase_doc.test_data, None) # get record document - new_record_doc = testdata_generator.create_testdata( + new_record_doc, error_message = testdata_generator.create_testdata( testcase_doc.test_data, run_name) - error_message = None + if (testcase_doc.testcase_type == "CREATE"): try: if new_record_doc: try: - new_record_doc.save() - testdata_doc_test_record_name = new_record_doc.name - - create_test_run_log( - run_name, testcase_doc.test_data, new_record_doc.name) - testdata_generator.set_record_name_child_table( - new_record_doc, testdata_doc, True, run_name) - print("\033[0;33;93m >>> Test Data created") + new_record_doc.save(True) except frappe.DuplicateEntryError as e: new_record_doc = resolve_duplicate_entry_error( e, testdata_doc, run_name) - testdata_doc_test_record_name = new_record_doc.name + testdata_doc_test_record_name = new_record_doc.name - create_test_run_log( - run_name, testcase_doc.test_data, new_record_doc.name) + create_test_run_log( + run_name, testcase_doc.test_data, new_record_doc.name) + + if testdata_doc.create_using == 'Data': testdata_generator.set_record_name_child_table( new_record_doc, testdata_doc, True, run_name) - print("\033[0;33;93m >>> Test Data created") + print("\033[0;33;93m >>> Test Data created") else: frappe.throw( f'Test Data {testcase_doc.test_data} generated None doc. Please check Test Data {testcase_doc.test_data}') except Exception as e: + frappe.db.rollback() frappe.log_error(frappe.get_traceback( ), ('barista-CREATE-'+testcase_doc.name+'-'+str(e))[:error_log_title_len]) - error_message = str(e) + error_message += '\n' + str(e) print('\033[0;31;91m Error occurred ---', str(e)) elif (testcase_doc.testcase_type == "UPDATE"): + create_new = False try: - create_new = False + if testcase_doc.testcase_doctype != testdata_doc.doctype_name: value_from_test_record_doc = frappe.db.get_value( testdata_doc.doctype_name, testdata_doc_test_record_name, testcase_doc.test_data_docfield) @@ -142,7 +147,7 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui # create the record if already not created if(new_record_doc and new_record_doc.name == None): try: - new_record_doc.save() + new_record_doc.save(True) except frappe.UniqueValidationError as e: new_record_doc = resolve_unique_validation_error( e, testdata_doc, run_name) @@ -152,15 +157,13 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui run_name, testdata_doc.name, new_record_doc.name) # now take the fields to be updated - update_fields = frappe.get_list("Testdatafield", filters={ - "parent": testcase_doc.name}) fields = frappe.get_meta( testcase_doc.testcase_doctype).fields - for update_field in update_fields: - + for update_field in testcase_doc.update_fields: + field_doc = frappe._dict() update_field_doc = frappe.get_doc( - "Testdatafield", update_field['name']) + "Testdatafield", update_field.name) for field in fields: if field.fieldname == update_field_doc.docfield_fieldname: @@ -185,14 +188,14 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui new_record_doc.set(update_field_doc.docfield_fieldname, int( update_field_doc.docfield_value)) elif new_record_doc: - if (field_doc.fieldtype == "Table"): + if (field_doc.fieldtype in ["Table", "Table MultiSelect"]): # if it is table then user will have to add multiple rows for multiple records. # each test data field will link to one record. child_testdata_doc = frappe.get_doc( "Test Data", update_field_doc.linkfield_name) if(child_testdata_doc.doctype_type == "Transaction"): create_new = True - child_doc = testdata_generator.create_testdata( + child_doc, error_message = testdata_generator.create_testdata( update_field_doc.linkfield_name, run_name) child_doc.parentfield = field_doc.fieldname @@ -211,11 +214,11 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui create_test_run_log( run_name, child_testdata_doc.name, None) - child_doc = testdata_generator.create_testdata( + child_doc, error_message = testdata_generator.create_testdata( update_field_doc.linkfield_name, run_name) try: if child_doc: - child_doc.save() + child_doc.save(True) else: frappe.throw( f"Child Doc is None. Test Data of Child {update_field_doc.linkfield_name}. Test Data of Parent {testdata_doc.name}") @@ -230,7 +233,7 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui create_test_run_log( run_name, child_testdata_doc.name, child_doc.name) new_record_doc.set( - field_doc.fieldname, child_doc.name) + field_doc.fieldname, child_doc.get(update_field_doc.linkfield_key or "name")) # for rest of data type.. either it should be code or fixed value elif (update_field_doc.docfield_code_value == "Code"): if update_field_doc.docfield_code and not update_field_doc.linkfield_name: @@ -246,7 +249,7 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui update_field_doc.docfield_fieldname, update_field_doc.docfield_value) try: if new_record_doc: - new_record_doc.save() + new_record_doc.save(True) print("\033[0;33;93m >>> Test Data updated") else: frappe.throw( @@ -256,9 +259,10 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui e, testdata_doc, run_name) except Exception as e: + frappe.db.rollback() frappe.log_error(frappe.get_traceback( ), ('barista-UPDATE-'+testcase_doc.name+'-'+str(e))[:error_log_title_len]) - error_message = str(e) + error_message += '\n' + str(e) print('\033[0;31;91m Error occurred ---', str(e)) testdata_generator.set_record_name_child_table( @@ -271,19 +275,21 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui testdata_doc.doctype_name, testdata_doc_test_record_name) record_doc.delete() except Exception as e: + frappe.db.rollback() frappe.log_error(frappe.get_traceback( ), ('barista-'+testcase_doc.name+'-DELETE-'+str(e))[:error_log_title_len]) - error_message = str(e) + error_message += '\n' + str(e) print( "\033[0;31;91m >>> Error in deleting - "+str(e)) elif (testcase_doc.testcase_type == "WORKFLOW"): + current_workflow_state = None try: start_time = time.time() - current_workflow_state = None + if(new_record_doc and new_record_doc.name == None): current_workflow_state = new_record_doc.workflow_state try: - new_record_doc = new_record_doc.save() + new_record_doc = new_record_doc.save(True) except frappe.UniqueValidationError as e: new_record_doc = resolve_unique_validation_error( e, testdata_doc, run_name) @@ -294,21 +300,26 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui apply_workflow(new_record_doc, testcase_doc.workflow_state) print("\033[0;32;92m >>> Workflow Applied") except Exception as e: + frappe.db.rollback() frappe.log_error(frappe.get_traceback(), (f"""barista-WORKFLOW-{testcase_doc.name}-{str( - e)}-DocType-[{testdata_doc.doctype_name}]-WorkflowState-[{current_workflow_state}]-Action-[{testcase_doc.workflow_state}]""")[:error_log_title_len]) - error_message = str(e) + e)}-DocType-[{testdata_doc.doctype_name}]-WorkflowState-[{current_workflow_state}]-Action-[{testcase_doc.workflow_state}]""")[:error_log_title_len]) + error_message += '\n' + str(e) print( "\033[0;31;91m >>> Error in applying Workflow - "+str(e)) elif (testcase_doc.testcase_type == "FUNCTION"): kwargs = {} + context_dict = {} + resolved_jinja = ' ' try: for param in testcase_doc.function_parameters: parameter = param.parameter - - if param.value and param.value.strip()[0] in ['{', '[']: + value = None + if param.value and (param.value.strip()[0] in ['{', '[']) and ('{{' not in param.value): value = eval(param.value) - else: + elif param.type == 'eval': + value = eval(param.value) + elif param.value and '{{' not in param.value: value = param.value kwargs[parameter] = value @@ -321,33 +332,47 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui test_record_doc = frappe.get_doc( test_record_doctype, test_record_name) if param.is_object == 1: - kwargs[parameter] = test_record_doc.as_dict() + if param.object_type == 'dict': + kwargs[parameter] = test_record_doc.as_dict() + elif param.object_type == 'json': + kwargs[parameter] = test_record_doc.as_json() + elif param.field: + kwargs[parameter] = test_record_doc.get(param.field) else: - kwargs[parameter] = test_record_doc.get( - param.field) + try: + if '{{' in param.value: + context_dict = {'doc':test_record_doc.as_dict()} + jinja, context_dict = self.fetch_context(param.value, context_dict, run_name) + resolved_jinja = render_template(jinja, context_dict) + kwargs[parameter] = eval(str(resolved_jinja)) + except Exception as e: + + frappe.log_error(frappe.get_traceback(), ('barista-FUNCTION-'+testcase_doc.name+'-'+str(e))[:error_log_title_len]) + print( + "\033[0;31;91m >>>> Error in Function Parameter\n ", str(e)) print("\033[0;33;93m >>> Executing Function --", testcase_doc.function_name) if testcase_doc.json_parameter and testcase_doc.json_parameter.strip() != '': - context_dict = {} - resolved_jinja = ' ' - if testcase_doc.testcase_doctype and testcase_doc.test_data: - test_record_name = frappe.db.get_value( - 'Test Run Log', {'test_run_name': run_name, 'test_data': testcase_doc.test_data}, 'test_record') - - context = frappe.get_doc( - testcase_doc.testcase_doctype, test_record_name).as_dict() - context_dict = {"doc": context} + try: + testcase_doc.json_parameter = testcase_doc.json_parameter.replace('null', 'None').replace('true', 'True').replace('false', 'False') + if testcase_doc.testcase_doctype and testcase_doc.test_data: + test_record_name = frappe.db.get_value( + 'Test Run Log', {'test_run_name': run_name, 'test_data': testcase_doc.test_data}, 'test_record') + + context = frappe.get_doc( + testcase_doc.testcase_doctype, test_record_name).as_dict() + context_dict = {"doc": context} validate_template(testcase_doc.json_parameter) resolved_jinja = render_template( testcase_doc.json_parameter, context_dict) + kwargs.update(eval(str(resolved_jinja))) except Exception as e: + frappe.db.rollback() + frappe.log_error(frappe.get_traceback(), ('barista-FUNCTION-'+testcase_doc.name+'-'+str(e))[:error_log_title_len]) print( "\033[0;31;91m >>>> Error in Json Parameter\n ", str(e)) - - kwargs.update(eval(str(resolved_jinja))) - method = testcase_doc.function_name if method and '.' in method: args = [] @@ -363,12 +388,13 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui method, **kwargs) print("\033[0;32;92m >>> Function Executed") except Exception as e: + frappe.db.rollback() frappe.log_error(frappe.get_traceback( ), ('barista-FUNCTION-'+testcase_doc.name+'-'+str(e))[:error_log_title_len]) - error_message = str(e) + error_message += '\n' + str(e) print( "\033[0;31;91m >>>> Execution of function failed\n Error occurred :", str(e)) - + test_result_doc.execution_time = get_execution_time(start_time) assertions = frappe.get_list( @@ -377,22 +403,28 @@ def run_testcase(self, testcase, test_suite, testcase_srno, total_testcases, sui if len(assertions) == 0: test_result_doc.execution_result = 'Assertions are not present in the TestCase. Please add atleast one assertion.' test_result_doc.test_case_status = "Failed" - test_result_doc.save() + test_result_doc.save(True) + frappe.db.commit() + # Sleep For Time + if testcase_doc.wait_for: + time.sleep(testcase_doc.wait_for) for assertion in assertions: self.process_assertion( assertion, testcase_doc, run_name, error_message, function_result, test_result_doc) except Exception as e: + frappe.db.rollback() frappe.log_error(frappe.get_traceback( ), ('barista-Critical Error-'+testcase+'-'+str(e))[:error_log_title_len]) test_result_doc.test_case_execution = "Execution Failed" test_result_doc.execution_result = str(e) test_result_doc.test_case_status = "Failed" - test_result_doc.save() finally: print("\033[0;36;96m>> " + "Execution Ended \n\n") - test_result_doc.save() + test_result_doc.save(True) + frappe.set_user("Administrator") + def process_assertion(self, assertion, testcase_doc, run_name, error_message, function_result, test_result_doc): assertion_doc = frappe.get_doc("Assertion", assertion['name']) @@ -400,6 +432,10 @@ def process_assertion(self, assertion, testcase_doc, run_name, error_message, fu value_type = 'Fixed Value' record_count = 1 + testdata_doc_test_record_name = None + test_record_doc = None + validation_doctype = [] + testdata_doc = frappe._dict() if assertion_doc.value_type: value_type = assertion_doc.value_type @@ -415,13 +451,12 @@ def process_assertion(self, assertion, testcase_doc, run_name, error_message, fu assertion_result = frappe.new_doc("Assertion Result") assertion_result.assertion = assertion_doc.name assertion_result.assertion_status = "Passed" - testdata_doc = frappe.get_doc( - 'Test Data', testcase_doc.test_data) - testdata_doc_test_record_name = frappe.db.get_value( - 'Test Run Log', {'test_run_name': run_name, 'test_data': testcase_doc.test_data}, 'test_record') + if testcase_doc.test_data: + testdata_doc = frappe.get_doc( + 'Test Data', testcase_doc.test_data) + testdata_doc_test_record_name = frappe.db.get_value('Test Run Log', {'test_run_name': run_name, 'test_data': testcase_doc.test_data}, 'test_record') if(assertion_doc.assertion_type != "RESPONSE" and assertion_doc.assertion_type != "ERROR"): - validation_doctype = frappe.get_all(assertion_doc.doctype_name, filters={ - assertion_doc.reference_field: testdata_doc_test_record_name}) + validation_doctype = frappe.get_all(assertion_doc.doctype_name, filters={assertion_doc.reference_field: testdata_doc_test_record_name}) if (assertion_doc.assertion_type == "FIELD VALUE"): if (len(validation_doctype) != 1): assertion_result.assertion_status = "Failed" @@ -484,24 +519,22 @@ def process_assertion(self, assertion, testcase_doc, run_name, error_message, fu filter_field_to_refer = 'name' if assertion_doc.docfield_name and assertion_doc.docfield_name.strip() != '': filter_field_to_refer = assertion_doc.docfield_name - test_record_doc = frappe.get_doc( - testdata_doc.doctype_name, testdata_doc_test_record_name) + if testdata_doc_test_record_name: + test_record_doc = frappe.get_doc(testdata_doc.doctype_name, testdata_doc_test_record_name) if test_record_doc: - filter_field_value = test_record_doc.get( - filter_field_to_refer) + filter_field_value = test_record_doc.get(filter_field_to_refer) else: filter_field_value = '' validation_doctype = frappe.get_all(assertion_doc.doctype_name, filters={ - assertion_doc.reference_field: filter_field_value}) + assertion_doc.reference_field: filter_field_value}) if (len(validation_doctype) == record_count): - records = [doc['name'] for doc in validation_doctype] + records = [str(doc['name']) for doc in validation_doctype] # Assertion is successful assertion_result = frappe.new_doc("Assertion Result") assertion_result.assertion = assertion_doc.name assertion_result.assertion_status = "Passed" - assertion_result.assertion_result = "Record found - " + \ - ','.join(records) + assertion_result.assertion_result = f"Record found - {','.join(records)}" print("\033[0;32;92m >>>> Assertion Passed") else: assertion_result.assertion_status = "Failed" @@ -617,8 +650,20 @@ def to_json_converter(value): assertion_result.parentfield = "assertion_results" test_result_doc.get("assertion_results").append( assertion_result) - test_result_doc.save() - + test_result_doc.save(True) + + def fetch_context(self, value, context_dict, run_name): + """Fetches the Context For all TestData""" + for data in list(set(re.findall('{{([^.]*)',value))): + i = 1 + if frappe.db.exists("Test Data", data): + test_record_name = frappe.db.get_value('Test Run Log', {'test_run_name': run_name, 'test_data': data}, ['test_data_doctype','test_record']) + if test_record_name: + key = f"doc{i}" + context_dict[key] = frappe.get_doc(test_record_name[0], test_record_name[1]).as_dict() + value = value.replace(data, key) + + return (value, context_dict) def get_execution_time(start_time): end_time = round(time.time() - start_time, 4) @@ -628,3 +673,5 @@ def get_execution_time(start_time): time_uom = 'minutes' return str(end_time)+' '+time_uom + + diff --git a/barista/barista/doctype/test_data/test_data.js b/barista/barista/doctype/test_data/test_data.js index 9ef0777..c9d19ce 100644 --- a/barista/barista/doctype/test_data/test_data.js +++ b/barista/barista/doctype/test_data/test_data.js @@ -10,25 +10,34 @@ frappe.ui.form.on('Test Data', { $('textarea[data-fieldname=eval_function_result').css('height', '30px'); if (cur_frm.doc.doctype_name) { if (cur_frm.doc.doctype_name) { - frappe.model.with_doctype(cur_frm.doc.doctype_name, function () { - var options = $.map(frappe.get_meta(cur_frm.doc.doctype_name).fields, - function (d) { - if (d.fieldname && frappe.model.no_value_type.indexOf(d.fieldtype) === -1) { - return d.fieldname; - } else if (d.fieldname && d.fieldtype == 'Table') { - return d.fieldname; - } - return null; - } - ); - options.push("docstatus"); - frappe.meta.get_docfield("Testdatafield", "docfield_fieldname", cur_frm.doc.name).options = options; - }); + loadOptionsFromDoctype(); } } + }, + doctype_name: function (frm) { + loadOptionsFromDoctype(); } }); +function loadOptionsFromDoctype() { + frappe.model.with_doctype(cur_frm.doc.doctype_name, function () { + var options = $.map(frappe.get_meta(cur_frm.doc.doctype_name).fields, + function (d) { + if (d.fieldname && frappe.model.no_value_type.indexOf(d.fieldtype) === -1) { + return d.fieldname; + } else if (d.fieldname && d.fieldtype == 'Table') { + return d.fieldname; + } else if (d.fieldname && d.fieldtype == 'Table MultiSelect') { + return d.fieldname; + } + return null; + } + ); + options.push("docstatus"); + options.push("name"); + frappe.meta.get_docfield("Testdatafield", "docfield_fieldname", cur_frm.doc.name).options = options; + }); +} frappe.ui.form.on('Testdatafield', { refresh: function (frm, cdt, cdn) { @@ -46,6 +55,8 @@ frappe.ui.form.on('Testdatafield', { return d.fieldname; } else if (d.fieldname && d.fieldtype == 'Table') { return d.fieldname; + } else if (d.fieldname && d.fieldtype == 'Table MultiSelect') { + return d.fieldname; } return null; } @@ -91,6 +102,9 @@ frappe.ui.form.on("Test Data", "doctype_name", function (frm, cdt, cdn) { } else if (d.fieldname && d.fieldtype == 'Table') { tableFields.push(d.fieldname); return d.fieldname; + } else if (d.fieldname && d.fieldtype == 'Table MultiSelect') { + tableFields.push(d.fieldname); + return d.fieldname; } return null; } @@ -193,4 +207,82 @@ frappe.ui.form.on("Function Parameter", "test_data", function (frm, cdt, cdn) { }); }); +}); + +frappe.ui.form.on("Test Data Condition", "test_data", function (frm, cdt, cdn) { + let row = locals[cdt][cdn]; + let docFields = []; + if (!row.test_data) { + return; + } + frappe.db.get_value('Test Data', row.test_data, 'doctype_name').then((d) => { + let testDataDoctype = d.message.doctype_name; + frappe.model.with_doctype(testDataDoctype); + frappe.call({ + method: 'frappe.desk.form.load.getdoctype', + args: { + 'doctype': testDataDoctype, + 'with_parent': 1 + }, + freeze: true, + callback: function (r) { + if (!r.exc) { + frappe.model.with_doctype(testDataDoctype, function () { + let fields = frappe.get_meta(testDataDoctype).fields; + let options = []; + fields.forEach((f) => { + if (!['Section Break', 'Column Break'].includes(f.fieldtype)) { + options.push(f.fieldname); + } + }) + options.push("docstatus"); + options.push('name'); + options.push('doctype'); + options.push('parent'); + docFields = options; + frappe.meta.get_docfield("Test Data Condition", "field", cur_frm.doc.name).options = docFields; + }); + cur_frm.refresh_fields(); + } + } + }); + }); + +}); +frappe.ui.form.on("Test Data Condition", "reference_doctype", function (frm, cdt, cdn) { + let row = locals[cdt][cdn]; + let docFields = []; + if (!row.reference_doctype) { + return; + } + frappe.model.with_doctype(row.reference_doctype); + frappe.call({ + method: 'frappe.desk.form.load.getdoctype', + args: { + 'doctype': row.reference_doctype, + 'with_parent': 1 + }, + freeze: true, + callback: function (r) { + if (!r.exc) { + frappe.model.with_doctype(row.reference_doctype, function () { + let fields = frappe.get_meta(row.reference_doctype).fields; + let options = []; + fields.forEach((f) => { + if (!['Section Break', 'Column Break'].includes(f.fieldtype)) { + options.push(f.fieldname); + } + }) + options.push("docstatus"); + options.push('name'); + options.push('doctype'); + options.push('parent'); + docFields = options; + frappe.meta.get_docfield("Test Data Condition", "reference_field", cur_frm.doc.name).options = docFields; + frappe.meta.get_docfield("Test Data Condition", "field_to_refer", cur_frm.doc.name).options = docFields; + }); + cur_frm.refresh_fields(); + } + } + }); }); \ No newline at end of file diff --git a/barista/barista/doctype/test_data/test_data.json b/barista/barista/doctype/test_data/test_data.json index d87c40b..6175990 100644 --- a/barista/barista/doctype/test_data/test_data.json +++ b/barista/barista/doctype/test_data/test_data.json @@ -4,10 +4,13 @@ "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 0, - "autoname": "TestData-.####", + "app": "", + "autoname": "naming_series:", "beta": 0, + "color": "", "creation": "2019-12-26 06:54:24.843530", "custom": 0, + "default_print_format": "", "docstatus": 0, "doctype": "DocType", "document_type": "", @@ -35,10 +38,13 @@ "label": "Description", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -46,7 +52,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -68,11 +75,14 @@ "label": "Doctype Name", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "DocType", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -80,7 +90,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -102,11 +113,14 @@ "label": "Doctype Type", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "Master\nTransaction", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -114,7 +128,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -133,12 +148,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -146,7 +165,47 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "No", + "fetch_if_empty": 0, + "fieldname": "is_standard", + "fieldtype": "Select", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Is Standard", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Yes\nNo", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -169,11 +228,14 @@ "label": "Module Name", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "Module Def", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 1, "remember_last_selected_value": 0, "report_hide": 0, @@ -181,7 +243,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -204,11 +267,14 @@ "label": "App Name", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 1, "remember_last_selected_value": 0, "report_hide": 0, @@ -216,7 +282,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -238,11 +305,14 @@ "label": "Existing Record", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "doctype_name", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -250,7 +320,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -269,12 +340,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -282,7 +357,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -291,11 +367,10 @@ "bold": 0, "collapsible": 0, "columns": 0, - "default": "0", - "depends_on": "eval:(doc.use_function ===0)", + "default": "Data", "fetch_if_empty": 0, - "fieldname": "use_script", - "fieldtype": "Check", + "fieldname": "create_using", + "fieldtype": "Select", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -303,13 +378,17 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Use Script", + "label": "Create Using", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Data\nSql Script\nFunction", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -317,7 +396,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -326,9 +406,10 @@ "bold": 0, "collapsible": 0, "columns": 0, + "depends_on": "eval:(doc.create_using === 'Function')", "fetch_if_empty": 0, - "fieldname": "column_break_10", - "fieldtype": "Column Break", + "fieldname": "section_break_12", + "fieldtype": "Section Break", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -336,12 +417,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -349,7 +434,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -358,11 +444,9 @@ "bold": 0, "collapsible": 0, "columns": 0, - "default": "0", - "depends_on": "eval:(doc.use_script ===0)", "fetch_if_empty": 0, - "fieldname": "use_function", - "fieldtype": "Check", + "fieldname": "function_name", + "fieldtype": "Small Text", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -370,13 +454,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Use Function", + "label": "Function Name", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -384,7 +471,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -393,10 +481,10 @@ "bold": 0, "collapsible": 0, "columns": 0, - "depends_on": "eval:(doc.use_function === 1)", + "description": "Use 'result' variable for evaluating and storing Test Record Name. Default key 'name' will be considered if nothing is provided.", "fetch_if_empty": 0, - "fieldname": "section_break_12", - "fieldtype": "Section Break", + "fieldname": "eval_function_result", + "fieldtype": "Small Text", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -404,12 +492,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "Evaluate Function Result", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -417,7 +509,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -427,8 +520,8 @@ "collapsible": 0, "columns": 0, "fetch_if_empty": 0, - "fieldname": "function_name", - "fieldtype": "Small Text", + "fieldname": "function_parameters", + "fieldtype": "Table", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -436,13 +529,17 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Function Name", + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Function Parameter", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -450,7 +547,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -459,10 +557,9 @@ "bold": 0, "collapsible": 0, "columns": 0, - "description": "Use 'result' variable for evaluating and storing Test Record Name. Default key 'name' will be considered if nothing is provided.", "fetch_if_empty": 0, - "fieldname": "eval_function_result", - "fieldtype": "Small Text", + "fieldname": "conditions", + "fieldtype": "Table", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -470,13 +567,17 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Evaluate Function Result", + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Test Data Condition", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -484,7 +585,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -493,9 +595,10 @@ "bold": 0, "collapsible": 0, "columns": 0, + "depends_on": "eval:(doc.create_using === 'Sql Script')", "fetch_if_empty": 0, - "fieldname": "function_parameters", - "fieldtype": "Table", + "fieldname": "section_break_10", + "fieldtype": "Section Break", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -503,13 +606,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "", "length": 0, "no_copy": 0, - "options": "Function Parameter", + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -517,7 +623,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -526,10 +633,10 @@ "bold": 0, "collapsible": 0, "columns": 0, - "depends_on": "eval:(doc.use_script === 1)", + "depends_on": "", "fetch_if_empty": 0, - "fieldname": "section_break_10", - "fieldtype": "Section Break", + "fieldname": "insert_script", + "fieldtype": "Code", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -537,12 +644,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "Sql Script", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -550,7 +661,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -559,10 +671,10 @@ "bold": 0, "collapsible": 0, "columns": 0, - "depends_on": "", + "depends_on": "eval:(doc.create_using === 'Data')", "fetch_if_empty": 0, - "fieldname": "insert_script", - "fieldtype": "Code", + "fieldname": "test_data_section", + "fieldtype": "Section Break", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -570,13 +682,16 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Insert Script", + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -584,7 +699,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -593,9 +709,11 @@ "bold": 0, "collapsible": 0, "columns": 0, + "depends_on": "", + "description": "NOTE :- Link and Table field will not auto-set and will be left blank if not set here", "fetch_if_empty": 0, - "fieldname": "test_data_section", - "fieldtype": "Section Break", + "fieldname": "docfield_value", + "fieldtype": "Table", "hidden": 0, "ignore_user_permissions": 0, "ignore_xss_filter": 0, @@ -603,13 +721,17 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "", + "label": "Test Data", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "options": "Testdatafield", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -617,7 +739,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -626,26 +749,27 @@ "bold": 0, "collapsible": 0, "columns": 0, - "depends_on": "eval:(doc.use_script === 0 && doc.use_function ===0)", - "description": "NOTE :- Link and Table field will not auto-set and will be left blank if not set here", "fetch_if_empty": 0, - "fieldname": "docfield_value", - "fieldtype": "Table", - "hidden": 0, + "fieldname": "naming_series", + "fieldtype": "Select", + "hidden": 1, "ignore_user_permissions": 0, "ignore_xss_filter": 0, "in_filter": 0, "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, - "label": "Test Data", + "label": "", "length": 0, "no_copy": 0, - "options": "Testdatafield", + "oldfieldname": "", + "oldfieldtype": "", + "options": "TestData-", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -653,20 +777,24 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" } ], "has_web_view": 0, "hide_heading": 0, "hide_toolbar": 0, + "icon": "", "idx": 0, + "image_field": "", "image_view": 0, "in_create": 0, + "is_published_field": "", "is_submittable": 0, "issingle": 0, "istable": 0, "max_attachments": 0, - "modified": "2020-05-14 19:41:07.706409", + "modified": "2020-08-19 09:53:55.445436", "modified_by": "Administrator", "module": "Barista", "name": "Test Data", @@ -696,10 +824,14 @@ "quick_entry": 0, "read_only": 0, "read_only_onload": 0, - "search_fields": "doctype_name,description,use_script", + "restrict_to_domain": "", + "route": "", + "search_fields": "doctype_name,description,create_using", "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", + "timeline_field": "", + "title_field": "", "track_changes": 1, "track_seen": 0, "track_views": 0 diff --git a/barista/barista/doctype/test_data/test_data.py b/barista/barista/doctype/test_data/test_data.py index 8d810ca..28c3d88 100644 --- a/barista/barista/doctype/test_data/test_data.py +++ b/barista/barista/doctype/test_data/test_data.py @@ -34,17 +34,30 @@ import random import datetime import dateutil - +from frappe.modules.export_file import export_to_files class TestData(Document): - def validate(self): - docfields = [docfield.fieldname for docfield in frappe.get_meta( - self.doctype_name).fields] - docfields.append('docstatus') - docfields.append('name') - docfields.append('parent') + def autoname(self): + bs = '' + if frappe.conf.get('barista_series'): + bs = f"{frappe.conf.get('barista_series')}-" + + self.naming_series = 'TestData-' + + self.naming_series = f"{bs}{self.naming_series}" + + def validate(self): + docfields = [docfield.fieldname for docfield in frappe.get_meta( + self.doctype_name).fields] + docfields.append('docstatus') + docfields.append('name') + docfields.append('parent') + if self.create_using == 'Data': + for row in self.docfield_value: + if row.docfield_fieldname not in docfields: + frappe.throw( + f"Invalid DocField {row.docfield_fieldname} in {self.doctype_name} of {self.name}") - for row in self.docfield_value: - if row.docfield_fieldname not in docfields: - frappe.throw( - f"Invalid DocField {row.docfield_fieldname} in {self.doctype_name}") + def on_update(self): + if self.is_standard == "Yes" and frappe.local.conf.developer_mode and not frappe.flags.in_migrate: + export_to_files(record_list=[[self.doctype, self.name]], record_module="barista", create_init=True) \ No newline at end of file diff --git a/barista/barista/doctype/test_data/test_data_generator.py b/barista/barista/doctype/test_data/test_data_generator.py index 83c7208..99cd3f0 100644 --- a/barista/barista/doctype/test_data/test_data_generator.py +++ b/barista/barista/doctype/test_data/test_data_generator.py @@ -5,6 +5,7 @@ from __future__ import unicode_literals import frappe from frappe.model.document import Document +from frappe.utils.jinja import validate_template, render_template import ast import json import requests @@ -34,8 +35,11 @@ import random import datetime import dateutil +import string error_log_title_len = 1000 +yellow = '\033[0;33;93m' +red = '\033[0;31;91m' class TestDataGenerator(): @@ -44,16 +48,16 @@ def create_pretest_data(self, suite, run_name): all_testdata = frappe.db.sql_list( """select distinct td.name from `tabTest Data` td join `tabTestdata Item` tdi on tdi.test_data=td.name where tdi.parent=%(parent)s order by tdi.idx""", {'parent': suite}) if len(all_testdata) != 0: - print('\033[0;33;93m Creating Pre-Test Data') + print(f'{yellow}Creating Pre-Test Data') for testdata in all_testdata: try: testdata_doc = frappe.get_doc("Test Data", testdata) - if (testdata_doc.use_script == 1): + if (testdata_doc.create_using == 'Sql Script'): self.create_testdata(testdata, run_name) - elif (testdata_doc.use_function == 1): + elif (testdata_doc.create_using == 'Function'): self.create_testdata_function(testdata, run_name) else: - new_doc = self.create_testdata(testdata, run_name) + new_doc, error_message = self.create_testdata(testdata, run_name) if testdata_doc.doctype_type == 'Transaction': new_doc.save(True) created_doc = new_doc @@ -78,129 +82,138 @@ def create_pretest_data(self, suite, run_name): frappe.log_error(frappe.get_traceback( ), (f'barista-TestDataGenerator-{testdata}-{str(e)}')[:error_log_title_len]) if len(all_testdata) != 0: - print('\033[0;33;93m Pre-Test Data created successfully') + print(f'{yellow}Pre-Test Data created successfully') print('') frappe.db.commit() def create_testdata(self, testdata, run_name): + current_fieldname = '' + error_message = '' + new_doc = None try: - current_fieldname = '' testdata_doc = frappe.get_doc('Test Data', testdata) # first check if use script is true - if (testdata_doc.use_script == 1): + if (testdata_doc.create_using == 'Sql Script'): # if Yes run the script frappe.db.sql(testdata_doc.insert_script, auto_commit=1) - elif (testdata_doc.use_function == 1): + elif (testdata_doc.create_using == 'Function'): return self.create_testdata_function(testdata, run_name) else: testdata_doc_test_record_name = frappe.db.get_value( 'Test Run Log', {'test_run_name': run_name, 'test_data': testdata}, 'test_record') if (testdata_doc_test_record_name): - created_doc_earlier = frappe.get_doc( + new_doc = frappe.get_doc( testdata_doc.doctype_name, testdata_doc_test_record_name) - return created_doc_earlier - - # start creating the insert statement - new_doc = frappe.get_doc( - {"doctype": testdata_doc.doctype_name}) - fields = frappe.get_meta(testdata_doc.doctype_name).fields - declared_fields = frappe.get_list('Testdatafield', filters={ - 'parent': testdata_doc.name}) - # for each field - for field in fields: - # check if the field values are in provided.. use it - field_doc = field - flag_field = False - - for declared_field in declared_fields: - declared_field_doc = frappe.get_doc( - 'Testdatafield', declared_field['name']) - current_fieldname = declared_field_doc.docfield_fieldname - if (declared_field_doc.docfield_fieldname == "docstatus"): - if (declared_field_doc.docfield_value is None): - declared_field_doc.docfield_value = 0 - new_doc.set(declared_field_doc.docfield_fieldname, int( - declared_field_doc.docfield_value)) - elif(declared_field_doc.docfield_fieldname == field_doc.fieldname): - flag_field = True - if (declared_field_doc.is_default): - # ignore - pass - elif (field_doc.fieldtype == "Table"): - # if it is table then user will have to add multiple rows for multiple records. - child_testdata_doc = frappe.get_doc( - 'Test Data', declared_field_doc.linkfield_name) - if (child_testdata_doc.doctype_type == "Transaction"): - create_test_run_log( - run_name, child_testdata_doc.name, None) - # each test data field will link to one record. create a new record - child_doc = self.create_testdata( - declared_field_doc.linkfield_name, run_name) - if child_doc: - create_test_run_log( - run_name, child_testdata_doc.name, child_doc.name) + # return created_doc_earlier + else: + # start creating the insert statement + new_doc = frappe.get_doc( + {"doctype": testdata_doc.doctype_name}) + fields = frappe.get_meta(testdata_doc.doctype_name).fields + declared_fields = frappe.get_list('Testdatafield', filters={ + 'parent': testdata_doc.name}) + # for each field + for field in fields: + # check if the field values are in provided.. use it + field_doc = field + flag_field = False + + for declared_field in declared_fields: + declared_field_doc = frappe.get_doc( + 'Testdatafield', declared_field['name']) + current_fieldname = declared_field_doc.docfield_fieldname + if (declared_field_doc.docfield_fieldname == "docstatus"): + if (declared_field_doc.docfield_value is None): + declared_field_doc.docfield_value = 0 + new_doc.set(declared_field_doc.docfield_fieldname, int( + declared_field_doc.docfield_value)) + elif(declared_field_doc.docfield_fieldname == field_doc.fieldname): + flag_field = True + if (declared_field_doc.is_default): + # ignore + pass + elif (field_doc.fieldtype in ["Table", "Table MultiSelect"]): + # if it is table then user will have to add multiple rows for multiple records. + child_testdata_doc = frappe.get_doc( + 'Test Data', declared_field_doc.linkfield_name) + if (child_testdata_doc.doctype_type == "Transaction"): + create_test_run_log( + run_name, child_testdata_doc.name, None) + # each test data field will link to one record. create a new record + child_doc, error_message = self.create_testdata( + declared_field_doc.linkfield_name, run_name) + if child_doc: + child_doc.parent_doc = new_doc + create_test_run_log( + run_name, child_testdata_doc.name, child_doc.name) + + child_doc.parentfield = field_doc.fieldname + if not new_doc.get(field_doc.fieldname): + new_doc.set(field_doc.fieldname, []) + + new_doc.get(field_doc.fieldname).append( + child_doc) + else: + frappe.throw( + f'Child Doc is None. Test Data of Child {declared_field_doc.linkfield_name}. Test Data of Parent {testdata}') + + # link parent to this record + elif ("Link" in field_doc.fieldtype and declared_field_doc.docfield_code_value == "Fixed Value"): + new_doc.set(field_doc.fieldname, + declared_field_doc.docfield_value) + elif ("Link" in field_doc.fieldtype): + child_testdata_doc = frappe.get_doc( + 'Test Data', declared_field_doc.linkfield_name) + if (child_testdata_doc.doctype_type == "Transaction"): + create_test_run_log( + run_name, child_testdata_doc.name, None) + + child_doc, error_message = self.create_testdata( + declared_field_doc.linkfield_name, run_name) + try: + if(not child_doc.name): + child_doc.save() + except frappe.DuplicateEntryError as e: + child_doc = resolve_duplicate_entry_error( + e, child_testdata_doc, run_name) + except frappe.UniqueValidationError as e: + child_doc = resolve_unique_validation_error( + e, child_testdata_doc, run_name) - child_doc.parentfield = field_doc.fieldname - new_doc.get(field_doc.fieldname).append( - child_doc) - else: - frappe.throw( - f'Child Doc is None. Test Data of Child {declared_field_doc.linkfield_name}. Test Data of Parent {testdata}') - - # link parent to this record - elif ("Link" in field_doc.fieldtype and declared_field_doc.docfield_code_value == "Fixed Value"): - new_doc.set(field_doc.fieldname, - declared_field_doc.docfield_value) - elif ("Link" in field_doc.fieldtype): - child_testdata_doc = frappe.get_doc( - 'Test Data', declared_field_doc.linkfield_name) - if (child_testdata_doc.doctype_type == "Transaction"): create_test_run_log( - run_name, child_testdata_doc.name, None) - - child_doc = self.create_testdata( - declared_field_doc.linkfield_name, run_name) - try: - child_doc.save() - except frappe.DuplicateEntryError as e: - child_doc = resolve_duplicate_entry_error( - e, child_testdata_doc, run_name) - except frappe.UniqueValidationError as e: - child_doc = resolve_unique_validation_error( - e, child_testdata_doc, run_name) - - create_test_run_log( - run_name, child_testdata_doc.name, child_doc.name) - new_doc.set(field_doc.fieldname, - child_doc.name) - - elif (declared_field_doc.docfield_code_value == "Code"): - if declared_field_doc.docfield_code and not declared_field_doc.linkfield_name: - new_doc.set(declared_field_doc.docfield_fieldname, eval( - str(declared_field_doc.docfield_code))) - if not declared_field_doc.docfield_code and declared_field_doc.linkfield_name: - value = frappe.db.get_value( - 'Test Run Log', {'test_run_name': run_name, 'test_data': declared_field_doc.linkfield_name}, 'test_record') - new_doc.set( - declared_field_doc.docfield_fieldname, value) - else: - if field_doc.fieldtype in ['Currency', 'Float', 'Percent']: - new_doc.set(declared_field_doc.docfield_fieldname, float( - declared_field_doc.docfield_value)) - elif field_doc.fieldtype == 'Int': - new_doc.set(declared_field_doc.docfield_fieldname, int( - declared_field_doc.docfield_value)) + run_name, child_testdata_doc.name, child_doc.name) + new_doc.set(field_doc.fieldname, + child_doc.get(declared_field_doc.linkfield_key or 'name')) + + elif (declared_field_doc.docfield_code_value == "Code"): + if declared_field_doc.docfield_code and not declared_field_doc.linkfield_name: + new_doc.set(declared_field_doc.docfield_fieldname, eval( + str(declared_field_doc.docfield_code))) + if not declared_field_doc.docfield_code and declared_field_doc.linkfield_name: + value = frappe.db.get_value( + 'Test Run Log', {'test_run_name': run_name, 'test_data': declared_field_doc.linkfield_name}, 'test_record') + new_doc.set( + declared_field_doc.docfield_fieldname, value) else: - new_doc.set(declared_field_doc.docfield_fieldname, str( - declared_field_doc.docfield_value)) - - # self.assign_random_value( - # flag_field, field_doc, new_doc, declared_field_doc) - - return new_doc + if field_doc.fieldtype in ['Currency', 'Float', 'Percent']: + new_doc.set(declared_field_doc.docfield_fieldname, float( + declared_field_doc.docfield_value)) + elif field_doc.fieldtype == 'Int': + new_doc.set(declared_field_doc.docfield_fieldname, int( + declared_field_doc.docfield_value)) + else: + new_doc.set(declared_field_doc.docfield_fieldname, str( + declared_field_doc.docfield_value)) + + # self.assign_random_value( + # flag_field, field_doc, new_doc, declared_field_doc) + + # return new_doc except Exception as e: + error_message = str(error_message) frappe.log_error(frappe.get_traceback( ), (f'barista-TestDataGenerator-{testdata}-DocTypeField-[{current_fieldname}]-'+str(e))[:error_log_title_len]) + return new_doc, error_message def assign_random_value(self, flag_field, field_doc, new_doc, declared_field_doc): if(flag_field == False and not field_doc.fetch_from): @@ -230,7 +243,7 @@ def assign_random_value(self, flag_field, field_doc, new_doc, declared_field_doc value = "Frappe@12345" elif (field_doc.fieldtype == "Percent"): value = round(random.uniform(0, 100), 2) - elif ("Link" in field_doc.fieldtype or field_doc.fieldtype == "Table"): + elif ("Link" in field_doc.fieldtype or field_doc.fieldtype in ["Table", "Table MultiSelect"]): # it looks like table or link field is not declared by user... test data generation failed.. pass elif("Attach" in field_doc.fieldtype): @@ -242,6 +255,7 @@ def assign_random_value(self, flag_field, field_doc, new_doc, declared_field_doc def create_testdata_function(self, testdata, run_name): generated_doc = None + error_message = '' try: args = [] kwargs = {} @@ -250,13 +264,24 @@ def create_testdata_function(self, testdata, run_name): testdata_doc = frappe.get_doc('Test Data', testdata) method = testdata_doc.function_name + print("\033[0;33;93m >>> Executing Function --",method) + if frappe.db.get_value('Test Run Log',{'test_data':testdata,'test_run_name':run_name},'test_record'): + create_test_run_log(run_name,testdata,frappe.db.get_value('Test Run Log',{'test_data':testdata,'test_run_name':run_name},'test_record')) + return frappe.get_doc(testdata_doc.doctype_name,frappe.db.get_value('Test Run Log',{'test_data':testdata,'test_run_name':run_name},'test_record')), error_message for param in testdata_doc.function_parameters: key = param.parameter - if param.value and param.value.strip()[0] in ['{', '[']: + + if param.value and param.value.strip()[0] in ['{', '['] and '{{' not in param.value and param.type == "json": + value = eval(param.value) + elif param.value and '{{' in param.value: + value = self.resolve_jinja( + param.value, param.test_data, run_name) + elif param.value and param.type == 'eval': value = eval(param.value) else: value = param.value + kwargs[key] = value if param.test_data: test_record_name = frappe.db.get_value( @@ -267,8 +292,11 @@ def create_testdata_function(self, testdata, run_name): test_record_doc = frappe.get_doc( test_record_doctype, test_record_name) if param.is_object: - kwargs[key] = test_record_doc.as_dict() - else: + if param.object_type == 'dict': + kwargs[key] = test_record_doc.as_dict() + elif param.object_type == 'json': + kwargs[key] = test_record_doc.as_json() + elif param.field and not param.value: kwargs[key] = test_record_doc.get( param.field) @@ -286,28 +314,81 @@ def create_testdata_function(self, testdata, run_name): if testdata_doc.eval_function_result: test_record_to_save = eval(testdata_doc.eval_function_result) else: - if result: + if result and type(result) != str: test_record_to_save = result.get('name') + if len(testdata_doc.conditions): + filter_dct = {} + for c in testdata_doc.conditions: + filter_dct[c.reference_field] = c.value + if c.test_data: + test_record_name = frappe.db.get_value( + 'Test Run Log', {'test_run_name': run_name, 'test_data': c.test_data}, 'test_record') + test_record_doctype = frappe.db.get_value( + 'Test Data', c.test_data, 'doctype_name') + test_record_doc = frappe.get_doc( + test_record_doctype, test_record_name) + if c.field: + filter_dct[c.reference_field] = test_record_doc.get( + c.field) + else: + filter_dct[c.reference_field] = test_record_doc.get( + 'name') + + records = frappe.get_all( + c.reference_doctype, filters=filter_dct, fields=["*"]) + if len(records): + if not c.field_to_refer: + c.field_to_refer = 'name' + if records[0].get(c.field_to_refer): + test_record_to_save = records[0].get( + c.field_to_refer) + create_test_run_log(run_name, testdata, test_record_to_save) generated_doc = frappe.get_doc( testdata_doc.doctype_name, test_record_to_save) except Exception as e: + error_message = str(e) + print("\033[0;31;91m >>>> Execution of function failed\n Error occurred :", str(e)) frappe.log_error(frappe.get_traceback( ), (f'barista-TestDataGenerator-{testdata}-Function-[{method}]-'+str(e))[:error_log_title_len]) - return generated_doc + return generated_doc, error_message + + def resolve_jinja(self, jinja, testdata, run_name): + resolved_jinja = '' + try: + context_dict = {"doc": {}} + if testdata: + test_record_name = frappe.db.get_value( + 'Test Run Log', {'test_run_name': run_name, 'test_data': testdata}, 'test_record') + test_record_doctype = frappe.db.get_value( + 'Test Data', testdata, 'doctype_name') + context = frappe.get_doc( + test_record_doctype, test_record_name).as_dict() + context_dict = {"doc": context} + + try: + jinja, context_dict = self.fetch_context(jinja, context_dict, run_name) + resolved_jinja = render_template( + jinja, context_dict) + except Exception as e: + print(f"{red} >>>> Error in Json Parameter\n ", str(e)) + except Exception as e: + frappe.log_error(frappe.get_traceback( + ), (f'barista-TestDataGenerator-{testdata}-Jinja-'+str(e))[:error_log_title_len]) + return resolved_jinja def set_record_name_child_table(self, created_doc, parent_doc, create_new_child=False, run_name=None): parenttype = None if created_doc: parenttype = created_doc.doctype new_record_fields = frappe.db.sql( - f"select fieldname from `tabDocField` where parent = '{parenttype}'and fieldtype = 'Table'", as_dict=True) + f"select fieldname from `tabDocField` where parent = '{parenttype}'and fieldtype in ('Table','Table MultiSelect')", as_dict=True) for new_record_field in new_record_fields: child_records = created_doc.get(new_record_field.fieldname) test_data_field_values = frappe.db.sql('select linkfield_name from `tabTestdatafield` where docfield_fieldname = "' + - new_record_field.fieldname + '" and parent = "' + parent_doc.name + '" order by idx', as_dict=True) + new_record_field.fieldname + '" and parent = "' + parent_doc.name + '" order by idx', as_dict=True) child_record_index = 0 for test_data_field_value in test_data_field_values: if child_record_index < len(child_records): @@ -323,7 +404,19 @@ def set_record_name_child_table(self, created_doc, parent_doc, create_new_child= create_test_run_log( run_name, child_test_data_doc.name, child_records[child_record_index].name) child_record_index += 1 - + + def fetch_context(self, value, context_dict, run_name): + """Fetches the Context For all TestData""" + for data in list(set(re.findall('{{([^.]*)',value))): + if frappe.db.exists("Test Data", data): + i = 1 + test_record_name = frappe.db.get_value('Test Run Log', {'test_run_name': run_name, 'test_data': data}, ['test_data_doctype','test_record']) + if test_record_name: + key = f"doc{i}" + context_dict[key] = frappe.get_doc(test_record_name[0], test_record_name[1]).as_dict() + value = value.replace(data, key) + + return (value, context_dict) def create_test_run_log(run_name, test_data, test_record): try: diff --git a/barista/barista/doctype/test_data_condition/__init__.py b/barista/barista/doctype/test_data_condition/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/barista/barista/doctype/test_data_condition/test_data_condition.json b/barista/barista/doctype/test_data_condition/test_data_condition.json new file mode 100644 index 0000000..7c99d78 --- /dev/null +++ b/barista/barista/doctype/test_data_condition/test_data_condition.json @@ -0,0 +1,278 @@ +{ + "allow_copy": 0, + "allow_events_in_timeline": 0, + "allow_guest_to_view": 0, + "allow_import": 0, + "allow_rename": 0, + "beta": 0, + "creation": "2020-05-19 18:29:54.915730", + "custom": 0, + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "reference_doctype", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Reference DocType", + "length": 0, + "no_copy": 0, + "options": "DocType", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "depends_on": "eval: (doc.test_data === '' || doc.test_data === undefined)", + "fetch_if_empty": 0, + "fieldname": "value", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Value", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "field_to_refer", + "fieldtype": "Select", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "Field To Refer", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "column_break_3", + "fieldtype": "Column Break", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "reference_field", + "fieldtype": "Select", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Reference Field", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 1, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "depends_on": "eval: (doc.value === undefined || doc.value === '')", + "fetch_if_empty": 0, + "fieldname": "test_data", + "fieldtype": "Link", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Test Data", + "length": 0, + "no_copy": 0, + "options": "Test Data", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "depends_on": "eval: (doc.value === undefined || doc.value === '')", + "fetch_if_empty": 0, + "fieldname": "field", + "fieldtype": "Select", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "Test Data Field", + "length": 0, + "no_copy": 0, + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0 + } + ], + "has_web_view": 0, + "hide_heading": 0, + "hide_toolbar": 0, + "idx": 0, + "image_view": 0, + "in_create": 0, + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "max_attachments": 0, + "modified": "2020-05-20 20:28:02.588944", + "modified_by": "Administrator", + "module": "Barista", + "name": "Test Data Condition", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "show_name_in_global_search": 0, + "sort_field": "modified", + "sort_order": "DESC", + "track_changes": 1, + "track_seen": 0, + "track_views": 0 +} \ No newline at end of file diff --git a/barista/barista/doctype/test_data_condition/test_data_condition.py b/barista/barista/doctype/test_data_condition/test_data_condition.py new file mode 100644 index 0000000..cd8e3b7 --- /dev/null +++ b/barista/barista/doctype/test_data_condition/test_data_condition.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2020, elasticrun and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class TestDataCondition(Document): + pass diff --git a/barista/barista/doctype/test_run_log/test_run_log.json b/barista/barista/doctype/test_run_log/test_run_log.json index 20bfc8b..8a49d3e 100644 --- a/barista/barista/doctype/test_run_log/test_run_log.json +++ b/barista/barista/doctype/test_run_log/test_run_log.json @@ -1,300 +1,97 @@ { - "allow_copy": 0, - "allow_events_in_timeline": 0, - "allow_guest_to_view": 0, - "allow_import": 0, - "allow_rename": 0, + "actions": [], "autoname": "TRL-.#####", - "beta": 0, "creation": "2020-05-07 13:07:25.657233", - "custom": 0, - "docstatus": 0, "doctype": "DocType", - "document_type": "", "editable_grid": 1, "engine": "InnoDB", + "field_order": [ + "test_run_name", + "section_break_2", + "test_data", + "test_data_status", + "column_break_3", + "test_data_doctype", + "test_record" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, "fieldname": "test_run_name", "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 1, "label": "Test Run Name", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "reqd": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, "fieldname": "section_break_2", - "fieldtype": "Section Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Section Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, "fieldname": "test_data", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 1, "label": "Test Data", - "length": 0, - "no_copy": 0, "options": "Test Data", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "reqd": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_from": "", - "fetch_if_empty": 0, "fieldname": "test_data_status", "fieldtype": "Select", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, "in_standard_filter": 1, "label": "Test Data Status", - "length": 0, - "no_copy": 0, "options": "Created\nFailed", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 1, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "reqd": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, "fieldname": "column_break_3", - "fieldtype": "Column Break", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "fieldtype": "Column Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, "fetch_from": "test_data.doctype_name", "fetch_if_empty": 1, "fieldname": "test_data_doctype", "fieldtype": "Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, "in_list_view": 1, "in_standard_filter": 1, "label": "Test Data DocType", - "length": 0, - "no_copy": 0, "options": "DocType", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_from": "", - "fetch_if_empty": 0, "fieldname": "test_record", - "fieldtype": "Dynamic Link", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, + "fieldtype": "Data", "in_list_view": 1, "in_standard_filter": 1, "label": "Test Record", - "length": 0, - "no_copy": 0, - "options": "test_data_doctype", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 1, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "read_only": 1 } ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2020-05-14 15:11:31.128590", + "links": [], + "modified": "2022-06-27 19:49:05.549553", "modified_by": "Administrator", "module": "Barista", "name": "Test Run Log", - "name_case": "", "owner": "Administrator", "permissions": [ { - "amend": 0, - "cancel": 0, "create": 1, "delete": 1, "email": 1, "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, "print": 1, "read": 1, "report": 1, "role": "System Manager", - "set_user_permissions": 0, "share": 1, - "submit": 0, "write": 1 } ], - "quick_entry": 0, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 + "track_changes": 1 } \ No newline at end of file diff --git a/barista/barista/doctype/test_suite/run_test.py b/barista/barista/doctype/test_suite/run_test.py index 95622ca..a7137c1 100644 --- a/barista/barista/doctype/test_suite/run_test.py +++ b/barista/barista/doctype/test_suite/run_test.py @@ -17,17 +17,21 @@ import os from pathlib import Path from coverage.numbits import register_sqlite_functions - +from tabulate import tabulate error_log_title_len = 1000 +yellow = '\033[0;33;93m' +green = '\033[0;32;92m' +red = '\033[0;31;91m' +white = '\033[0;37m' class RunTest(): # Run all the suites for the given app def run_complete_suite(self, app_name, suites=[], run_name=None): start_time = time.time() - alter_error_log() - print("\033[0;33;93m************ Running all test cases for App - " + + # alter_error_log() + print(f"{yellow}************ Running all Test Cases for App - " + app_name + " *************\n\n") if len(suites) == 0: suites = frappe.get_all("Test Suite", filters={ @@ -39,21 +43,23 @@ def run_complete_suite(self, app_name, suites=[], run_name=None): suites = suite_name run_name_path = run_name.replace(' ', '__').replace('-', '_') - barista_app_path = f"{frappe.get_app_path('barista')}/public/test-coverage/{run_name_path}/" + # barista_app_path = f"{frappe.get_app_path('barista')}/public/test-coverage/{run_name_path}/" + barista_app_path = f'{frappe.get_site_path()}/public/files/test-coverage/{run_name_path}/' + data_file_path = str(f"{barista_app_path}{app_name}.coverage") shutil.rmtree(barista_app_path, ignore_errors=True) generatorObj = TestDataGenerator() objCoverage = coverage.Coverage(source=[frappe.get_app_path( - app_name)], data_file=data_file_path, omit=['*test_*'], config_file=False) + app_name)], data_file=None, omit=['*test_*'], config_file=False) objCoverage.erase() objCoverage.start() total_suites = len(suites) suite_srno = 0 for suite in suites: suite_srno += 1 - print("\033[0;32;92m************ Suite - " + + print(f"{green}************ Suite - " + suite.get('name') + " *************\n\n") try: generatorObj.create_pretest_data(suite.get('name'), run_name) @@ -69,12 +75,13 @@ def run_complete_suite(self, app_name, suites=[], run_name=None): except Exception as e: frappe.log_error(frappe.get_traceback( ), ('barista-Suite Execution Failed-'+suite.get('name')+'-'+str(e))[:error_log_title_len]) + print( - "\033[0;31;91mAn Error occurred which will cause false test case result in the suite - " + str(suite.get('name'))) - print("\033[0;31;91m*************ERROR****************") + f"{red}An Error occurred which will cause false test case result in the suite - " + str(suite.get('name'))) + print(f"{red}*************ERROR****************") print( - "\033[0;31;91m The error encountered is - " + str(e) + "\n") - print("\033[0;31;91m*************ERROR****************") + f"{red}The error encountered is - " + str(e) + "\n") + print(f"{red}*************ERROR****************") objCoverage.stop() objCoverage.save() @@ -84,7 +91,7 @@ def run_complete_suite(self, app_name, suites=[], run_name=None): directory=barista_app_path, skip_empty=True, omit=['*test_*']) print( - f"\033[0;33;93m************ Execution ends. Verify coverage at - /assets/barista/test-coverage/{run_name_path}/index.html") + f"{green}************ Execution ends. Verify coverage at - /files/test-coverage/{run_name_path}/index.html") end_time = round(time.time() - start_time, 2) time_uom = 'seconds' @@ -197,6 +204,10 @@ def read_file(file_path): def alter_error_log(): + # barista.barista.doctype.test_suite.run_test.alter_error_log + print(f'{yellow}Barista is altering the table `tabError Log`') + frappe.db.sql("""ALTER TABLE `tabError Log` DROP INDEX IF EXISTS `index_on_method`;""") + # frappe.db.sql('TRUNCATE `tabError Log`;') frappe.db.sql("""UPDATE `tabDocField` SET fieldtype="Small Text" WHERE parent= "Error Log" @@ -204,60 +215,71 @@ def alter_error_log(): AND label= "Title";""", auto_commit=1) frappe.db.sql( """ALTER TABLE `tabError Log` CHANGE `method` `method` text;""", auto_commit=1) - if frappe.conf.get('developer_mode') == 1: + + print(f'{yellow}Barista is turning ON Developer Mode{white}') + from frappe.installer import update_site_config + update_site_config('developer_mode', 1) + + if bool(frappe.conf.get('developer_mode')): frappe.get_doc('DocType', 'Error Log').save(True) # bench execute barista.barista.doctype.test_suite.run_test.fix_series def fix_series(): - print('Previous Series-', frappe.db.sql( - """select * from `tabSeries` where name in ('TestData-','TestCase-')""", as_dict=1)) + bs = '' + if frappe.conf.get('barista_series'): + bs = f"{frappe.conf.get('barista_series')}-" + + previous_series = frappe.db.sql( + f"""select * from `tabSeries` where name in ('{bs}TestData-','{bs}TestCase-')""", as_dict=1) + + test_data_lst = [0] + for test_data in frappe.get_all('Test Data'): + test_data_lst.append(int(test_data['name'].split('-')[-1])) + + max_test_data_series = max(test_data_lst) + + # max_test_data_series = frappe.db.sql_list( + # f"""select ifnull(max(name),'{bs}TestData-0') from `tabTest Data`;""") + # if len(max_test_data_series): + # max_test_data_series = int(max_test_data_series[0].split('-')[-1]) test_data_series = frappe.db.sql_list( - """select * from `tabSeries` where name='TestData-';""") - max_test_data_series = frappe.db.sql_list( - """select ifnull(max(name),'TestData-0') from `tabTest Data`;""") - if len(max_test_data_series): - max_test_data_series = int(max_test_data_series[0].split('-')[1]) + f"""select * from `tabSeries` where name='{bs}TestData-';""") + if len(test_data_series) == 0: frappe.db.sql( - f"""Insert into `tabSeries` (name,current) values ('TestData-',{max_test_data_series});""", auto_commit=1) + f"""Insert into `tabSeries` (name,current) values ('{bs}TestData-',{max_test_data_series});""", auto_commit=1) else: frappe.db.sql( - f"""update `tabSeries` set current={max_test_data_series} where name="TestData-";""", auto_commit=1) + f"""update `tabSeries` set current={max_test_data_series} where name="{bs}TestData-";""", auto_commit=1) + + test_case_lst = [0] + for test_case in frappe.get_all('Test Case'): + test_case_lst.append(int(test_case['name'].split('-')[-1])) + max_test_case_series = max(test_case_lst) + + # max_test_case_series = frappe.db.sql_list( + # f"""select ifnull(max(name),'{bs}TestCase-0') from `tabTest Case`;""") + # if len(max_test_case_series): + # max_test_case_series = int(max_test_case_series[0].split('-')[-1]) test_case_series = frappe.db.sql_list( - """select * from `tabSeries` where name='TestCase-';""") - max_test_case_series = frappe.db.sql_list( - """select ifnull(max(name),'TestCase-0') from `tabTest Case`;""") - if len(max_test_case_series): - max_test_case_series = int(max_test_case_series[0].split('-')[1]) + f"""select * from `tabSeries` where name='{bs}TestCase-';""") + if len(test_case_series) == 0: frappe.db.sql( - f"""Insert into `tabSeries` (name,current) values ('TestCase-',{max_test_case_series});""", auto_commit=1) + f"""Insert into `tabSeries` (name,current) values ('{bs}TestCase-',{max_test_case_series});""", auto_commit=1) else: frappe.db.sql( - f"""update `tabSeries` set current={max_test_case_series} where name="TestCase-";""", auto_commit=1) - - print('Current Series-', frappe.db.sql( - """select * from `tabSeries` where name in ('TestData-','TestCase-')""", as_dict=1)) - - -# bench execute barista.barista.doctype.test_suite.run_test.run_test --kwargs "{'app_name':'velocityduos','suites':[]}" -def run_test(app_name, suites=[]): - print(''' - This commmand is deprecated. - ''', end='') - print(''' - Please use bench execute barista.run --kwargs "{'app_name':'velocityduos','suites':[],'reset_testdata':0,'clear_testresult':0,'run_name':'Release 1'}" - ''', end='') - print(''' - app_name is mandatory while all other parameters are optional - ''', end='') - print(''' - You can use bench execute barista.run --kwargs "{'app_name':'velocityduos'}" - ''') - return - # RunTest().run_complete_suite(app_name, suites) + f"""update `tabSeries` set current={max_test_case_series} where name="{bs}TestCase-";""", auto_commit=1) + + current_series = frappe.db.sql( + f"""select * from `tabSeries` where name in ('{bs}TestData-','{bs}TestCase-')""", as_dict=1) + + print(f'{yellow}Barista is fixing Test Data and Test Case series:\nPrevious Series-\n', end='') + print(tabulate(previous_series, headers="keys", tablefmt="fancy_grid")) + print(f'{yellow}Current Series-\n', end='') + print(tabulate(current_series, headers="keys", tablefmt="fancy_grid")) def fix_assertion_type_status(): @@ -300,6 +322,11 @@ def resolve_run_name(run_name='Pass-1'): f'Provided Run Name [{run_name}] already exists. Please provide other Run Name.') sys.exit(1) else: + frappe.get_doc({ + "run_name":run_name, + "doctype": "Run Name", + }).db_insert() + frappe.db.commit() return run_name @@ -315,34 +342,44 @@ def get_test_coverage(): # bench execute barista.barista.doctype.test_suite.run_test.get_test_coverage test_coverage_lst = [] try: - barista_app_path = frappe.get_app_path('barista') - test_coverage_path = f"{barista_app_path}/public/test-coverage" - - paths = sorted(Path(test_coverage_path).iterdir(), - key=os.path.getmtime) - - for path in paths: - if path.is_dir(): - path_parts = str(path).split('/') - d = path_parts.pop() - run_name = d.replace('__', ' ').replace('_', '-') - test_coverage_lst.append({ - 'coverage_path': f"/assets/barista/test-coverage/{d}/index.html", - 'test_run_name': run_name - }) + # barista_app_path = frappe.get_app_path('barista') + barista_app_path = frappe.get_site_path() + test_coverage_path = f"{barista_app_path}/public/files/test-coverage" + + process_paths(test_coverage_path, test_coverage_lst) + except OSError as o: + frappe.log_error(frappe.get_traceback(), + 'barista-get_test_coverage-OSError') + test_coverage_path = './site1.docker/public/files/test-coverage' + process_paths(test_coverage_path, test_coverage_lst) except Exception as e: - print('error-', e) frappe.log_error(frappe.get_traceback(), 'barista-get_test_coverage') return test_coverage_lst +def process_paths(directory_path, test_coverage_lst): + paths = sorted(Path(directory_path).iterdir(), + key=os.path.getmtime) + + for path in paths: + if path.is_dir(): + path_parts = str(path).split('/') + d = path_parts.pop() + run_name = d.replace('__', ' ').replace('_', '-') + test_coverage_lst.append({ + 'coverage_path': f"/files/test-coverage/{d}/index.html", + 'test_run_name': run_name + }) + + @frappe.whitelist() def delete_test_coverage(run_name): # barista.barista.doctype.test_suite.run_test.delete_test_coverage try: run_name_path = run_name.replace(' ', '__').replace('-', '_') - barista_app_path = f"{frappe.get_app_path('barista')}/public/test-coverage/{run_name_path}/" + # barista_app_path = f"{frappe.get_app_path('barista')}/public/test-coverage/{run_name_path}/" + barista_app_path = f'{frappe.get_site_path()}/public/files/test-coverage/{run_name_path}/' shutil.rmtree(barista_app_path, ignore_errors=True) frappe.db.sql(''' @@ -354,3 +391,13 @@ def delete_test_coverage(run_name): except Exception: frappe.log_error(frappe.get_traceback(), 'barista-delete_test_coverage') + + +def fix_create_using(): + frappe.db.sql( + "update `tabTest Data` set create_using='Data' where create_using is null or create_using=''", auto_commit=1) + + +def fix_object_type(): + frappe.db.sql( + "update `tabFunction Parameter` set object_type='json' where object_type is null or object_type=''", auto_commit=1) diff --git a/barista/barista/doctype/test_suite/test_suite.js b/barista/barista/doctype/test_suite/test_suite.js index dae514b..389f744 100644 --- a/barista/barista/doctype/test_suite/test_suite.js +++ b/barista/barista/doctype/test_suite/test_suite.js @@ -2,7 +2,70 @@ // For license information, please see license.txt frappe.ui.form.on('Test Suite', { - refresh: function(frm) { + refresh: function(frm) { + // debugger + cur_frm.doc.testcase.forEach((test_case) => { + // Get the test-case row, in which 'info' button is to be added: + let fieldDiv = $(`.frappe-control[data-fieldname='testcase']`); + console.log(fieldDiv); + // Check if there's a button already present: + // debugger + if (!fieldDiv.find(`.test_case-details-${test_case.idx}`).length){ + + // get the div at end of the row, and add a info-button-div: + let divToAppend = fieldDiv.find(`.grid-row[data-idx=${test_case.idx}]`); + let colToAppend = divToAppend.find(`.static-area`)[1] + let infoDiv = ` +
+ `; + let divPresent = fieldDiv.find( + `.fa.fa-info-circle.test_case-${test_case.idx}` + ); + + // Prepend the info-button-div: + if (!divPresent.length) { + divPresent = $(infoDiv).prependTo(colToAppend); + divPresent.removeClass(`test_case-${test_case.idx}`); + } - } + // Update the class name: + let cls = `test_case-details-${test_case.idx}`; + divPresent.addClass(`${cls}`); + + // click event listener + $(`.${cls}`) + .off("click") + .on("click", () => { + get_test_case_info(test_case.testcase) + frm.refresh() + }); + } + + }) + } }); + +// Function to fire API to get the test case info in form of HTML: +function get_test_case_info(test_case) { + frappe.call({ + method: "barista.barista.doctype.test_case.test_case.get_test_case_info", + args: { + "test_case": test_case, + }, + freeze: true, + freeze_message: "Getting Details", + callback: function(r, rt){ + console.log("get-test-case-info: ", r) + + // Show dialog box with the details: + var dialog = new frappe.ui.Dialog({ + title: __('Details of Test Case: '+ (test_case)), + fields: [], + + }); + dialog.show_message("
"+r.message+"
"); + dialog.show() + dialog.$wrapper.find('.modal-dialog').css({"width":"1000px","color":""}); + } + }); +} \ No newline at end of file diff --git a/barista/barista/doctype/test_suite/test_suite.json b/barista/barista/doctype/test_suite/test_suite.json index 3c85efb..a6eb8f6 100644 --- a/barista/barista/doctype/test_suite/test_suite.json +++ b/barista/barista/doctype/test_suite/test_suite.json @@ -1,198 +1,103 @@ { - "allow_copy": 0, - "allow_events_in_timeline": 0, - "allow_guest_to_view": 0, - "allow_import": 0, + "actions": [], "allow_rename": 1, - "autoname": "field:suite_name", - "beta": 0, "creation": "2019-12-19 11:49:55.460732", - "custom": 0, - "docstatus": 0, "doctype": "DocType", - "document_type": "", "editable_grid": 1, "engine": "InnoDB", + "field_order": [ + "suite_name", + "app_name", + "is_standard", + "column_break_1", + "workgroup", + "spoc", + "module", + "section_break_1", + "test_data", + "testcase" + ], "fields": [ { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, "fieldname": "suite_name", "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Suite Name", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, + "reqd": 1, "unique": 1 }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, "fieldname": "app_name", "fieldtype": "Data", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, - "label": "App Name", - "length": 0, - "no_copy": 0, - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "label": "App Name" + }, + { + "fieldname": "module", + "fieldtype": "Data", + "in_list_view": 1, + "label": "Module" + }, + { + "default": "No", + "fieldname": "is_standard", + "fieldtype": "Select", + "label": "Is Standard", + "options": "Yes\nNo" + }, + { + "fieldname": "column_break_1", + "fieldtype": "Column Break" + }, + { + "fieldname": "workgroup", + "fieldtype": "Link", + "label": "Module WorkGroup", + "options": "Workgroup" + }, + { + "fetch_from": "workgroup.workgroup_owner", + "fieldname": "spoc", + "fieldtype": "Data", + "label": "Module Owner" + }, + { + "fieldname": "section_break_1", + "fieldtype": "Section Break" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, "fieldname": "test_data", "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Test Data", - "length": 0, - "no_copy": 0, - "options": "Testdata Item", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Testdata Item" }, { - "allow_bulk_edit": 0, - "allow_in_quick_entry": 0, - "allow_on_submit": 0, - "bold": 0, - "collapsible": 0, - "columns": 0, - "fetch_if_empty": 0, "fieldname": "testcase", "fieldtype": "Table", - "hidden": 0, - "ignore_user_permissions": 0, - "ignore_xss_filter": 0, - "in_filter": 0, - "in_global_search": 0, - "in_list_view": 0, - "in_standard_filter": 0, "label": "Testcase", - "length": 0, - "no_copy": 0, - "options": "Testcase Item", - "permlevel": 0, - "precision": "", - "print_hide": 0, - "print_hide_if_no_value": 0, - "read_only": 0, - "remember_last_selected_value": 0, - "report_hide": 0, - "reqd": 0, - "search_index": 0, - "set_only_once": 0, - "translatable": 0, - "unique": 0 + "options": "Testcase Item" } ], - "has_web_view": 0, - "hide_heading": 0, - "hide_toolbar": 0, - "idx": 0, - "image_view": 0, - "in_create": 0, - "is_submittable": 0, - "issingle": 0, - "istable": 0, - "max_attachments": 0, - "modified": "2020-05-07 14:17:49.904989", + "links": [], + "modified": "2022-06-27 19:44:43.471953", "modified_by": "Administrator", "module": "Barista", "name": "Test Suite", - "name_case": "", "owner": "Administrator", "permissions": [ { - "amend": 0, - "cancel": 0, "create": 1, "delete": 1, "email": 1, "export": 1, - "if_owner": 0, - "import": 0, - "permlevel": 0, "print": 1, "read": 1, "report": 1, "role": "System Manager", - "set_user_permissions": 0, "share": 1, - "submit": 0, "write": 1 } ], - "quick_entry": 0, - "read_only": 0, - "read_only_onload": 0, - "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", - "track_changes": 1, - "track_seen": 0, - "track_views": 0 + "title_field": "suite_name", + "track_changes": 1 } \ No newline at end of file diff --git a/barista/barista/doctype/test_suite/test_suite.py b/barista/barista/doctype/test_suite/test_suite.py index 3979097..75b7a0a 100644 --- a/barista/barista/doctype/test_suite/test_suite.py +++ b/barista/barista/doctype/test_suite/test_suite.py @@ -9,8 +9,18 @@ import datetime import ast, json, requests, urllib3, re, math, difflib, base64, operator, copy, traceback, urllib, ssl, binascii, six, html.parser, os import bs4, sys, pymysql, html2text, warnings, markdown2, csv, calendar, unittest +from frappe.modules.export_file import export_to_files class TestSuite(Document): - pass + def autoname(self): + self.name = self.suite_name.replace(' ', '_').lower() + + def before_save(self): + if self.module: + self.module = self.module.strip().replace(' ','_').upper() + + def on_update(self): + if self.is_standard == "Yes" and frappe.local.conf.developer_mode and not frappe.flags.in_migrate: + export_to_files(record_list=[[self.doctype, self.name]], record_module="barista", create_init=True) diff --git a/barista/barista/doctype/testdatafield/testdatafield.json b/barista/barista/doctype/testdatafield/testdatafield.json index 9c3adda..d071a85 100644 --- a/barista/barista/doctype/testdatafield/testdatafield.json +++ b/barista/barista/doctype/testdatafield/testdatafield.json @@ -4,9 +4,13 @@ "allow_guest_to_view": 0, "allow_import": 0, "allow_rename": 0, + "app": "", + "autoname": "", "beta": 0, + "color": "", "creation": "2019-12-18 09:55:19.639158", "custom": 0, + "default_print_format": "", "docstatus": 0, "doctype": "DocType", "document_type": "", @@ -33,11 +37,14 @@ "label": "DocType Name", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "DocType", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 1, "remember_last_selected_value": 0, "report_hide": 0, @@ -45,7 +52,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -68,11 +76,14 @@ "label": "DocField Name", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -80,7 +91,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -103,10 +115,13 @@ "label": "Assign Random Value", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -114,7 +129,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -138,11 +154,14 @@ "label": "DocField Fixed Value or Code", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "\nFixed Value\nCode", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -150,7 +169,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -174,10 +194,13 @@ "label": "DocField Code", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -185,7 +208,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -207,13 +231,17 @@ "in_global_search": 0, "in_list_view": 0, "in_standard_filter": 0, + "label": "", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 1, "remember_last_selected_value": 0, "report_hide": 0, @@ -221,7 +249,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -244,10 +273,13 @@ "label": "DocField Value", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -255,7 +287,8 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" }, { "allow_bulk_edit": 0, @@ -278,11 +311,14 @@ "label": "Link Field", "length": 0, "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", "options": "Test Data", "permlevel": 0, "precision": "", "print_hide": 0, "print_hide_if_no_value": 0, + "print_width": "", "read_only": 0, "remember_last_selected_value": 0, "report_hide": 0, @@ -290,20 +326,62 @@ "search_index": 0, "set_only_once": 0, "translatable": 0, - "unique": 0 + "unique": 0, + "width": "" + }, + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "default": "name", + "fetch_if_empty": 0, + "fieldname": "linkfield_key", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 0, + "in_standard_filter": 0, + "label": "LinkField Key", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 0, + "width": "" } ], "has_web_view": 0, "hide_heading": 0, "hide_toolbar": 0, + "icon": "", "idx": 0, + "image_field": "", "image_view": 0, "in_create": 0, + "is_published_field": "", "is_submittable": 0, "issingle": 0, "istable": 1, "max_attachments": 0, - "modified": "2020-04-14 17:29:14.869061", + "modified": "2021-05-13 20:27:20.887948", "modified_by": "Administrator", "module": "Barista", "name": "Testdatafield", @@ -313,9 +391,14 @@ "quick_entry": 1, "read_only": 0, "read_only_onload": 0, + "restrict_to_domain": "", + "route": "", + "search_fields": "", "show_name_in_global_search": 0, "sort_field": "modified", "sort_order": "DESC", + "timeline_field": "", + "title_field": "", "track_changes": 1, "track_seen": 0, "track_views": 0 diff --git a/barista/barista/doctype/to_email_id/__init__.py b/barista/barista/doctype/to_email_id/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/barista/barista/doctype/to_email_id/to_email_id.json b/barista/barista/doctype/to_email_id/to_email_id.json new file mode 100644 index 0000000..7dce641 --- /dev/null +++ b/barista/barista/doctype/to_email_id/to_email_id.json @@ -0,0 +1,92 @@ +{ + "allow_copy": 0, + "allow_events_in_timeline": 0, + "allow_guest_to_view": 0, + "allow_import": 0, + "allow_rename": 0, + "app": "", + "autoname": "", + "beta": 0, + "color": "", + "creation": "2021-01-14 13:34:12.308074", + "custom": 0, + "default_print_format": "", + "docstatus": 0, + "doctype": "DocType", + "document_type": "", + "editable_grid": 1, + "engine": "InnoDB", + "fields": [ + { + "allow_bulk_edit": 0, + "allow_in_quick_entry": 0, + "allow_on_submit": 0, + "bold": 0, + "collapsible": 0, + "columns": 0, + "fetch_if_empty": 0, + "fieldname": "to_email_id", + "fieldtype": "Data", + "hidden": 0, + "ignore_user_permissions": 0, + "ignore_xss_filter": 0, + "in_filter": 0, + "in_global_search": 0, + "in_list_view": 1, + "in_standard_filter": 0, + "label": "To Email ID", + "length": 0, + "no_copy": 0, + "oldfieldname": "", + "oldfieldtype": "", + "permlevel": 0, + "precision": "", + "print_hide": 0, + "print_hide_if_no_value": 0, + "print_width": "", + "read_only": 0, + "remember_last_selected_value": 0, + "report_hide": 0, + "reqd": 0, + "search_index": 0, + "set_only_once": 0, + "translatable": 0, + "unique": 1, + "width": "" + } + ], + "has_web_view": 0, + "hide_heading": 0, + "hide_toolbar": 0, + "icon": "", + "idx": 0, + "image_field": "", + "image_view": 0, + "in_create": 0, + "is_published_field": "", + "is_submittable": 0, + "issingle": 0, + "istable": 1, + "max_attachments": 0, + "modified": "2021-02-23 16:19:11.353844", + "modified_by": "Administrator", + "module": "Barista", + "name": "To Email ID", + "name_case": "", + "owner": "Administrator", + "permissions": [], + "quick_entry": 1, + "read_only": 0, + "read_only_onload": 0, + "restrict_to_domain": "", + "route": "", + "search_fields": "", + "show_name_in_global_search": 0, + "sort_field": "modified", + "sort_order": "ASC", + "timeline_field": "", + "title_field": "", + "track_changes": 1, + "track_seen": 0, + "track_views": 0 +} \ No newline at end of file diff --git a/barista/barista/doctype/to_email_id/to_email_id.py b/barista/barista/doctype/to_email_id/to_email_id.py new file mode 100644 index 0000000..2d301f3 --- /dev/null +++ b/barista/barista/doctype/to_email_id/to_email_id.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright (c) 2021, elasticrun and contributors +# For license information, please see license.txt + +from __future__ import unicode_literals +import frappe +from frappe.model.document import Document + +class ToEmailID(Document): + pass diff --git a/barista/barista/doctype/workgroup/__init__.py b/barista/barista/doctype/workgroup/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/barista/barista/doctype/workgroup/test_workgroup.py b/barista/barista/doctype/workgroup/test_workgroup.py new file mode 100644 index 0000000..f5c8dac --- /dev/null +++ b/barista/barista/doctype/workgroup/test_workgroup.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, elasticrun and Contributors +# See license.txt + +# import frappe +import unittest + +class TestWorkgroup(unittest.TestCase): + pass diff --git a/barista/barista/doctype/workgroup/workgroup.js b/barista/barista/doctype/workgroup/workgroup.js new file mode 100644 index 0000000..ebd0ad4 --- /dev/null +++ b/barista/barista/doctype/workgroup/workgroup.js @@ -0,0 +1,8 @@ +// Copyright (c) 2022, elasticrun and contributors +// For license information, please see license.txt + +frappe.ui.form.on('Workgroup', { + // refresh: function(frm) { + + // } +}); diff --git a/barista/barista/doctype/workgroup/workgroup.json b/barista/barista/doctype/workgroup/workgroup.json new file mode 100644 index 0000000..d3d2969 --- /dev/null +++ b/barista/barista/doctype/workgroup/workgroup.json @@ -0,0 +1,49 @@ +{ + "actions": [], + "allow_rename": 1, + "autoname": "field:workgroup", + "creation": "2022-06-27 14:35:35.932188", + "doctype": "DocType", + "editable_grid": 1, + "engine": "InnoDB", + "field_order": [ + "workgroup", + "workgroup_owner" + ], + "fields": [ + { + "fieldname": "workgroup", + "fieldtype": "Data", + "label": "WorkGroup", + "unique": 1 + }, + { + "fieldname": "workgroup_owner", + "fieldtype": "Data", + "label": "WorkGroup Owner" + } + ], + "index_web_pages_for_search": 1, + "links": [], + "modified": "2022-06-27 19:42:58.804832", + "modified_by": "Administrator", + "module": "Barista", + "name": "Workgroup", + "owner": "Administrator", + "permissions": [ + { + "create": 1, + "delete": 1, + "email": 1, + "export": 1, + "print": 1, + "read": 1, + "report": 1, + "role": "System Manager", + "share": 1, + "write": 1 + } + ], + "sort_field": "modified", + "sort_order": "DESC" +} \ No newline at end of file diff --git a/barista/barista/doctype/workgroup/workgroup.py b/barista/barista/doctype/workgroup/workgroup.py new file mode 100644 index 0000000..f7c5bc3 --- /dev/null +++ b/barista/barista/doctype/workgroup/workgroup.py @@ -0,0 +1,8 @@ +# Copyright (c) 2022, elasticrun and contributors +# For license information, please see license.txt + +# import frappe +from frappe.model.document import Document + +class Workgroup(Document): + pass diff --git a/barista/barista/report/barista_error_statistics/__init__.py b/barista/barista/report/barista_error_statistics/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/barista/barista/report/error_statistics/error_statistics.json b/barista/barista/report/barista_error_statistics/barista_error_statistics.json similarity index 83% rename from barista/barista/report/error_statistics/error_statistics.json rename to barista/barista/report/barista_error_statistics/barista_error_statistics.json index 37c489a..5b7f746 100644 --- a/barista/barista/report/error_statistics/error_statistics.json +++ b/barista/barista/report/barista_error_statistics/barista_error_statistics.json @@ -8,15 +8,15 @@ "idx": 0, "is_standard": "Yes", "letter_head": "ElasticRun", - "modified": "2020-05-07 20:00:05.588666", + "modified": "2020-06-02 18:00:01.504873", "modified_by": "Administrator", "module": "Barista", - "name": "Error Statistics", + "name": "Barista Error Statistics", "owner": "Administrator", "prepared_report": 0, "query": "SELECT count(error) as 'Error Count',\n replace(METHOD, 'barista-', '') as 'Error:Text:1500'\nFROM `tabError Log`\nWHERE METHOD LIKE 'barista%%'\nGROUP BY error\nORDER BY METHOD;", "ref_doctype": "Error Log", - "report_name": "Error Statistics", + "report_name": "Barista Error Statistics", "report_type": "Query Report", "roles": [ { diff --git a/barista/barista/report/test_execution_statistics/test_execution_statistics.json b/barista/barista/report/test_execution_statistics/test_execution_statistics.json index 876ddb5..daebe5c 100644 --- a/barista/barista/report/test_execution_statistics/test_execution_statistics.json +++ b/barista/barista/report/test_execution_statistics/test_execution_statistics.json @@ -1,25 +1,30 @@ { "add_total_row": 1, + "columns": [], "creation": "2020-04-09 23:38:08.774486", "disable_prepared_report": 0, "disabled": 0, "docstatus": 0, "doctype": "Report", + "filters": [], "idx": 0, "is_standard": "Yes", - "javascript": "let apps = [];\nlet run_names = [];\ngetAppName();\ngetRunName();\nfrappe.query_reports[\"Test Execution Statistics\"] = {\n \"filters\": [{\n \"fieldname\": \"app_name\",\n \"label\": __(\"App\"),\n \"fieldtype\": \"Select\",\n \"default\": '',\n \"reqd\": 1,\n \"options\": apps\n },\n {\n \"fieldname\": \"run_name\",\n \"label\": __(\"Test Run Name\"),\n \"fieldtype\": \"Select\",\n \"default\": '',\n \"reqd\": 1,\n \"options\": run_names\n }\n ]\n}\n\nfunction getAppName() {\n apps = [];\n frappe.call({\n method: 'frappe.desk.reportview.get',\n args: {\n doctype: 'Module Def',\n fields: [\"`tabModule Def`.`app_name`\"],\n order_by: \"`tabModule Def`.`modified` desc\",\n start: 0,\n page_length: 2000,\n with_comment_count: true\n },\n freeze: true,\n freeze_message: 'Loading report please wait',\n async: false,\n callback: function (r) {\n if (!r.exc) {\n let all_apps = r.message.values;\n all_apps.forEach((a) => {\n let app_name = a[0];\n if (!apps.includes(app_name)) {\n apps.push(app_name);\n }\n });\n\n return apps;\n }\n }\n });\n}\n\nfunction getRunName() {\n run_names = [];\n frappe.call({\n type: 'GET',\n url: `${window.location.origin}/api/resource/Test Run Log?fields=[\"distinct test_run_name\"]&limit_page_length=9000`,\n freeze: true,\n freeze_message: 'Loading report please wait',\n async: false,\n callback: function (r) {\n if (!r.exc) {\n let all_runs = r.data;\n all_runs.forEach((a) => {\n let run_name = a['test_run_name'];\n if (!run_names.includes(run_name)) {\n run_names.push(run_name);\n }\n });\n\n return run_names;\n }\n }\n });\n}", - "letter_head": "ElasticRun", - "modified": "2020-05-14 09:37:39.360327", + "javascript": "let apps = [];\nlet run_names = [];\ngetAppName();\n// getRunName();\nfrappe.query_reports[\"Test Execution Statistics\"] = {\n \"filters\": [{\n \"fieldname\": \"app_name\",\n \"label\": __(\"App\"),\n \"fieldtype\": \"Select\",\n \"default\": '',\n \"reqd\": 1,\n \"options\": apps\n },\n {\n \"fieldname\": \"run_name\",\n \"label\": __(\"Test Run Name\"),\n \"fieldtype\": \"Link\",\n \"default\": '',\n \"options\": \"Run Name\",\n \"ignore_user_permissions\":1,\n \"reqd\": 1\n }\n ]\n}\n\nfunction getAppName() {\n apps = [];\n frappe.call({\n method: 'frappe.desk.reportview.get',\n args: {\n doctype: 'Module Def',\n fields: [\"`tabModule Def`.`app_name`\"],\n order_by: \"`tabModule Def`.`modified` desc\",\n start: 0,\n page_length: 2000,\n with_comment_count: true\n },\n freeze: true,\n freeze_message: 'Loading report please wait',\n async: false,\n callback: function (r) {\n if (!r.exc) {\n let all_apps = r.message.values;\n all_apps.forEach((a) => {\n let app_name = a[0];\n if (!apps.includes(app_name)) {\n apps.push(app_name);\n }\n });\n\n return apps;\n }\n }\n });\n}\n\nfunction getRunName() {\n run_names = [];\n frappe.call({\n type: 'GET',\n url: `${window.location.origin}/api/resource/Test Run Log?fields=[\"distinct test_run_name\"]&limit_page_length=9000`,\n freeze: true,\n freeze_message: 'Loading report please wait',\n async: false,\n callback: function (r) {\n if (!r.exc) {\n let all_runs = r.data;\n all_runs.forEach((a) => {\n let run_name = a['test_run_name'];\n if (!run_names.includes(run_name)) {\n run_names.push(run_name);\n }\n });\n\n return run_names;\n }\n }\n });\n}", + "letter_head": "", + "modified": "2022-06-27 16:17:55.367640", "modified_by": "Administrator", "module": "Barista", "name": "Test Execution Statistics", "owner": "Administrator", "prepared_report": 0, - "query": "SELECT tr.test_suite AS 'Test Suite:Link/Test Suite',\n dtr.total_tr AS 'Total Test Cases:Int',\n dtrp.passed_tr AS 'Passed Test Cases:Int',\n ifnull(dtrf.failed_tr,0) AS 'Failed Test Cases:Int',\n\t((dtrp.passed_tr/dtr.total_tr)*100) as 'Percentage Passed:Percent'\nFROM `tabTest Result` tr\nINNER JOIN `tabTest Suite` ts ON ts.name=tr.test_suite\nLEFT JOIN\n (SELECT count(trs.name) AS 'total_tr',\n trs.test_suite\n FROM `tabTest Result` trs where trs.test_run_name=%(run_name)s\n GROUP BY trs.test_suite) dtr ON dtr.test_suite=tr.test_suite\nLEFT JOIN\n (SELECT count(trp.name) AS 'passed_tr',\n trp.test_suite\n FROM `tabTest Result` trp\n WHERE trp.test_case_status='Passed' and trp.test_run_name=%(run_name)s\n GROUP BY trp.test_suite) dtrp ON dtrp.test_suite=tr.test_suite\nLEFT JOIN\n (SELECT count(trf.name) AS 'failed_tr',\n trf.test_suite\n FROM `tabTest Result` trf\n WHERE trf.test_case_status='Failed' and trf.test_run_name=%(run_name)s\n GROUP BY trf.test_suite) dtrf ON dtrf.test_suite=tr.test_suite\nWHERE ts.app_name=%(app_name)s and tr.test_run_name=%(run_name)s\nGROUP BY tr.test_suite\norder by ifnull(dtrf.failed_tr,0)", + "query": "SELECT tr.test_suite AS 'Test Suite:Link/Test Suite',\n ts.module AS 'Module:Data',\n dtr.total_tr AS 'Total Test Cases:Int',\n dtrp.passed_tr AS 'Passed Test Cases:Int',\n ifnull(dtrf.failed_tr,0) AS 'Failed Test Cases:Int',\n\t((dtrp.passed_tr/dtr.total_tr)*100) as 'Percentage Passed:Percent',\n ts.workgroup AS 'Work Group:Data',\n ts.spoc AS 'SPOC:Data'\nFROM `tabTest Result` tr\nINNER JOIN `tabTest Suite` ts ON ts.name=tr.test_suite\nLEFT JOIN\n (SELECT count(trs.name) AS 'total_tr',\n trs.test_suite\n FROM `tabTest Result` trs where trs.test_run_name=%(run_name)s\n GROUP BY trs.test_suite) dtr ON dtr.test_suite=tr.test_suite\nLEFT JOIN\n (SELECT count(trp.name) AS 'passed_tr',\n trp.test_suite\n FROM `tabTest Result` trp\n WHERE trp.test_case_status='Passed' and trp.test_run_name=%(run_name)s\n GROUP BY trp.test_suite) dtrp ON dtrp.test_suite=tr.test_suite\nLEFT JOIN\n (SELECT count(trf.name) AS 'failed_tr',\n trf.test_suite\n FROM `tabTest Result` trf\n WHERE trf.test_case_status='Failed' and trf.test_run_name=%(run_name)s\n GROUP BY trf.test_suite) dtrf ON dtrf.test_suite=tr.test_suite\nWHERE ts.app_name=%(app_name)s and tr.test_run_name=%(run_name)s\nGROUP BY tr.test_suite\norder by ifnull(dtrf.failed_tr,0)", "ref_doctype": "Test Result", "report_name": "Test Execution Statistics", "report_type": "Query Report", "roles": [ + { + "role": "System Manager" + }, { "role": "System Manager" } diff --git a/barista/commands.py b/barista/commands.py index f4b42bb..5468b35 100644 --- a/barista/commands.py +++ b/barista/commands.py @@ -9,17 +9,27 @@ @click.argument('app_name') @click.option('-r', '--run-name', default='Pass-1', help='Test Run Name for this execution run') @click.option('-s', '--suite', multiple=True, help='Test Suite name') +@click.option('-u', '--user', default='Administrator', help='Set user for execution') @pass_context -def run_barista(context, app_name, suite=[], run_name='Pass-1'): +def run_barista(context, app_name, suite=[], run_name='Pass-1',user='Administrator'): site = get_site(context) frappe.init(site=site) frappe.connect(site) - + frappe.set_user(user) run_name = resolve_run_name(run_name) print('Test Run Name - ', run_name) RunTest().run_complete_suite(app_name, list(suite), run_name) - + +@click.command('clear-error-log') +@pass_context +def clear_error_log(context): + site = get_site(context) + frappe.init(site=site) + frappe.connect(site) + frappe.db.sql('TRUNCATE `tabError Log`;',auto_commit=1) + print('`Error Log` cleared successfully') commands = [ - run_barista + run_barista, + clear_error_log, ] diff --git a/barista/config/desktop.py b/barista/config/desktop.py index b7864a9..6ac7b21 100644 --- a/barista/config/desktop.py +++ b/barista/config/desktop.py @@ -6,8 +6,8 @@ def get_data(): return [ { "module_name": "Barista", - "color": "grey", - "icon": "octicon octicon-file-directory", + "color": "blue", + "icon": "fa fa-flask", "type": "module", "label": _("Barista") } diff --git a/barista/hooks.py b/barista/hooks.py index 30222c4..7629c9f 100644 --- a/barista/hooks.py +++ b/barista/hooks.py @@ -90,7 +90,7 @@ # Scheduled Tasks # --------------- -# scheduler_events = { +scheduler_events = { # "all": [ # "barista.tasks.all" # ], @@ -106,7 +106,15 @@ # "monthly": [ # "barista.tasks.monthly" # ] -# } + "cron": { + "15 16 * * *": [ + "barista.barista.api.barista_trigger.barista_job" + ] + # "00 12 * * 3": [ + # "barista.barista.api.barista_trigger.barista_job" + # ] + } +} # Testing # ------- @@ -120,17 +128,25 @@ # "frappe.desk.doctype.event.event.get_events": "barista.event.get_events" # } fixtures = [ - "Test Data", - "Test Case", - "Test Suite", - # "Testcase Item", - # "Testdata Item", - # "Assertion", - # "Testdatafield" + {'doctype': "Test Data", 'filters': {'is_standard': 'No'}}, + {'doctype': "Test Case", 'filters': {'is_standard': 'No'}}, + {'doctype': "Test Suite", 'filters': {'is_standard': 'No'}} +] + +before_migrate = [ + 'barista.barista.doctype.test_suite.run_test.alter_error_log' ] after_migrate = [ 'barista.barista.doctype.test_suite.run_test.fix_series', 'barista.barista.doctype.test_suite.run_test.fix_assertion_type_status', 'barista.barista.doctype.test_suite.run_test.fix_testcase_type_status', + 'barista.barista.doctype.test_suite.run_test.fix_create_using', + 'barista.barista.doctype.test_suite.run_test.fix_object_type', +] + +standard_doctypes = [ + 'Test Case', + 'Test Data', + 'Test Suite' ] diff --git a/requirements.txt b/requirements.txt index 898a139..87be497 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,2 @@ -frappe -coverage==5.0.4 \ No newline at end of file +coverage==5.2.1 +tabulate