def test_customer_list_not_archived(auth_client): CustomerFactory.create(archived=True) customer = CustomerFactory.create(archived=False) url = reverse("customer-list") response = auth_client.get(url, data={"archived": 0}) assert response.status_code == status.HTTP_200_OK json = response.json() assert len(json["data"]) == 1 assert json["data"][0]["id"] == str(customer.id)
def test_customer_list_not_archived(auth_client): CustomerFactory.create(archived=True) customer = CustomerFactory.create(archived=False) url = reverse('customer-list') response = auth_client.get(url, data={'archived': 0}) assert response.status_code == status.HTTP_200_OK json = response.json() assert len(json['data']) == 1 assert json['data'][0]['id'] == str(customer.id)
def test_work_report_multiple_projects(auth_client, django_assert_num_queries): NUM_PROJECTS = 2 user = auth_client.user customer = CustomerFactory.create(name="Customer") report_date = date(2017, 8, 17) for i in range(NUM_PROJECTS): project = ProjectFactory.create(customer=customer, name="Project{0}".format(i)) task = TaskFactory.create(project=project) ReportFactory.create_batch(10, user=user, task=task, date=report_date) url = reverse("work-report-list") with django_assert_num_queries(3): res = auth_client.get(url, data={"user": auth_client.user.id, "verified": 0}) assert res.status_code == status.HTTP_200_OK assert "20170901-WorkReports.zip" in (res["Content-Disposition"]) content = io.BytesIO(res.content) with ZipFile(content, "r") as zipfile: for i in range(NUM_PROJECTS): ods_content = zipfile.read( "1708-20170901-Customer-Project{0}.ods".format(i) ) doc = ezodf.opendoc(io.BytesIO(ods_content)) table = doc.sheets[0] assert table["C5"].value == "2017-08-17" assert table["C6"].value == "2017-08-17"
def test_work_report_multiple_projects(auth_client, django_assert_num_queries): NUM_PROJECTS = 2 user = auth_client.user customer = CustomerFactory.create(name='Customer') report_date = date(2017, 8, 17) for i in range(NUM_PROJECTS): project = ProjectFactory.create( customer=customer, name='Project{0}'.format(i) ) task = TaskFactory.create(project=project) ReportFactory.create_batch(10, user=user, task=task, date=report_date) url = reverse('work-report-list') with django_assert_num_queries(4): res = auth_client.get(url, data={ 'user': auth_client.user.id, 'verified': 0 }) assert res.status_code == HTTP_200_OK assert '20170901-WorkReports.zip' in ( res['Content-Disposition'] ) content = io.BytesIO(res.content) with ZipFile(content, 'r') as zipfile: for i in range(NUM_PROJECTS): ods_content = zipfile.read( '1708-20170901-Customer-Project{0}.ods'.format(i) ) doc = ezodf.opendoc(io.BytesIO(ods_content)) table = doc.sheets[0] assert table['C5'].value == '2017-08-17' assert table['C6'].value == '2017-08-17'
def test_work_report_single_project(auth_client, django_assert_num_queries): user = auth_client.user # spaces should be replaced with underscore customer = CustomerFactory.create(name='Customer Name') # slashes should be dropped from file name project = ProjectFactory.create(customer=customer, name='Project/') task = TaskFactory.create(project=project) ReportFactory.create_batch( 10, user=user, verified_by=user, task=task, date=date(2017, 8, 17) ) url = reverse('work-report-list') with django_assert_num_queries(4): res = auth_client.get(url, data={ 'user': auth_client.user.id, 'from_date': '2017-08-01', 'to_date': '2017-08-31', 'verified': 1 }) assert res.status_code == HTTP_200_OK assert '1708-20170901-Customer_Name-Project.ods' in ( res['Content-Disposition'] ) content = io.BytesIO(res.content) doc = ezodf.opendoc(content) table = doc.sheets[0] assert table['C5'].value == '2017-08-01' assert table['C6'].value == '2017-08-31' assert table['C9'].value == 'Test User' assert table['C10'].value == 'Test User'
def test_work_report_single_project(auth_client, django_assert_num_queries): user = auth_client.user # spaces should be replaced with underscore customer = CustomerFactory.create(name="Customer Name") # slashes should be dropped from file name project = ProjectFactory.create(customer=customer, name="Project/") task = TaskFactory.create(project=project) ReportFactory.create_batch(10, user=user, verified_by=user, task=task, date=date(2017, 8, 17)) url = reverse("work-report-list") with django_assert_num_queries(3): res = auth_client.get( url, data={ "user": auth_client.user.id, "from_date": "2017-08-01", "to_date": "2017-08-31", "verified": 1, }, ) assert res.status_code == status.HTTP_200_OK assert "1708-20170901-Customer_Name-Project.ods" in ( res["Content-Disposition"]) content = io.BytesIO(res.content) doc = ezodf.opendoc(content) table = doc.sheets[0] assert table["C5"].value == "2017-08-01" assert table["C6"].value == "2017-08-31" assert table["C9"].value == "Test User" assert table["C10"].value == "Test User"
def test_customer_delete(auth_client): customer = CustomerFactory.create() url = reverse("customer-detail", args=[customer.id]) response = auth_client.delete(url) assert response.status_code == status.HTTP_405_METHOD_NOT_ALLOWED
def test_customer_detail(auth_client): customer = CustomerFactory.create() url = reverse("customer-detail", args=[customer.id]) response = auth_client.get(url) assert response.status_code == status.HTTP_200_OK
def test_generate_work_report_name(db, customer_name, project_name, expected): test_date = date(2017, 8, 18) view = WorkReportViewSet() # spaces should be replaced with underscore customer = CustomerFactory.create(name=customer_name) # slashes should be dropped from file name project = ProjectFactory.create(customer=customer, name=project_name) name = view._generate_workreport_name(test_date, test_date, project) assert name == expected
def test_subscription_package_filter_customer(auth_client): customer = CustomerFactory.create() billing_type = BillingTypeFactory.create() package = PackageFactory.create(billing_type=billing_type) ProjectFactory.create_batch(2, billing_type=billing_type, customer=customer) url = reverse("subscription-package-list") res = auth_client.get(url, data={"customer": customer.id}) assert res.status_code == HTTP_200_OK json = res.json() assert len(json["data"]) == 1 assert json["data"][0]["id"] == str(package.id)
def test_subscription_project_list(auth_client): customer = CustomerFactory.create() billing_type = BillingTypeFactory() project = ProjectFactory.create(billing_type=billing_type, customer=customer, customer_visible=True) PackageFactory.create_batch(2, billing_type=billing_type) # create spent hours task = TaskFactory.create(project=project) TaskFactory.create(project=project) ReportFactory.create(task=task, duration=timedelta(hours=2)) ReportFactory.create(task=task, duration=timedelta(hours=3)) # not billable reports should not be included in spent hours ReportFactory.create(not_billable=True, task=task, duration=timedelta(hours=4)) # project of same customer but without customer_visible set # should not appear ProjectFactory.create(customer=customer) # create purchased time OrderFactory.create(project=project, acknowledged=True, duration=timedelta(hours=2)) OrderFactory.create(project=project, acknowledged=True, duration=timedelta(hours=4)) # report on different project should not be included in spent time ReportFactory.create(duration=timedelta(hours=2)) # not acknowledged order should not be included in purchased time OrderFactory.create(project=project, duration=timedelta(hours=2)) url = reverse('subscription-project-list') res = auth_client.get(url, data={ 'customer': customer.id, 'ordering': 'id' }) assert res.status_code == HTTP_200_OK json = res.json() assert len(json['data']) == 1 assert json['data'][0]['id'] == str(project.id) attrs = json['data'][0]['attributes'] assert attrs['spent-time'] == '05:00:00' assert attrs['purchased-time'] == '06:00:00'
def test_work_report_count( auth_client, settings, settings_count, given_count, expected_status ): user = auth_client.user customer = CustomerFactory.create(name="Customer") report_date = date(2017, 8, 17) settings.WORK_REPORTS_EXPORT_MAX_COUNT = settings_count project = ProjectFactory.create(customer=customer) task = TaskFactory.create(project=project) ReportFactory.create_batch(given_count, user=user, task=task, date=report_date) url = reverse("work-report-list") res = auth_client.get(url, data={"user": auth_client.user.id, "verified": 0}) assert res.status_code == expected_status