Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upgrade to wagtail 6.4 + Django 5.1 #1606

Merged
merged 8 commits into from
Feb 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 35 additions & 21 deletions api/tests.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
import json
from django.test import TestCase

from django.urls import reverse
from wagtail.test.utils import WagtailTestUtils
from wagtail.images.tests.utils import Image, get_test_image_file
from wagtail.documents.tests.utils import get_test_document_file
from wagtail.documents.models import Document

from api.models import FeatureFlag, WebviewSettings

from shared.test_utilities import mock_user_login


class PagesAPI(TestCase, WagtailTestUtils):
def setUp(self):
pass

def test_api_v2_pages_urls(self):
#make sure we get a 200 with or without a slash, no 3xx
# make sure we get a 200 with or without a slash, no 3xx
response = self.client.get('/apps/cms/api/v2/pages/')
self.assertEqual(response.status_code, 200)

Expand Down Expand Up @@ -63,38 +65,50 @@ def setUp(self):
pass

def test_api_v2_single_document(self):
response = self.client.get('/apps/cms/api/v2/documents/')
# Get the URL dynamically
url = reverse('document-list') # Update with the actual view name if different

# Initial GET: Expect empty list
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
response_dict = eval(response.content.decode(response.charset))
self.assertIsInstance(response_dict, dict)
self.assertEqual(response_dict['meta']['total_count'], 0)
self.assertEqual(response_dict['items'], [])
response_dict = response.json()
self.assertEqual(len(response_dict), 0)
self.assertEqual(response_dict, [])

