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

New importer #33

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def airtable_record_updated(instance, is_wagtail_page, record_id):
### Management Commands

```bash
python manage.py import_airtable appname.ModelName secondapp.SecondModel
python manage.py import_airtable appname.ModelName
```

Optionally you can turn up the verbosity for better debugging with the `--verbosity=2` flag.
Expand Down
149 changes: 149 additions & 0 deletions tests/mock_airtable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
"""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",
},
},
{
"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",
},
},
]

return MockAirtable
3 changes: 3 additions & 0 deletions tests/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ class AdvertSerializer(AirtableSerializer):
slug = serializers.CharField(max_length=100, required=True)
title = serializers.CharField(max_length=255)
external_link = serializers.URLField(required=False)

class SimplePageSerializer(AirtableSerializer):
pass
Loading