diff --git a/allies/tests.py b/allies/tests.py new file mode 100644 index 000000000..3c7605cb4 --- /dev/null +++ b/allies/tests.py @@ -0,0 +1,49 @@ +from unittest import TestCase + +from allies.models import AllySubject, Ally +from snippets.models import Subject + +from wagtail.test.utils import WagtailTestUtils, WagtailPageTests + + +class AlliesTests(WagtailPageTests): + def setUp(self): + self.math = Subject(name="Math", page_content="Math page content.", seo_title="Math SEO Title", + search_description="Math page description.") + self.math.save() + + self.economics = Subject(name="Economics", page_content="Economics page content.", + seo_title="Economics SEO Title", + search_description="Economics page description.") + self.economics.save() + + self.subject = Subject(name="Science", page_content="Science page content.", seo_title="Science SEO Title", + search_description="Science page description.") + self.subject.save() + + self.ally = Ally(online_homework=True, + adaptive_courseware=False, + customization_tools=False, + is_ap=False, + do_not_display=False, + heading='Ally Heading', + short_description='short description', + long_description='long description', + slug='new-ally', + depth=1, + title='Ally Page', + path='ally') + self.ally.save() + + def test_can_create_ally_subject(self): + ally_subject = AllySubject(subject=self.math, ally=self.ally) + ally_subject.save() + result = AllySubject.objects.all()[0] + self.assertEquals('Math', result.get_subject_name()) + + def test_can_create_ally(self): + #ally_subject = AllySubject(subject=self.math, ally=self.ally) + #ally_subject.save() + result = Ally.objects.all()[0] + #print('ally subject: ' + str(result)) + self.assertEquals('Ally Heading', result.heading) diff --git a/api/tests.py b/api/tests.py index 832aa5e08..349eb527d 100644 --- a/api/tests.py +++ b/api/tests.py @@ -5,7 +5,7 @@ from wagtail.images.tests.utils import Image, get_test_image_file from wagtail.documents.models import Document -from api.models import FeatureFlag +from api.models import FeatureFlag, WebviewSettings from shared.test_utilities import assertPathDoesNotRedirectToTrailingSlash, mock_user_login @@ -164,3 +164,10 @@ def test_errata_resource_api(self): self.assertNotIn('content', 'OpenStax Concept Coach') self.assertNotIn('content', 'Rover by OpenStax') self.assertEqual(response.status_code, 200) + + def test_webview_settings_api(self): + wvs = WebviewSettings.objects.create(name='Test', value='Test value') + response = self.client.get('/apps/cms/api/webview-settings/') + self.assertEqual(response.status_code, 200) + self.assertIn("\"value\": \"Test value\"", response.content.decode("utf-8")) + diff --git a/errata/migrations/0054_alter_errata_resource.py b/errata/migrations/0054_alter_errata_resource.py new file mode 100644 index 000000000..a7f70fc77 --- /dev/null +++ b/errata/migrations/0054_alter_errata_resource.py @@ -0,0 +1,34 @@ +# Generated by Django 4.1.7 on 2023-09-11 19:14 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("errata", "0053_alter_errata_resource"), + ] + + operations = [ + migrations.AlterField( + model_name="errata", + name="resource", + field=models.CharField( + blank=True, + choices=[ + ("Textbook", "Textbook"), + ("iBooks version", "iBooks version"), + ("Instructor solution manual", "Instructor solution manual"), + ("Student solution manual", "Student solution manual"), + ("OpenStax Tutor", "OpenStax Tutor"), + ("OpenStax Concept Coach", "OpenStax Concept Coach"), + ("Rover by OpenStax", "Rover by OpenStax"), + ("Kindle", "Kindle"), + ("Study guide in online view", "Study guide in online view"), + ("Assignable", "Assignable"), + ("Other", "Other"), + ], + max_length=100, + null=True, + ), + ), + ] diff --git a/errata/models.py b/errata/models.py index 199951ed1..79eb96e6a 100644 --- a/errata/models.py +++ b/errata/models.py @@ -90,7 +90,6 @@ ('OpenStax Tutor', 'OpenStax Tutor'), ('OpenStax Concept Coach', 'OpenStax Concept Coach'), ('Rover by OpenStax', 'Rover by OpenStax'), - ('OpenStax + SE', 'OpenStax + SE'), ('Kindle', 'Kindle'), ('Study guide in online view', 'Study guide in online view'), ('Assignable', 'Assignable'), @@ -265,7 +264,7 @@ def save(self, *args, **kwargs): self.resolution_notes = 'This issue is occurring within a deprecated product that OpenStax no longer maintains. For updated content, please refer to openstax.org and view online or download a free PDF that may be used on your device.' #auto filling a couple of fields if it is clear that it is an assessment errata based on the text that tutor fills into the additional_location_information field - if self.additional_location_information and self.resource == 'OpenStax Tutor' and ('@' in self.additional_location_information.split()[0]): + if self.additional_location_information and (self.resource == 'OpenStax Tutor' or self.resource == 'Assignable') and ('@' in self.additional_location_information.split()[0]): self.is_assessment_errata = 'Yes' self.assessment_id = self.additional_location_information.split('@', )[0] diff --git a/extraadminfilters/tests.py b/extraadminfilters/tests.py new file mode 100644 index 000000000..fd41837a0 --- /dev/null +++ b/extraadminfilters/tests.py @@ -0,0 +1,12 @@ +from django.test import TestCase + +from extraadminfilters.filters import UnionFieldListFilter + + +class FilterTests(TestCase): + + def test_create_union_field_filter(self): + list_filter = [ + ("book", UnionFieldListFilter), + ] + self.assertEquals(list_filter[0][1], UnionFieldListFilter) diff --git a/news/tests.py b/news/tests.py index 9c4c42f07..ad0547b5e 100644 --- a/news/tests.py +++ b/news/tests.py @@ -1,3 +1,4 @@ +import datetime import json from django.utils import timezone @@ -182,7 +183,7 @@ def setUpTestData(cls): root_page.add_child(instance=homepage) # create book index page news_index = NewsIndex(title="News Index") - # add book index to homepage + homepage.add_child(instance=news_index) cls.news_index = Page.objects.get(id=news_index.id) @@ -257,4 +258,53 @@ def test_search_blog_collection_and_two_subjects(self): self.assertContains(response, 'Math') +class PressTests(WagtailPageTests): + def setUp(self): + press_index = PressIndex.objects.all()[0] + self.press_release = PressRelease(title='Press release', + date=datetime.datetime.now(), + author='someone', + heading='heading', + excerpt='this is a press release', + slug='press-release-1', + path=' ', + depth=1, + body=json.dumps( + [{"id": "ae6f048b-6eb5-42e7-844f-cfcd459f81b5", "type": "heading", + "value": "Press release"}, + {"id": "a21bcbd4-fec4-432e-bf06-966d739c6de9", "type": "paragraph", + "value": "
This is a test of a press release.
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
"}, + {"id": "4d339739-131c-4547-954b-0787afdc4914", "type": "tagline", + "value": "This is a test"}] + ) + ) + press_index.add_child(instance=self.press_release) + + @classmethod + def setUpTestData(cls): + root_page = Page.objects.get(title="Root") + homepage = HomePage(title="Hello World", slug="hello-world") + root_page.add_child(instance=homepage) + + press_index = PressIndex(about='About press index', + press_inquiry_phone='111-111-1111', + press_inquiry_email='press@example.com', + experts_heading='experts heading', + experts_blurb='experts blurb', + infographic_text='infographic text', + title='Press Index', + path=' ', + slug='press', + depth=1) + # add book index to homepage + homepage.add_child(instance=press_index) + cls.press_index = Page.objects.get(id=press_index.id) + + def test_can_create_press_release(self): + self.assertEqual(self.press_release.title, 'Press release') + + + + + diff --git a/shared/tests.py b/shared/tests.py index 1f82e65db..56a7e2efe 100644 --- a/shared/tests.py +++ b/shared/tests.py @@ -1,8 +1,16 @@ -from wagtail.test.utils import WagtailPageTests -from shared.test_utilities import assertPathDoesNotRedirectToTrailingSlash +from django.test import TestCase +from shared.test_utilities import mock_user_login, RequestMock + from unittest.mock import MagicMock -class WagtailTests(WagtailPageTests): - def setUp(self): - pass +class TestMockUserLogin(TestCase): + def test_mock_user_login(self): + user = mock_user_login() + self.assertEqual(user.openstaxuserprofile.openstax_accounts_uuid, '467cea6c-8159-40b1-90f1-e9b0dc26344c') + + +class TestMockRequest(TestCase): + def test_create_mock_request(self): + req = RequestMock() + self.assertEqual(req.cookies, {}) diff --git a/wagtailimportexport/functions.py b/wagtailimportexport/functions.py index 2b7871968..0b19bd0ed 100644 --- a/wagtailimportexport/functions.py +++ b/wagtailimportexport/functions.py @@ -243,3 +243,4 @@ def content_type_by_model(model): return None else: return str(content_type[0].pk) + diff --git a/wagtailimportexport/tests/tests.py b/wagtailimportexport/tests/tests.py new file mode 100644 index 000000000..ec9f65409 --- /dev/null +++ b/wagtailimportexport/tests/tests.py @@ -0,0 +1,36 @@ +from unittest import mock + +from django.forms import FileField, ModelChoiceField +from django.test import TestCase, Client +from django.core.files.uploadedfile import SimpleUploadedFile +from django.core.files import File + +from pages.models import HomePage +from wagtailimportexport.forms import ImportPage, ExportPage + + +class TemplateTests(TestCase): + def setUp(self): + self.client = Client() + + def test_import_template(self): + response = self.client.get('/admin/import-export/import-page/', follow=True) + self.assertEqual(response.status_code, 200) + + def test_export_template(self): + response = self.client.get('/admin/import-export/export-page/', follow=True) + self.assertEqual(response.status_code, 200) + + def test_import_form(self): + zip = SimpleUploadedFile("test.zip", b"file content", content_type="application/zip") + form_data = {"parent_page": 1} + form = ImportPage(form_data, files={'file': zip}) + self.assertTrue(form.is_valid(), form.errors) + + def test_export_form(self): + form_data = {"root_page": 1} + form = ExportPage(form_data) + self.assertTrue(form.is_valid(), form.errors) + + +