Ejemplo n.º 1
0
    def test_weekly_dashboard_chart(self):
        insert_test_records()

        if frappe.db.exists('Dashboard Chart', 'Test Weekly Dashboard Chart'):
            frappe.delete_doc('Dashboard Chart', 'Test Weekly Dashboard Chart')

        frappe.get_doc(
            dict(doctype='Dashboard Chart',
                 chart_name='Test Weekly Dashboard Chart',
                 chart_type='Sum',
                 document_type='Communication',
                 based_on='communication_date',
                 value_based_on='rating',
                 timespan='Select Date Range',
                 time_interval='Weekly',
                 from_date=datetime(2018, 12, 30),
                 to_date=datetime(2019, 1, 15),
                 filters_json='[]',
                 timeseries=1)).insert()

        result = get(chart_name='Test Weekly Dashboard Chart', refresh=1)

        self.assertEqual(
            result.get('datasets')[0].get('values'), [50.0, 300.0, 800.0, 0.0])
        self.assertEqual(result.get('labels'),
                         ['30-12-18', '06-01-19', '13-01-19', '20-01-19'])

        frappe.db.rollback()
Ejemplo n.º 2
0
    def test_empty_dashboard_chart(self):
        if frappe.db.exists('Dashboard Chart', 'Test Empty Dashboard Chart'):
            frappe.delete_doc('Dashboard Chart', 'Test Empty Dashboard Chart')

        frappe.db.sql('delete from `tabError Log`')

        frappe.get_doc(
            dict(doctype='Dashboard Chart',
                 chart_name='Test Empty Dashboard Chart',
                 chart_type='Count',
                 document_type='Error Log',
                 based_on='creation',
                 timespan='Last Year',
                 time_interval='Monthly',
                 filters_json='[]',
                 timeseries=1)).insert()

        cur_date = datetime.now() - relativedelta(years=1)

        result = get(chart_name='Test Empty Dashboard Chart', refresh=1)

        for idx in range(13):
            month = get_last_day(cur_date)
            month = formatdate(month.strftime('%Y-%m-%d'))
            self.assertEqual(result.get('labels')[idx], get_period(month))
            cur_date += relativedelta(months=1)

        frappe.db.rollback()
Ejemplo n.º 3
0
    def test_dashboard_chart(self):
        if frappe.db.exists('Dashboard Chart', 'Test Dashboard Chart'):
            frappe.delete_doc('Dashboard Chart', 'Test Dashboard Chart')

        frappe.get_doc(
            dict(doctype='Dashboard Chart',
                 chart_name='Test Dashboard Chart',
                 chart_type='Count',
                 document_type='DocType',
                 based_on='creation',
                 timespan='Last Year',
                 time_interval='Monthly',
                 filters_json='{}',
                 timeseries=1)).insert()

        cur_date = datetime.now() - relativedelta(years=1)

        result = get(chart_name='Test Dashboard Chart', refresh=1)
        for idx in range(13):
            month = datetime(
                int(cur_date.year), int(cur_date.strftime('%m')),
                int(calendar.monthrange(cur_date.year, cur_date.month)[1]))
            month = formatdate(month.strftime('%Y-%m-%d'), 'yyyy-mm-dd')
            self.assertEqual(result.get('labels')[idx], month)
            cur_date += relativedelta(months=1)

        # self.assertEqual(result.get('datasets')[0].get('values')[:-1],
        # 	[44, 28, 8, 11, 2, 6, 18, 6, 4, 5, 15, 13])

        frappe.db.rollback()
Ejemplo n.º 4
0
    def test_group_by_chart_type(self):
        if frappe.db.exists('Dashboard Chart',
                            'Test Group By Dashboard Chart'):
            frappe.delete_doc('Dashboard Chart',
                              'Test Group By Dashboard Chart')

        frappe.get_doc({"doctype": "ToDo", "description": "test"}).insert()

        frappe.get_doc(
            dict(
                doctype='Dashboard Chart',
                chart_name='Test Group By Dashboard Chart',
                chart_type='Group By',
                document_type='ToDo',
                group_by_based_on='status',
                filters_json='[]',
            )).insert()

        result = get(chart_name='Test Group By Dashboard Chart', refresh=1)
        todo_status_count = frappe.db.count(
            'ToDo', {'status': result.get('labels')[0]})

        self.assertEqual(
            result.get('datasets')[0].get('values')[0], todo_status_count)

        frappe.db.rollback()
Ejemplo n.º 5
0
    def test_avg_dashboard_chart(self):
        insert_test_records()

        if frappe.db.exists("Dashboard Chart", "Test Average Dashboard Chart"):
            frappe.delete_doc("Dashboard Chart",
                              "Test Average Dashboard Chart")

        frappe.get_doc(
            dict(
                doctype="Dashboard Chart",
                chart_name="Test Average Dashboard Chart",
                chart_type="Average",
                document_type="Communication",
                based_on="communication_date",
                value_based_on="rating",
                timespan="Select Date Range",
                time_interval="Weekly",
                from_date=datetime(2018, 12, 30),
                to_date=datetime(2019, 1, 15),
                filters_json="[]",
                timeseries=1,
            )).insert()

        with patch.object(frappe.utils.data,
                          "get_first_day_of_the_week",
                          return_value="Monday"):
            result = get(chart_name="Test Average Dashboard Chart", refresh=1)
            self.assertEqual(result.get("labels"),
                             ["30-12-18", "06-01-19", "13-01-19", "20-01-19"])
            self.assertEqual(
                result.get("datasets")[0].get("values"),
                [50.0, 150.0, 266.6666666666667, 0.0])

        frappe.db.rollback()
