Skip to content

Commit

Permalink
Wrapping product creation in a create_version block so versions happe…
Browse files Browse the repository at this point in the history
…n like they should (#2073)
  • Loading branch information
jkachel authored Jan 26, 2024
1 parent d09bca6 commit c878b1a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 16 deletions.
20 changes: 11 additions & 9 deletions courses/views/v2/views_test.py
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
"""
Tests for courses api views v2
"""
import operator as op
import logging
import random

import pytest
from django.db import connection
from django.urls import reverse
from rest_framework import status
from django.db import connection
import logging

from courses.conftest import course_catalog_data
from courses.factories import DepartmentFactory
from courses.serializers.v2.programs import ProgramSerializer
from courses.models import Program
from courses.serializers.v2.courses import CourseWithCourseRunsSerializer
from courses.serializers.v2.departments import DepartmentWithCountSerializer
from courses.serializers.v2.programs import ProgramSerializer
from courses.views.test_utils import (
num_queries_from_programs,
num_queries_from_course,
num_queries_from_department,
num_queries_from_programs,
)
from courses.views.v2 import Pagination
from fixtures.common import raise_nplusone
from main.test_utils import assert_drf_json_equal, duplicate_queries_check

pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures("raise_nplusone")]
Expand Down Expand Up @@ -75,12 +73,16 @@ def test_get_departments(


@pytest.mark.parametrize("course_catalog_course_count", [100], indirect=True)
@pytest.mark.parametrize("course_catalog_program_count", [15], indirect=True)
@pytest.mark.parametrize("course_catalog_program_count", [12], indirect=True)
def test_get_programs(
user_drf_client, django_assert_max_num_queries, course_catalog_data
):
"""Test the view that handles requests for all Programs"""
_, programs, _ = course_catalog_data
course_catalog_data

# Fetch programs after running the fixture so they're in the right order
programs = Program.objects.order_by("title").prefetch_related("departments").all()

num_queries = num_queries_from_programs(programs, "v2")
with django_assert_max_num_queries(num_queries) as context:
resp = user_drf_client.get(reverse("v2:programs_api-list"))
Expand Down
17 changes: 10 additions & 7 deletions ecommerce/management/commands/create_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
Creates a product for the given courseware ID. This only supports course runs
for right now (since we don't really do program runs).
"""

import reversion
from django.contrib.contenttypes.models import ContentType
from django.core.management import BaseCommand

Expand Down Expand Up @@ -56,12 +58,13 @@ def handle(self, *args, **kwargs):
if "description" in kwargs and kwargs["description"] is not None:
description = kwargs["description"]

product = Product.objects.create(
object_id=courserun.id,
content_type=content_type,
price=kwargs["price"],
description=description,
is_active=kwargs["inactive"],
)
with reversion.create_revision():
product = Product.objects.create(
object_id=courserun.id,
content_type=content_type,
price=kwargs["price"],
description=description,
is_active=kwargs["inactive"],
)

self.stdout.write(f"Created product {product}.")

0 comments on commit c878b1a

Please sign in to comment.