-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add the gist of a new importer Extracted from internal project * Convert mock airtable to a callable This means the data in it is pure, and is safe to mutate if needed. * Update tests for importer * Use mocks for stubbing out airtable * Move mock airtable into tests dir Reduce the size of the package, and put test fixtures where they should be * Remove display method Woops! * Add tests for creating an object * Fix count reporting on index view * Reinstate ability to pass multiple models to import_airtable command * Reinstate fix for m2m on model creation (from #36) * Fix "null has no effect on ManyToManyField" warning on tests Also rename the migration that adds the advert-publications relation to something more meaningful * Add test for posting to airtable_import_listing * Test (and fix) importing of page models * Remove unused wagtail_route template tag This was introduced in a4298fc to make the overridden type_index.html template work with URL routes for both Wagtail 3.2 and 4.0, and became redundant in 431fd47 when the template was replaced with the one from Wagtail 4.2 (which doesn't refer to those routes at all, as they're passed in the template context). * Update docs to state that PARENT_PAGE_ID functions take no arguments. Fixes #74 * Add airtable_import_record_updated hook support to new importer * Add tests for updating pages, and publishing created pages --------- Co-authored-by: Jake Howard <[email protected]>
- Loading branch information
1 parent
bc1604c
commit 1096de3
Showing
19 changed files
with
825 additions
and
1,222 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.9 on 2024-12-12 23:29 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("tests", "0004_advert_publications"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="simplepage", | ||
name="airtable_record_id", | ||
field=models.CharField(blank=True, db_index=True, max_length=35), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,160 @@ | ||
"""A mocked Airtable API wrapper.""" | ||
from unittest import mock | ||
|
||
def get_mock_airtable(): | ||
""" | ||
Wrap it in a function, so it's pure | ||
""" | ||
|
||
class MockAirtable(mock.Mock): | ||
def get_iter(self): | ||
return [self.get_all()] | ||
|
||
|
||
MockAirtable.table_name = "app_airtable_advert_base_key" | ||
|
||
MockAirtable.get = mock.MagicMock("get") | ||
MockAirtable.get.return_value = { | ||
"id": "recNewRecordId", | ||
"fields": { | ||
"title": "Red! It's the new blue!", | ||
"description": "Red is a scientifically proven color that moves faster than all other colors.", | ||
"external_link": "https://example.com/", | ||
"is_active": True, | ||
"rating": "1.5", | ||
"long_description": "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam laboriosam consequatur saepe. Repellat itaque dolores neque, impedit reprehenderit eum culpa voluptates harum sapiente nesciunt ratione.</p>", | ||
"points": 95, | ||
"slug": "red-its-new-blue", | ||
}, | ||
} | ||
|
||
MockAirtable.insert = mock.MagicMock("insert") | ||
MockAirtable.insert.return_value = { | ||
"id": "recNewRecordId", | ||
"fields": { | ||
"title": "Red! It's the new blue!", | ||
"description": "Red is a scientifically proven color that moves faster than all other colors.", | ||
"external_link": "https://example.com/", | ||
"is_active": True, | ||
"rating": "1.5", | ||
"long_description": "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam laboriosam consequatur saepe. Repellat itaque dolores neque, impedit reprehenderit eum culpa voluptates harum sapiente nesciunt ratione.</p>", | ||
"points": 95, | ||
"slug": "red-its-new-blue", | ||
}, | ||
} | ||
|
||
MockAirtable.update = mock.MagicMock("update") | ||
MockAirtable.update.return_value = { | ||
"id": "recNewRecordId", | ||
"fields": { | ||
"title": "Red! It's the new blue!", | ||
"description": "Red is a scientifically proven color that moves faster than all other colors.", | ||
"external_link": "https://example.com/", | ||
"is_active": True, | ||
"rating": "1.5", | ||
"long_description": "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam laboriosam consequatur saepe. Repellat itaque dolores neque, impedit reprehenderit eum culpa voluptates harum sapiente nesciunt ratione.</p>", | ||
"points": 95, | ||
"slug": "red-its-new-blue", | ||
}, | ||
} | ||
|
||
MockAirtable.delete = mock.MagicMock("delete") | ||
MockAirtable.delete.return_value = {"deleted": True, "record": "recNewRecordId"} | ||
|
||
MockAirtable.search = mock.MagicMock("search") | ||
MockAirtable.search.return_value = [ | ||
{ | ||
"id": "recNewRecordId", | ||
"fields": { | ||
"title": "Red! It's the new blue!", | ||
"description": "Red is a scientifically proven color that moves faster than all other colors.", | ||
"external_link": "https://example.com/", | ||
"is_active": True, | ||
"rating": "1.5", | ||
"long_description": "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam laboriosam consequatur saepe. Repellat itaque dolores neque, impedit reprehenderit eum culpa voluptates harum sapiente nesciunt ratione.</p>", | ||
"points": 95, | ||
"slug": "red-its-new-blue", | ||
}, | ||
}, | ||
{ | ||
"id": "Different record", | ||
"fields": { | ||
"title": "Not the used record.", | ||
"description": "This is only used for multiple responses from MockAirtable", | ||
"external_link": "https://example.com/", | ||
"is_active": False, | ||
"rating": "5.5", | ||
"long_description": "", | ||
"points": 1, | ||
"slug": "not-the-used-record", | ||
}, | ||
}, | ||
] | ||
|
||
MockAirtable.get_all = mock.MagicMock("get_all") | ||
MockAirtable.get_all.return_value = [ | ||
{ | ||
"id": "recNewRecordId", | ||
"fields": { | ||
"title": "Red! It's the new blue!", | ||
"description": "Red is a scientifically proven color that moves faster than all other colors.", | ||
"external_link": "https://example.com/", | ||
"is_active": True, | ||
"rating": "1.5", | ||
"long_description": "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Veniam laboriosam consequatur saepe. Repellat itaque dolores neque, impedit reprehenderit eum culpa voluptates harum sapiente nesciunt ratione.</p>", | ||
"points": 95, | ||
"slug": "delete-me", | ||
"publications": [ | ||
{"title": "Record 1 publication 1"}, | ||
{"title": "Record 1 publication 2"}, | ||
{"title": "Record 1 publication 3"}, | ||
] | ||
}, | ||
}, | ||
{ | ||
"id": "Different record", | ||
"fields": { | ||
"title": "Not the used record.", | ||
"description": "This is only used for multiple responses from MockAirtable", | ||
"external_link": "https://example.com/", | ||
"is_active": False, | ||
"rating": "5.5", | ||
"long_description": "", | ||
"points": 1, | ||
"slug": "not-the-used-record", | ||
}, | ||
}, | ||
{ | ||
"id": "recRecordThree", | ||
"fields": { | ||
"title": "A third record.", | ||
"description": "This is only used for multiple responses from MockAirtable", | ||
"external_link": "https://example.com/", | ||
"is_active": False, | ||
"rating": "5.5", | ||
"long_description": "", | ||
"points": 1, | ||
"slug": "record-3", | ||
}, | ||
}, | ||
{ | ||
"id": "recRecordFour", | ||
"fields": { | ||
"title": "A fourth record.", | ||
"description": "This is only used for multiple responses from MockAirtable", | ||
"external_link": "https://example.com/", | ||
"is_active": False, | ||
"rating": "5.5", | ||
"long_description": "", | ||
"points": 1, | ||
"slug": "record-4", | ||
"publications": [ | ||
{"title": "Record 4 publication 1"}, | ||
{"title": "Record 4 publication 2"}, | ||
{"title": "Record 4 publication 3"}, | ||
] | ||
}, | ||
}, | ||
] | ||
|
||
return MockAirtable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.