Skip to content

Commit

Permalink
Merge branch 'django-oscar:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
snake-soft authored Dec 31, 2023
2 parents 28dd9ee + c76343a commit 7b5f37f
Show file tree
Hide file tree
Showing 11 changed files with 130 additions and 12 deletions.
8 changes: 6 additions & 2 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
version: 2

build:
os: "ubuntu-22.04"
tools:
python: "3.11"

sphinx:
configuration: docs/source/conf.py

python:
version: 3.7
install:
- requirements: docs/requirements.txt
- method: pip
path: .
extra_requirements:
- dev
- requirements: docs/requirements.txt
5 changes: 5 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
=========

3.2.4 (2023-09-08)
------------------
this release is compatible with Oscar 3.2.1. This adds support for Django versions up to Django 4.2


3.2.0 (2023-03-03)
------------------
This release is compatible with Oscar 3.2 . Supported Django versions are 3.2, and supported Python versions are 3.7, 3.8, 3.9, 3.10 and 3.11. This is my (maerteijn) last release as maintainer of OscarAPI.
Expand Down
3 changes: 1 addition & 2 deletions oscarapi/basket/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_anonymous_basket(request):

basket_id = get_basket_id_from_session(request)
try:
basket = Basket.open.get(pk=basket_id)
basket = Basket.open.get(pk=basket_id, owner=None)
except Basket.DoesNotExist:
basket = None

Expand All @@ -83,7 +83,6 @@ def get_anonymous_basket(request):

def get_user_basket(user):
"get basket for a user."

try:
basket, __ = Basket.open.get_or_create(owner=user)
except Basket.MultipleObjectsReturned:
Expand Down
2 changes: 1 addition & 1 deletion oscarapi/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def process_response(self, request, response):
# We just have to make sure it is stored as a cookie, because it
# could have been created by oscarapi.
cookie_key = self.get_cookie_key(request)
basket = get_basket(request)
basket = get_basket(request, prepare=False)
cookie = self.get_basket_hash(basket.id)

# Delete any surplus cookies
Expand Down
2 changes: 1 addition & 1 deletion oscarapi/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"OSCARAPI_VOUCHER_FIELDS",
default=("name", "code", "start_datetime", "end_datetime"),
)
"ik ben harrie"

BASKET_FIELDS = overridable(
"OSCARAPI_BASKET_FIELDS",
default=(
Expand Down
108 changes: 106 additions & 2 deletions oscarapi/tests/unit/testbasket.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import json

from mock import patch

from unittest.mock import patch
from django.test import override_settings
from django.contrib.auth import get_user_model
from django.urls import reverse

Expand Down Expand Up @@ -1147,3 +1147,107 @@ def test_get_user_basket_with_multiple_baskets(self):
user_basket = get_user_basket(user)
self.assertEqual(Basket.open.count(), 1)
self.assertEqual(user_basket, Basket.open.first())


@override_settings(
MIDDLEWARE=(
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"oscarapi.middleware.ApiBasketMiddleWare",
"django.contrib.flatpages.middleware.FlatpageFallbackMiddleware",
)
)
class ApiBasketMiddleWareTest(APITest):
fixtures = [
"product",
"productcategory",
"productattribute",
"productclass",
"productattributevalue",
"category",
"attributeoptiongroup",
"attributeoption",
"stockrecord",
"partner",
"option",
]

def test_basket_login_logout(self):
self.assertEqual(
Basket.objects.count(), 0, "Initially there should be no baskets"
)

# add something to the anonymous basket, so we get a cookie basket
url = reverse("basket:add", kwargs={"pk": 1})
post_params = {"child_id": 2, "action": "add", "quantity": 5}
response = self.client.post(url, post_params, follow=True)

self.assertEqual(
Basket.objects.count(),
1,
"After posting to the basket, 1 basket should be created.",
)
self.assertIn(
"oscar_open_basket",
self.client.cookies,
"An basket cookie should have been created",
)
self.assertStartsWith(self.client.cookies["oscar_open_basket"].value, "1")

# retrieve the basket with oscarapi.
self.response = self.get("api-basket")
self.response.assertValueEqual(
"owner", None, "The basket should not have an owner"
)
self.response.assertValueEqual("id", 1)
self.assertStartsWith(self.client.cookies["oscar_open_basket"].value, "1")

# now lets log in with oscarapi
response = self.post("api-login", username="nobody", password="nobody")
# and lets retrieve the basket
self.response = self.get("api-basket")
self.response.assertValueEqual(
"owner",
"http://testserver/api/users/2/",
"the basket after login should have an owner",
)
self.assertEqual(
self.client.cookies["oscar_open_basket"].value,
"1:Rdm76bzEHM-N1G6WSTj0Zu9ByZ80a8ggxSkqqvGbC6s",
"After logging out the cookie unfortunately does not go away",
)

response = self.client.post(url, post_params, follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(Basket.objects.count(), 2)
self.assertEqual(
self.client.cookies["oscar_open_basket"].value,
"",
"The basket cookie should be removed",
)

self.response = self.delete("api-login")
self.assertStartsWith(
self.client.cookies["oscar_open_basket"].value,
"",
"After loging out, nothing happened to the basket cookie",
)

self.response = self.get("api-basket")
self.response.assertValueEqual(
"owner", None, "The logged out user's basket should not have an owner"
)
self.assertEqual(
Basket.objects.count(),
3,
"A new basket should be created for the anonymous (logged out) user",
)
self.assertStartsWith(
self.client.cookies["oscar_open_basket"].value,
"3",
"The basket cookie is re-established after accessing the basket when logged out",
)
2 changes: 1 addition & 1 deletion oscarapi/tests/unit/testcheckout.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from decimal import Decimal
from mock import patch
from unittest.mock import patch

from django.contrib.auth import get_user_model
from django.urls import reverse
Expand Down
2 changes: 1 addition & 1 deletion oscarapi/tests/unit/testproduct.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import mock
from unittest import mock
import decimal
import datetime
import json
Expand Down
2 changes: 1 addition & 1 deletion oscarapi/tests/unit/testuser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from mock import patch
from unittest.mock import patch
from django.contrib.auth import get_user_model
from django.urls import reverse

Expand Down
6 changes: 6 additions & 0 deletions oscarapi/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ def reload_modules(modules=()):
for module in modules:
reload_module(module)

def assertStartsWith(self, value, startvalue, message=""):
if not value.startswith(startvalue):
self.fail(
"'%s' does not start with '%s'. %s" % (value, startvalue, message)
)


class ParsedResponse(object):
def __init__(self, response, unittestcase):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import find_packages, setup

__version__ = "3.2.2"
__version__ = "3.2.4"

setup(
# package name in pypi
Expand Down

0 comments on commit 7b5f37f

Please sign in to comment.