Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/weni-ai/flows into feature/…
Browse files Browse the repository at this point in the history
…add-task-to-update-products-for-a-catalog
  • Loading branch information
lucaslinhares committed Feb 2, 2024
2 parents 90466ad + 4fe9a36 commit 21b90e1
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
8 changes: 8 additions & 0 deletions WENI-CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
3.5.5
----------
* Chore: Bump floweditor to 2.10.2

3.5.4
----------
* Chore: Bump floweditor to 2.10.1

3.5.3
----------
* Fix error when nexus return 500
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
]
},
"dependencies": {
"@weni/flow-editor": "2.10.0",
"@weni/flow-editor": "2.10.2",
"@nyaruka/temba-components": "0.23.0",
"colorette": "1.2.2",
"fa-icons": "0.2.0",
Expand Down
29 changes: 29 additions & 0 deletions temba/api/v2/wenigpt/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def test_get_intelligences(self, mock_requests_get):
]

mock_requests_get.return_value = mock_response
mock_requests_get.return_value.status_code = 200

url = reverse("api.v2.intelligences") + ".json"

Expand All @@ -37,3 +38,31 @@ def test_get_intelligences(self, mock_requests_get):
}

self.assertEqual(response.json(), expected_data)

@patch("temba.api.v2.wenigpt.views.requests.get")
def test_get_intelligences_error(self, mock_requests_get):
mock_response = MagicMock()
mock_response.json.return_value = [
{
"intelligence_name": "Test Intelligence 0",
"content_bases": [
{"uuid": "123456", "content_base_name": "Test Content Base 0"},
{"uuid": "654321", "content_base_name": "Test Content Base 1"},
],
},
]

mock_requests_get.return_value = mock_response
mock_requests_get.return_value.status_code = 500

url = reverse("api.v2.intelligences") + ".json"

self.client.force_login(self.user)

response = self.client.get(url)

self.assertEqual(response.status_code, 200)

expected_data = {"results": []}

self.assertEqual(response.json(), expected_data)
8 changes: 4 additions & 4 deletions temba/channels/types/whatsapp/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,16 +583,16 @@ def test_get_api_products(self, mock_get):
MockResponse(200, '{"data": ["bar"], "paging": {"next": null} }'),
]

products_data, no_error = WhatsAppType().get_api_products(channel, catalog)
products_data, no_error = WhatsAppType().get_api_products(channel, catalog.facebook_catalog_id)
self.assertEqual(1, HTTPLog.objects.filter(log_type=HTTPLog.WHATSAPP_PRODUCTS_SYNCED).count())
self.assertFalse(no_error)
self.assertEqual([], products_data)

products_data, no_error = WhatsAppType().get_api_products(channel, catalog)
products_data, no_error = WhatsAppType().get_api_products(channel, catalog.facebook_catalog_id)
self.assertFalse(no_error)
self.assertEqual([], products_data)

products_data, no_error = WhatsAppType().get_api_products(channel, catalog)
products_data, no_error = WhatsAppType().get_api_products(channel, catalog.facebook_catalog_id)
self.assertTrue(no_error)
self.assertEqual(["foo", "bar"], products_data)

Expand All @@ -601,6 +601,6 @@ def test_get_api_products(self, mock_get):
params={"access_token": "token123456", "limit": 255},
)

products_data, no_error = WhatsAppType().get_api_products(channel, catalog)
products_data, no_error = WhatsAppType().get_api_products(channel, catalog.facebook_catalog_id)
self.assertTrue(no_error)
self.assertEqual(["foo", "bar"], products_data)
10 changes: 5 additions & 5 deletions temba/channels/types/whatsapp_cloud/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ def test_get_api_catalogs(self, mock_get):

@override_settings(WHATSAPP_ADMIN_SYSTEM_USER_TOKEN="WA_ADMIN_TOKEN")
@patch("requests.get")
def test_get_api_produtcs(self, mock_get):
def test_get_api_products(self, mock_get):
Product.objects.all().delete()
Catalog.objects.all().delete()
Channel.objects.all().delete()
Expand Down Expand Up @@ -462,18 +462,18 @@ def test_get_api_produtcs(self, mock_get):
]

# RequestException check HTTPLog
products_data, no_error = WhatsAppCloudType().get_api_products(channel, catalog)
products_data, no_error = WhatsAppCloudType().get_api_products(channel, catalog.facebook_catalog_id)
self.assertEqual(1, HTTPLog.objects.filter(log_type=HTTPLog.WHATSAPP_PRODUCTS_SYNCED).count())
self.assertFalse(no_error)
self.assertEqual([], products_data)

# should be empty list with an error flag if fail with API
products_data, no_error = WhatsAppCloudType().get_api_products(channel, catalog)
products_data, no_error = WhatsAppCloudType().get_api_products(channel, catalog.facebook_catalog_id)
self.assertFalse(no_error)
self.assertEqual([], products_data)

# success no error and list
products_data, no_error = WhatsAppCloudType().get_api_products(channel, catalog)
products_data, no_error = WhatsAppCloudType().get_api_products(channel, catalog.facebook_catalog_id)
self.assertTrue(no_error)
self.assertEqual(["foo", "bar"], products_data)

Expand All @@ -484,7 +484,7 @@ def test_get_api_produtcs(self, mock_get):
)

# success no error and pagination
products_data, no_error = WhatsAppCloudType().get_api_products(channel, catalog)
products_data, no_error = WhatsAppCloudType().get_api_products(channel, catalog.facebook_catalog_id)
self.assertTrue(no_error)
self.assertEqual(["foo", "bar"], products_data)

Expand Down

0 comments on commit 21b90e1

Please sign in to comment.