def test_update_budget(api_client, user, create_budget, models): budget = create_budget() api_client.force_login(user) response = api_client.patch("/v1/budgets/%s/" % budget.pk, data={ "name": "New Name" }) assert response.status_code == 200 budget.refresh_from_db() assert budget.name == "New Name" assert response.json() == { "id": budget.pk, "name": "New Name", "project_number": budget.project_number, "production_type": { "id": budget.production_type, "name": models.Budget.PRODUCTION_TYPES[budget.production_type] }, "created_at": "2020-01-01 00:00:00", "updated_at": "2020-01-01 00:00:00", "shoot_date": api_datetime_string(budget.shoot_date), "delivery_date": api_datetime_string(budget.delivery_date), "build_days": budget.build_days, "prelight_days": budget.prelight_days, "studio_shoot_days": budget.studio_shoot_days, "location_days": budget.location_days, "estimated": None, "variance": None, "actual": None, "created_by": user.pk, "type": "budget", "image": None, }
def test_reset_password(user, api_client, db): reset_uid = ResetUID.objects.create( token="token1234567", used=False, user=user, ) response = api_client.post("/v1/auth/reset-password/", data={ "token": reset_uid.token, "password": "******", "confirm": "TestUserPassword4321$", }) user.refresh_from_db() assert response.status_code == 201 assert response.json() == { 'id': user.pk, 'first_name': user.first_name, 'last_name': user.last_name, 'full_name': user.full_name, 'email': user.email, 'username': user.username, 'is_active': user.is_active, 'is_admin': user.is_admin, 'is_superuser': user.is_superuser, 'is_staff': user.is_staff, 'date_joined': api_datetime_string(user.date_joined), 'updated_at': api_datetime_string(user.updated_at), 'created_at': api_datetime_string(user.created_at), 'last_login': None, 'timezone': str(user.timezone), "profile_image": None, }
def test_get_budget_in_trash(api_client, user, create_budget, models): api_client.force_login(user) budget = create_budget(trash=True) response = api_client.get("/v1/budgets/trash/%s/" % budget.pk) assert response.status_code == 200 assert response.json() == { "id": budget.pk, "name": budget.name, "project_number": budget.project_number, "production_type": { "id": budget.production_type, "name": models.Budget.PRODUCTION_TYPES[budget.production_type] }, "created_at": "2020-01-01 00:00:00", "updated_at": "2020-01-01 00:00:00", "shoot_date": api_datetime_string(budget.shoot_date), "delivery_date": api_datetime_string(budget.delivery_date), "build_days": budget.build_days, "prelight_days": budget.prelight_days, "studio_shoot_days": budget.studio_shoot_days, "location_days": budget.location_days, "estimated": None, "variance": None, "actual": None, "created_by": user.pk, "type": "budget", "image": None, }
def test_create_budget(api_client, user, models): api_client.force_login(user) response = api_client.post("/v1/budgets/", data={ "name": "Test Name", "production_type": 1, }) assert response.status_code == 201 budget = models.Budget.objects.first() assert budget is not None assert response.json() == { "id": budget.pk, "name": budget.name, "project_number": budget.project_number, "production_type": { "id": 1, "name": models.Budget.PRODUCTION_TYPES[1], }, "created_at": "2020-01-01 00:00:00", "updated_at": "2020-01-01 00:00:00", "shoot_date": api_datetime_string(budget.shoot_date), "delivery_date": api_datetime_string(budget.delivery_date), "build_days": budget.build_days, "prelight_days": budget.prelight_days, "studio_shoot_days": budget.studio_shoot_days, "location_days": budget.location_days, "estimated": None, "variance": None, "actual": None, "created_by": user.pk, "type": "budget", "image": None, }
def test_validate_token(api_client, settings, user): api_client.force_login(user) token = GreenbudgetSlidingToken.for_user(user) api_client.cookies = SimpleCookie({ settings.JWT_TOKEN_COOKIE_NAME: str(token), }) response = api_client.post("/v1/jwt/validate/") assert response.status_code == 201 assert 'greenbudgetjwt' in response.cookies assert response.json() == { 'user': { 'id': user.pk, 'first_name': user.first_name, 'last_name': user.last_name, 'full_name': user.full_name, 'email': user.email, 'username': user.username, 'is_active': user.is_active, 'is_admin': user.is_admin, 'is_superuser': user.is_superuser, 'is_staff': user.is_staff, 'date_joined': api_datetime_string(user.date_joined), 'updated_at': api_datetime_string(user.updated_at), 'created_at': api_datetime_string(user.created_at), 'last_login': '******', 'timezone': str(user.timezone), "profile_image": None, } }
def test_duplicate_budget(api_client, user, create_budget, create_fringe, create_budget_account, create_budget_subaccount, models, create_budget_account_group, create_budget_subaccount_group): original = create_budget(created_by=user) fringes = [ create_fringe( budget=original, created_by=user, updated_by=user ), create_fringe( budget=original, created_by=user, updated_by=user ), ] account_group = create_budget_account_group(parent=original) accounts = [ create_budget_account( budget=original, created_by=user, updated_by=user, group=account_group, ), create_budget_account( budget=original, created_by=user, updated_by=user, group=account_group, ) ] subaccount_group = create_budget_subaccount_group(parent=accounts[0]) subaccounts = [ create_budget_subaccount( parent=accounts[0], budget=original, created_by=user, updated_by=user, group=subaccount_group ), create_budget_subaccount( parent=accounts[1], budget=original, created_by=user, updated_by=user ) ] child_subaccounts = [ create_budget_subaccount( parent=subaccounts[0], budget=original, created_by=user, updated_by=user ), create_budget_subaccount( parent=subaccounts[1], budget=original, created_by=user, updated_by=user ) ] api_client.force_login(user) response = api_client.post("/v1/budgets/%s/duplicate/" % original.pk) assert models.Budget.objects.count() == 2 budget = models.Budget.objects.all()[1] assert response.status_code == 201 assert response.json() == { "id": budget.pk, "name": original.name, "project_number": original.project_number, "production_type": { "id": original.production_type, "name": models.Budget.PRODUCTION_TYPES[original.production_type] }, "created_at": "2020-01-01 00:00:00", "updated_at": "2020-01-01 00:00:00", "shoot_date": api_datetime_string(original.shoot_date), "delivery_date": api_datetime_string(original.delivery_date), "build_days": original.build_days, "prelight_days": original.prelight_days, "studio_shoot_days": original.studio_shoot_days, "location_days": original.location_days, "estimated": None, "variance": None, "actual": None, "created_by": user.pk, "type": "budget", "image": None, } assert budget.name == original.name assert budget.accounts.count() == 2 assert budget.created_by == user assert budget.groups.count() == 1 budget_account_group = budget.groups.first() assert budget_account_group.name == account_group.name assert budget_account_group.color == account_group.color assert budget.fringes.count() == 2 first_fringe = budget.fringes.first() assert first_fringe.created_by == user assert first_fringe.updated_by == user assert first_fringe.name == fringes[0].name assert first_fringe.description == fringes[0].description assert first_fringe.cutoff == fringes[0].cutoff assert first_fringe.rate == fringes[0].rate assert first_fringe.unit == fringes[0].unit second_fringe = budget.fringes.all()[1] assert second_fringe.created_by == user assert second_fringe.updated_by == user assert second_fringe.name == fringes[1].name assert second_fringe.description == fringes[1].description assert second_fringe.cutoff == fringes[1].cutoff assert second_fringe.rate == fringes[1].rate assert second_fringe.unit == fringes[1].unit assert budget.accounts.count() == 2 first_account = budget.accounts.first() assert first_account.group == budget_account_group assert first_account.identifier == accounts[0].identifier assert first_account.description == accounts[0].description assert first_account.created_by == user assert first_account.updated_by == user assert first_account.subaccounts.count() == 1 assert first_account.groups.count() == 1 budget_subaccount_group = first_account.groups.first() assert budget_subaccount_group.name == subaccount_group.name assert budget_subaccount_group.color == subaccount_group.color first_account_subaccount = first_account.subaccounts.first() assert first_account_subaccount.group == budget_subaccount_group assert first_account_subaccount.created_by == user assert first_account_subaccount.updated_by == user assert first_account_subaccount.identifier == subaccounts[0].identifier assert first_account_subaccount.description == subaccounts[0].description assert first_account_subaccount.budget == budget # These values will be None because the subaccount has children. assert first_account_subaccount.name is None assert first_account_subaccount.rate is None assert first_account_subaccount.quantity is None assert first_account_subaccount.multiplier is None assert first_account_subaccount.unit is None assert first_account_subaccount.subaccounts.count() == 1 first_account_subaccount_subaccount = first_account_subaccount.subaccounts.first() # noqa assert first_account_subaccount_subaccount.created_by == user assert first_account_subaccount_subaccount.updated_by == user assert first_account_subaccount_subaccount.identifier == child_subaccounts[0].identifier # noqa assert first_account_subaccount_subaccount.description == child_subaccounts[0].description # noqa assert first_account_subaccount_subaccount.name == child_subaccounts[0].name # noqa assert first_account_subaccount_subaccount.rate == child_subaccounts[0].rate # noqa assert first_account_subaccount_subaccount.quantity == child_subaccounts[0].quantity # noqa assert first_account_subaccount_subaccount.multiplier == child_subaccounts[0].multiplier # noqa assert first_account_subaccount_subaccount.unit == child_subaccounts[0].unit # noqa assert first_account_subaccount_subaccount.budget == budget second_account = budget.accounts.all()[1] assert second_account.group == budget_account_group assert second_account.identifier == accounts[1].identifier assert second_account.description == accounts[1].description assert second_account.created_by == user assert second_account.updated_by == user assert second_account.subaccounts.count() == 1 second_account_subaccount = second_account.subaccounts.first() assert second_account_subaccount.created_by == user assert second_account_subaccount.updated_by == user assert second_account_subaccount.identifier == subaccounts[1].identifier assert second_account_subaccount.description == subaccounts[1].description assert second_account_subaccount.budget == budget # These values will be None because the subaccount has children. assert second_account_subaccount.name is None assert second_account_subaccount.rate is None assert second_account_subaccount.quantity is None assert second_account_subaccount.multiplier is None assert second_account_subaccount.unit is None assert second_account_subaccount.subaccounts.count() == 1 second_account_subaccount_subaccount = second_account_subaccount.subaccounts.first() # noqa assert second_account_subaccount_subaccount.created_by == user assert second_account_subaccount_subaccount.updated_by == user assert second_account_subaccount_subaccount.identifier == child_subaccounts[1].identifier # noqa assert second_account_subaccount_subaccount.description == child_subaccounts[1].description # noqa assert second_account_subaccount_subaccount.name == child_subaccounts[1].name # noqa assert second_account_subaccount_subaccount.rate == child_subaccounts[1].rate # noqa assert second_account_subaccount_subaccount.quantity == child_subaccounts[1].quantity # noqa assert second_account_subaccount_subaccount.multiplier == child_subaccounts[1].multiplier # noqa assert second_account_subaccount_subaccount.unit == child_subaccounts[1].unit # noqa assert second_account_subaccount_subaccount.budget == budget
def serialize_value(value): if type(value) is datetime.datetime: value = api_datetime_string(value) return json.dumps(value)