# Create a document
expected_title = "Test document"
image = Document.objects.create(
Document.objects.create(
title=expected_title,
file=get_test_image_file(),
file=get_test_document_file(),
)

response = self.client.get('/apps/cms/api/v2/documents/')
# Second GET: Expect one document
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
response_dict = eval(response.content.decode(response.charset))
self.assertIsInstance(response_dict, dict)
self.assertEqual(response_dict['meta']['total_count'], 1)
returned_title = response_dict['items'][0]['title']
self.assertEqual(expected_title, returned_title)
response_dict = response.json()

# Assertions
self.assertEqual(len(response_dict), 1)
self.assertEqual(response_dict[0]['title'], expected_title)

def test_can_search_documents(self):
image = Document.objects.create(
url = reverse('document-list')

document = Document.objects.create(
title="OpenStax",
file=get_test_image_file(),
file=get_test_document_file(),
)
self.assertEqual(document.title, 'OpenStax')

response = self.client.get('/apps/cms/api/v2/documents/?search=OpenStax')
response = self.client.get(url, {'search': 'OpenStax'})
self.assertEqual(response.status_code, 200)
response_dict = eval(response.content.decode(response.charset))
self.assertIsInstance(response_dict, dict)
self.assertEqual(response_dict['meta']['total_count'], 1)

# Safer JSON parsing
response_dict = response.json()

# Assertions
self.assertEqual(len(response_dict), 1)
self.assertEqual(response_dict[0]['title'], 'OpenStax')


class APITests(TestCase, WagtailTestUtils):
Expand Down
9 changes: 4 additions & 5 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,10 @@ class DocumentViewSet(viewsets.ReadOnlyModelViewSet):
serializer_class = DocumentSerializer

def get_queryset(self):
queryset = Document.objects.all()
search = self.request.query_params.get('search', None)
if search is not None:
queryset = queryset.filter(title__icontains=search)
return queryset
search = self.request.query_params.get('search')
if search:
return Document.objects.filter(title__icontains=search)
return Document.objects.all()


class ProgressViewSet(viewsets.ReadOnlyModelViewSet):
Expand Down
4 changes: 1 addition & 3 deletions books/tests.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
import vcr

from wagtail.test.utils import WagtailPageTestCase
from wagtail.models import Page

import snippets.models
from pages.models import HomePage
from books.models import BookIndex, Book, BookFacultyResources
from shared.test_utilities import assertPathDoesNotRedirectToTrailingSlash
from salesforce.tests import openstax_vcr as vcr
from django.core.files.uploadedfile import SimpleUploadedFile
from django.test import Client
from rest_framework.exceptions import NotFound
from wagtail.documents.models import Document
import datetime

Expand Down
46 changes: 23 additions & 23 deletions fixtures/vcr_cassettes/books_license.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@ interactions:
\ <urn:client>simple-salesforce</urn:client>\n <urn:defaultNamespace>sf</urn:defaultNamespace>\n
\ </urn:CallOptions>\n </env:Header>\n <env:Body>\n <n1:login
xmlns:n1=\"urn:partner.soap.sforce.com\">\n <n1:username></n1:username>\n
\ <n1:password></n1:password>\n
\ </n1:login>\n </env:Body>\n</env:Envelope>"
\ <n1:password></n1:password>\n </n1:login>\n </env:Body>\n</env:Envelope>"
headers:
Accept:
- '*/*'
Expand All @@ -16,37 +15,38 @@ interactions:
Connection:
- keep-alive
Content-Length:
- '744'
- '759'
SOAPAction:
- login
User-Agent:
- python-requests/2.31.0
- python-requests/2.32.3
charset:
- UTF-8
content-type:
- text/xml
method: POST
uri: https://test.salesforce.com/services/Soap/u/57.0
uri: https://test.salesforce.com/services/Soap/u/59.0
response:
body:
string: <?xml version="1.0" encoding="UTF-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><loginResponse><result><metadataServerUrl>https://openstax--staging.sandbox.my.salesforce.com/services/Soap/m/57.0/00DOx000002qc01</metadataServerUrl><passwordExpired>false</passwordExpired><sandbox>true</sandbox><serverUrl>https://openstax--staging.sandbox.my.salesforce.com/services/Soap/u/57.0/00DOx000002qc01</serverUrl><sessionId>00DOx000002qc01!AQEAQF2cYbO.p0JWJlBNDnChZd7X5xizdDbtmoe.29hI9rztJW0J8hN8VuzWnVfb55rN0PWexxpTHIeHrW7U5sFx4.trlQ85</sessionId><userId>005U0000005akrEIAQ</userId><userInfo><accessibilityMode>false</accessibilityMode><chatterExternal>false</chatterExternal><currencySymbol>$</currencySymbol><orgAttachmentFileSizeLimit>5242880</orgAttachmentFileSizeLimit><orgDefaultCurrencyIsoCode>USD</orgDefaultCurrencyIsoCode><orgDefaultCurrencyLocale>en_US</orgDefaultCurrencyLocale><orgDisallowHtmlAttachments>false</orgDisallowHtmlAttachments><orgHasPersonAccounts>true</orgHasPersonAccounts><organizationId>00DOx000002qc01MAA</organizationId><organizationMultiCurrency>false</organizationMultiCurrency><organizationName>OpenStax</organizationName><profileId>00eU0000000qdoxIAA</profileId><roleId>00E6f000001ybA2EAI</roleId><sessionSecondsValid>86400</sessionSecondsValid><userDefaultCurrencyIsoCode
xsi:nil="true"/><userEmail>volo@rice.edu</userEmail><userFullName>Michael
Volo</userFullName><userId>005U0000005akrEIAQ</userId><userLanguage>en_US</userLanguage><userLocale>en_US</userLocale><userName>volo@rice.edu.staging</userName><userTimeZone>America/Chicago</userTimeZone><userType>Standard</userType><userUiSkin>Theme3</userUiSkin></userInfo></result></loginResponse></soapenv:Body></soapenv:Envelope>
xmlns="urn:partner.soap.sforce.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><soapenv:Body><loginResponse><result><metadataServerUrl>https://openstax--staging.sandbox.my.salesforce.com/services/Soap/m/59.0/00DOy00000BbeBR</metadataServerUrl><passwordExpired>false</passwordExpired><sandbox>true</sandbox><serverUrl>https://openstax--staging.sandbox.my.salesforce.com/services/Soap/u/59.0/00DOy00000BbeBR</serverUrl><sessionId>00DOy00000BbeBR!AQEAQNlbmZg4EFb12KJbpA20fYO8sFvdmYoU26vKoJrGeuSNMJbF12oT1umtbNAXpw9DIGXCInDt_ROtK3SRY1vOupFQQQwU</sessionId><userId>005U0000005MXdmIAG</userId><userInfo><accessibilityMode>false</accessibilityMode><chatterExternal>false</chatterExternal><currencySymbol>$</currencySymbol><orgAttachmentFileSizeLimit>5242880</orgAttachmentFileSizeLimit><orgDefaultCurrencyIsoCode>USD</orgDefaultCurrencyIsoCode><orgDefaultCurrencyLocale>en_US</orgDefaultCurrencyLocale><orgDisallowHtmlAttachments>false</orgDisallowHtmlAttachments><orgHasPersonAccounts>true</orgHasPersonAccounts><organizationId>00DOy00000BbeBRMAZ</organizationId><organizationMultiCurrency>false</organizationMultiCurrency><organizationName>OpenStax</organizationName><profileId>00eU0000000qdoxIAA</profileId><roleId
xsi:nil="true"/><sessionSecondsValid>86400</sessionSecondsValid><userDefaultCurrencyIsoCode
xsi:nil="true"/><userEmail>sfadmin@openstax.org</userEmail><userFullName>Tracking
User</userFullName><userId>005U0000005MXdmIAG</userId><userLanguage>en_US</userLanguage><userLocale>en_US</userLocale><userName>trackinguser@rice.edu.staging</userName><userTimeZone>America/Chicago</userTimeZone><userType>Standard</userType><userUiSkin>Theme3</userUiSkin></userInfo></result></loginResponse></soapenv:Body></soapenv:Envelope>
headers:
Cache-Control:
- no-cache,must-revalidate,max-age=0,no-store,private
Content-Encoding:
- gzip
Content-Length:
- '831'
- '835'
Content-Type:
- text/xml; charset=utf-8
Date:
- Wed, 28 Feb 2024 00:30:00 GMT
- Sat, 11 Jan 2025 00:01:40 GMT
Set-Cookie:
- BrowserId=gc8VMdXQEe6miukBr8Go3g; domain=.salesforce.com; path=/; expires=Thu,
27-Feb-2025 00:30:00 GMT; Max-Age=31536000
- BrowserId=PE2bPc-vEe-lpS2DlOJiBg; domain=.salesforce.com; path=/; expires=Sun,
11-Jan-2026 00:01:40 GMT; Max-Age=31536000; secure; SameSite=None
Vary:
- Accept-Encoding
status:
Expand All @@ -59,24 +59,22 @@ interactions:
- '*/*'
Accept-Encoding:
- gzip, deflate
Authorization:
- Bearer 00DOx000002qc01!AQEAQF2cYbO.p0JWJlBNDnChZd7X5xizdDbtmoe.29hI9rztJW0J8hN8VuzWnVfb55rN0PWexxpTHIeHrW7U5sFx4.trlQ85
Connection:
- keep-alive
Content-Type:
- application/json
Cookie:
- BrowserId=gc8VMdXQEe6miukBr8Go3g
- BrowserId=PE2bPc-vEe-lpS2DlOJiBg
User-Agent:
- python-requests/2.31.0
- python-requests/2.32.3
X-PrettyPrint:
- '1'
method: GET
uri: https://openstax--staging.sandbox.my.salesforce.com/services/data/v57.0/query/?q=Select+Name%2C+Official_Name__c+from+Book__c+where+Id+%3D+%27a0ZU0000008pyvQMAQ%27
uri: https://openstax--staging.sandbox.my.salesforce.com/services/data/v59.0/query/?q=Select+Name%2C+Official_Name__c+from+Book__c+where+Id+%3D+%27a0ZU0000008pyvQMAQ%27
response:
body:
string: "{\n \"totalSize\" : 1,\n \"done\" : true,\n \"records\" : [ {\n
\ \"attributes\" : {\n \"type\" : \"Book__c\",\n \"url\" : \"/services/data/v57.0/sobjects/Book__c/a0ZU0000008pyvQMAQ\"\n
\ \"attributes\" : {\n \"type\" : \"Book__c\",\n \"url\" : \"/services/data/v59.0/sobjects/Book__c/a0ZU0000008pyvQMAQ\"\n
\ },\n \"Name\" : \"University Physics (Calc)\",\n \"Official_Name__c\"
: \"University Physics\"\n } ]\n}"
headers:
Expand All @@ -89,16 +87,16 @@ interactions:
Content-Type:
- application/json;charset=UTF-8
Date:
- Wed, 28 Feb 2024 00:30:01 GMT
- Sat, 11 Jan 2025 00:01:41 GMT
Server:
- sfdcedge
Set-Cookie:
- CookieConsentPolicy=0:1; path=/; expires=Thu, 27-Feb-2025 00:30:01 GMT; Max-Age=31536000;
- CookieConsentPolicy=0:1; path=/; expires=Sun, 11-Jan-2026 00:01:41 GMT; Max-Age=31536000;
secure
- LSKey-c$CookieConsentPolicy=0:1; path=/; expires=Thu, 27-Feb-2025 00:30:01
- LSKey-c$CookieConsentPolicy=0:1; path=/; expires=Sun, 11-Jan-2026 00:01:41
GMT; Max-Age=31536000; secure
Sforce-Limit-Info:
- api-usage=64987/5000000
- api-usage=37317/5000000
Strict-Transport-Security:
- max-age=63072000; includeSubDomains
Transfer-Encoding:
Expand All @@ -107,12 +105,14 @@ interactions:
- Accept-Encoding
X-Content-Type-Options:
- nosniff
X-Request-Id:
- fda241a9f6f3e3024f437c21a744177a
X-Robots-Tag:
- none
X-SFDC-Edge-Cache:
- MISS
X-SFDC-Request-Id:
- 2f53fd0746bc84b7370c052e05f9780c
- fda241a9f6f3e3024f437c21a744177a
status:
code: 200
message: OK
Expand Down
Loading