Ejemplo n.º 6
0
    def test_empty_dashboard_chart(self):
        if frappe.db.exists("Dashboard Chart", "Test Empty Dashboard Chart"):
            frappe.delete_doc("Dashboard Chart", "Test Empty Dashboard Chart")

        frappe.db.sql("delete from `tabError Log`")

        frappe.get_doc(
            dict(
                doctype="Dashboard Chart",
                chart_name="Test Empty Dashboard Chart",
                chart_type="Count",
                document_type="Error Log",
                based_on="creation",
                timespan="Last Year",
                time_interval="Monthly",
                filters_json="[]",
                timeseries=1,
            )).insert()

        cur_date = datetime.now() - relativedelta(years=1)

        result = get(chart_name="Test Empty Dashboard Chart", refresh=1)

        for idx in range(13):
            month = get_last_day(cur_date)
            month = formatdate(month.strftime("%Y-%m-%d"))
            self.assertEqual(result.get("labels")[idx], get_period(month))
            cur_date += relativedelta(months=1)

        frappe.db.rollback()
Ejemplo n.º 7
0
    def test_group_by_chart_type(self):
        if frappe.db.exists("Dashboard Chart",
                            "Test Group By Dashboard Chart"):
            frappe.delete_doc("Dashboard Chart",
                              "Test Group By Dashboard Chart")

        frappe.get_doc({"doctype": "ToDo", "description": "test"}).insert()

        frappe.get_doc(
            dict(
                doctype="Dashboard Chart",
                chart_name="Test Group By Dashboard Chart",
                chart_type="Group By",
                document_type="ToDo",
                group_by_based_on="status",
                filters_json="[]",
            )).insert()

        result = get(chart_name="Test Group By Dashboard Chart", refresh=1)
        todo_status_count = frappe.db.count(
            "ToDo", {"status": result.get("labels")[0]})

        self.assertEqual(
            result.get("datasets")[0].get("values")[0], todo_status_count)

        frappe.db.rollback()
Ejemplo n.º 8
0
    def test_daily_dashboard_chart(self):
        insert_test_records()

        if frappe.db.exists("Dashboard Chart", "Test Daily Dashboard Chart"):
            frappe.delete_doc("Dashboard Chart", "Test Daily Dashboard Chart")

        frappe.get_doc(
            dict(
                doctype="Dashboard Chart",
                chart_name="Test Daily Dashboard Chart",
                chart_type="Sum",
                document_type="Communication",
                based_on="communication_date",
                value_based_on="rating",
                timespan="Select Date Range",
                time_interval="Daily",
                from_date=datetime(2019, 1, 6),
                to_date=datetime(2019, 1, 11),
                filters_json="[]",
                timeseries=1,
            )).insert()

        result = get(chart_name="Test Daily Dashboard Chart", refresh=1)

        self.assertEqual(
            result.get("datasets")[0].get("values"),
            [200.0, 400.0, 300.0, 0.0, 100.0, 0.0])
        self.assertEqual(result.get("labels"), [
            "06-01-19", "07-01-19", "08-01-19", "09-01-19", "10-01-19",
            "11-01-19"
        ])

        frappe.db.rollback()
Ejemplo n.º 9
0
    def test_empty_dashboard_chart(self):
        if frappe.db.exists('Dashboard Chart', 'Test Empty Dashboard Chart'):
            frappe.delete_doc('Dashboard Chart', 'Test Empty Dashboard Chart')

        frappe.db.sql('delete from `tabError Log`')

        chart = dict(doctype='Dashboard Chart',
                     name='Test Empty Dashboard Chart',
                     chart_type='Count',
                     document_type='Error Log',
                     based_on='creation',
                     timespan='Last Year',
                     time_interval='Monthly',
                     filters_json='{}',
                     timeseries=1)

        cur_date = datetime.now() - relativedelta(years=1)

        result = get(chart=chart, refresh=1)
        for idx in range(13):
            month = datetime(
                int(cur_date.year), int(cur_date.strftime('%m')),
                int(calendar.monthrange(cur_date.year, cur_date.month)[1]))
            month = formatdate(month.strftime('%Y-%m-%d'))
            self.assertEqual(result.get('labels')[idx], month)
            cur_date += relativedelta(months=1)

        frappe.db.rollback()
