def test_subscription_project_detail(auth_client): billing_type = BillingTypeFactory() project = ProjectFactory.create(billing_type=billing_type) PackageFactory.create_batch(2, billing_type=billing_type) url = reverse('subscription-project-detail', args=[project.id]) res = auth_client.get(url) assert res.status_code == HTTP_200_OK json = res.json() assert json['data']['id'] == str(project.id)
def test_subscription_package_list(auth_client): PackageFactory.create() url = reverse('subscription-package-list') res = auth_client.get(url) assert res.status_code == HTTP_200_OK json = res.json() assert len(json['data']) == 1
def test_subscription_project_detail(auth_client): billing_type = BillingTypeFactory() project = ProjectFactory.create(billing_type=billing_type, customer_visible=True) PackageFactory.create_batch(2, billing_type=billing_type) url = reverse("subscription-project-detail", args=[project.id]) res = auth_client.get(url) assert res.status_code == HTTP_200_OK json = res.json() assert json["data"]["id"] == str(project.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_subscription_package_filter_customer(auth_client): other_project = ProjectFactory.create() PackageFactory.create(billing_type=other_project.billing_type) my_project = ProjectFactory.create() package = PackageFactory.create(billing_type=my_project.billing_type) url = reverse('subscription-package-list') res = auth_client.get(url, data={'customer': my_project.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_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)