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

Mnch 985 contentrepo whatsapp template #223

Merged
merged 6 commits into from
Jan 8, 2024
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
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ This can work for mac and (possibly Windows) by setting the environment variable

Run the following in a virtual environment
```bash
pip install -e .[dev]
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install -r requirements-dev.txt
createdb contentrepo
./manage.py migrate
./manage.py createsuperuser
Expand All @@ -91,7 +93,7 @@ createdb contentrepo

### Automated tests

Tests are run using [pytest](https://pytest.org)). For faster test runs, try adding `--no-cov` to disable coverage reporting and/or `-n auto` to run multiple tests in parallel.
Tests are run using [pytest](https://pytest.org). For faster test runs, try adding `--no-cov` to disable coverage reporting and/or `-n auto` to run multiple tests in parallel.

## API
The API documentation is available at the `/api/schema/swagger-ui/` endpoint.
Expand Down
2 changes: 1 addition & 1 deletion home/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,7 +605,7 @@ def latest_revision_rating(self):

@property
def whatsapp_template_prefix(self):
return self.whatsapp_title.replace(" ", "_")
return self.whatsapp_title.lower().replace(" ", "_")

@property
def whatsapp_template_body(self):
Expand Down
16 changes: 8 additions & 8 deletions home/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_template_create_on_save_deactivated(self, mock_create_whatsapp_template
def test_template_create_on_save(self, mock_create_whatsapp_template):
page = create_page(is_whatsapp_template=True)
mock_create_whatsapp_template.assert_called_with(
f"WA_Title_{page.get_latest_revision().id}",
f"wa_title_{page.get_latest_revision().id}",
"Test WhatsApp Message 1",
"UTILITY",
[],
Expand All @@ -71,7 +71,7 @@ def test_template_create_on_save(self, mock_create_whatsapp_template):
def test_template_create_with_buttons_on_save(self, mock_create_whatsapp_template):
page = create_page(is_whatsapp_template=True, has_quick_replies=True)
mock_create_whatsapp_template.assert_called_with(
f"WA_Title_{page.get_latest_revision().id}",
f"wa_title_{page.get_latest_revision().id}",
"Test WhatsApp Message 1",
"UTILITY",
["button 1", "button 2"],
Expand All @@ -86,7 +86,7 @@ def test_template_create_with_example_values_on_save(
):
page = create_page(is_whatsapp_template=True, add_example_values=True)
mock_create_whatsapp_template.assert_called_with(
f"WA_Title_{page.get_latest_revision().id}",
f"wa_title_{page.get_latest_revision().id}",
"Test WhatsApp Message with two variables, {{1}} and {{2}}",
"UTILITY",
[],
Expand All @@ -103,7 +103,7 @@ def test_template_updated_on_change(self, mock_create_whatsapp_template):
"""
page = create_page(is_whatsapp_template=True, has_quick_replies=True)
mock_create_whatsapp_template.assert_called_once_with(
f"WA_Title_{page.get_latest_revision().pk}",
f"wa_title_{page.get_latest_revision().pk}",
"Test WhatsApp Message 1",
"UTILITY",
["button 1", "button 2"],
Expand All @@ -116,7 +116,7 @@ def test_template_updated_on_change(self, mock_create_whatsapp_template):
revision = page.save_revision()
revision.publish()

expected_title = f"WA_Title_{page.get_latest_revision().pk}"
expected_title = f"wa_title_{page.get_latest_revision().pk}"
mock_create_whatsapp_template.assert_called_once_with(
expected_title,
"Test WhatsApp Message 2",
Expand All @@ -138,7 +138,7 @@ def test_template_not_submitted_on_no_change(self, mock_create_whatsapp_template
page = create_page(is_whatsapp_template=True, has_quick_replies=True)
page.get_latest_revision().publish()
page.refresh_from_db()
expected_template_name = f"WA_Title_{page.get_latest_revision().pk}"
expected_template_name = f"wa_title_{page.get_latest_revision().pk}"
mock_create_whatsapp_template.assert_called_once_with(
expected_template_name,
"Test WhatsApp Message 1",
Expand Down Expand Up @@ -172,7 +172,7 @@ def test_template_submitted_when_is_whatsapp_template_is_set(
page.save_revision().publish()

page.refresh_from_db()
expected_template_name = f"WA_Title_{page.get_latest_revision().pk}"
expected_template_name = f"wa_title_{page.get_latest_revision().pk}"
self.assertEqual(page.whatsapp_template_name, expected_template_name)
mock_create_whatsapp_template.assert_called_once_with(
expected_template_name,
Expand Down Expand Up @@ -205,7 +205,7 @@ def test_template_submitted_with_no_whatsapp_previous_revision(
page.is_whatsapp_template = True
page.save_revision()

expected_template_name = f"WA_Title_{page.get_latest_revision().pk}"
expected_template_name = f"wa_title_{page.get_latest_revision().pk}"
mock_create_whatsapp_template.assert_called_once_with(
expected_template_name,
"Test WhatsApp Message 1",
Expand Down
8 changes: 4 additions & 4 deletions home/tests/test_whatsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_create_whatsapp_template(self):
url = "http://whatsapp/graph/v14.0/27121231234/message_templates"
responses.add(responses.POST, url, json={})

create_whatsapp_template("Test-Template", "Test Body", "UTILITY")
create_whatsapp_template("test-template", "Test Body", "UTILITY")

request = responses.calls[0].request

Expand Down Expand Up @@ -55,7 +55,7 @@ def test_create_whatsapp_template_with_example_values(self):
responses.add(responses.POST, url, json={})

create_whatsapp_template(
"Test-Template",
"test-template",
"Hi {{1}}. You are testing as a {{2}}",
"UTILITY",
[],
Expand Down Expand Up @@ -88,7 +88,7 @@ def test_create_whatsapp_template_with_buttons(self):
responses.add(responses.POST, url, json={})

create_whatsapp_template(
"Test-Template",
"test-template",
"Test Body",
"UTILITY",
["Test button1", "test button2"],
Expand Down Expand Up @@ -137,7 +137,7 @@ def test_create_whatsapp_template_with_image(self, tmp_path, settings):
responses.add(responses.POST, template_url, json={})

create_whatsapp_template(
"Test-Template", "Test Body", "UTILITY", [], saved_image.id
"test-template", "Test Body", "UTILITY", [], saved_image.id
)

mock_get_session_data = {
Expand Down
2 changes: 1 addition & 1 deletion home/whatsapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def create_whatsapp_template(

data = {
"category": category,
"name": name.lower(),
"name": name,
"language": "en_US",
"components": components,
}
Expand Down