From 971c88db1fe0c310bc51758ca58191fab2d10cfd Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Thu, 12 Dec 2024 20:31:10 +0000 Subject: [PATCH] Add test for posting to airtable_import_listing --- tests/test_views.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/test_views.py b/tests/test_views.py index 6318344..b394e83 100644 --- a/tests/test_views.py +++ b/tests/test_views.py @@ -11,9 +11,12 @@ class TestAdminViews(TestCase): fixtures = ['test.json'] def setUp(self): - airtable_patcher = patch("wagtail_airtable.mixins.Airtable", new_callable=get_mock_airtable()) - airtable_patcher.start() - self.addCleanup(airtable_patcher.stop) + airtable_mixins_patcher = patch("wagtail_airtable.mixins.Airtable", new_callable=get_mock_airtable()) + airtable_mixins_patcher.start() + self.addCleanup(airtable_mixins_patcher.stop) + airtable_importer_patcher = patch("wagtail_airtable.importer.Airtable", new_callable=get_mock_airtable()) + self.mock_airtable = airtable_importer_patcher.start() + self.addCleanup(airtable_importer_patcher.stop) self.client.login(username='admin', password='password') @@ -24,6 +27,18 @@ def test_get(self): self.assertContains(response, 'Advert') self.assertNotContains(response, 'Simple Page') + def test_post(self): + advert = Advert.objects.get(airtable_record_id="recNewRecordId") + self.assertNotEqual(advert.title, "Red! It's the new blue!") + + response = self.client.post(reverse('airtable_import_listing'), { + 'model': 'tests.Advert', + }) + self.assertRedirects(response, reverse('airtable_import_listing')) + + advert.refresh_from_db() + self.assertEqual(advert.title, "Red! It's the new blue!") + def test_list_snippets(self): url = reverse('wagtailsnippets_tests_advert:list')