Ejemplo n.º 10
0
	def test_chart_wih_one_value(self):
		if frappe.db.exists('Dashboard Chart', 'Test Empty Dashboard Chart 2'):
			frappe.delete_doc('Dashboard Chart', 'Test Empty Dashboard Chart 2')

		frappe.db.sql('delete from `tabError Log`')

		# create one data point
		frappe.get_doc(dict(doctype = 'Error Log', creation = '2018-06-01 00:00:00')).insert()

		frappe.get_doc(dict(
			doctype = 'Dashboard Chart',
			chart_name = 'Test Empty Dashboard Chart 2',
			chart_type = 'Count',
			document_type = 'Error Log',
			based_on = 'creation',
			timespan = 'Last Year',
			time_interval = 'Monthly',
			filters_json = '{}',
			timeseries = 1
		)).insert()

		cur_date = datetime.now() - relativedelta(years=1)

		result = get(chart_name ='Test Empty Dashboard Chart 2', refresh = 1)
		for idx in range(13):
			month = str(cur_date.year) + '-' + str(cur_date.strftime('%m')) + '-' + str(calendar.monthrange(cur_date.year, cur_date.month)[1])
			self.assertEqual(result.get('labels')[idx], month)
			cur_date += relativedelta(months=1)

		# only 1 data point with value
		self.assertEqual(result.get('datasets')[0].get('values')[2], 0)

		frappe.db.rollback()
Ejemplo n.º 11
0
	def test_dashboard_chart(self):
		if frappe.db.exists('Dashboard Chart', 'Test Dashboard Chart'):
			frappe.delete_doc('Dashboard Chart', 'Test Dashboard Chart')

		frappe.get_doc(dict(
			doctype = 'Dashboard Chart',
			chart_name = 'Test Dashboard Chart',
			chart_type = 'Count',
			document_type = 'DocType',
			based_on = 'creation',
			timespan = 'Last Year',
			time_interval = 'Monthly',
			filters_json = '{}',
			timeseries = 1
		)).insert()

		cur_date = datetime.now() - relativedelta(years=1)

		result = get(chart_name='Test Dashboard Chart', refresh=1)
		self.assertEqual(result.get('labels')[0], formatdate(cur_date.strftime('%Y-%m-%d')))

		if formatdate(cur_date.strftime('%Y-%m-%d')) == formatdate(get_last_day(cur_date).strftime('%Y-%m-%d')):
			cur_date += relativedelta(months=1)

		for idx in range(1, 13):
			month = get_last_day(cur_date)
			month = formatdate(month.strftime('%Y-%m-%d'))
			self.assertEqual(result.get('labels')[idx], month)
			cur_date += relativedelta(months=1)

		frappe.db.rollback()
Ejemplo n.º 12
0
	def test_daily_dashboard_chart(self):
		insert_test_records()

		if frappe.db.exists('Dashboard Chart', 'Test Daily Dashboard Chart'):
			frappe.delete_doc('Dashboard Chart', 'Test Daily Dashboard Chart')

		frappe.get_doc(dict(
			doctype = 'Dashboard Chart',
			chart_name = 'Test Daily Dashboard Chart',
			chart_type = 'Sum',
			document_type = 'Communication',
			based_on = 'communication_date',
			value_based_on = 'rating',
			timespan = 'Select Date Range',
			time_interval = 'Daily',
			from_date = datetime(2019, 1, 6),
			to_date = datetime(2019, 1, 11),
			filters_json = '[]',
			timeseries = 1
		)).insert()

		result = get(chart_name ='Test Daily Dashboard Chart', refresh = 1)

		self.assertEqual(result.get('datasets')[0].get('values'), [200.0, 400.0, 300.0, 0.0, 100.0, 0.0])
		self.assertEqual(
			result.get('labels'),
			[formatdate('2019-01-06'), formatdate('2019-01-07'), formatdate('2019-01-08'),\
			formatdate('2019-01-09'), formatdate('2019-01-10'), formatdate('2019-01-11')]
		)

		frappe.db.rollback()
Ejemplo n.º 13
0
    def test_chart_wih_one_value(self):
        if frappe.db.exists('Dashboard Chart', 'Test Empty Dashboard Chart 2'):
            frappe.delete_doc('Dashboard Chart',
                              'Test Empty Dashboard Chart 2')

        frappe.db.delete("Error Log")

        # create one data point
        frappe.get_doc(
            dict(doctype='Error Log',
                 creation='2018-06-01 00:00:00')).insert()

        frappe.get_doc(
            dict(doctype='Dashboard Chart',
                 chart_name='Test Empty Dashboard Chart 2',
                 chart_type='Count',
                 document_type='Error Log',
                 based_on='creation',
                 timespan='Last Year',
                 time_interval='Monthly',
                 filters_json='[]',
                 timeseries=1)).insert()

        cur_date = datetime.now() - relativedelta(years=1)

        result = get(chart_name='Test Empty Dashboard Chart 2', refresh=1)

        for idx in range(13):
            month = get_last_day(cur_date)
            month = formatdate(month.strftime('%Y-%m-%d'))
            self.assertEqual(result.get('labels')[idx], get_period(month))
            cur_date += relativedelta(months=1)

        # only 1 data point with value
        self.assertEqual(result.get('datasets')[0].get('values')[2], 0)

        frappe.db.rollback()