Skip to content
This repository was archived by the owner on Aug 18, 2023. It is now read-only.

Commit

Permalink
Merge pull request #42 from klaviyo/202106_fix_identify_call
Browse files Browse the repository at this point in the history
fix identify call
  • Loading branch information
remstone7 authored Jun 15, 2021
2 parents a318c56 + c1fc4b1 commit cff5edb
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## CHANGELOG

### 3.1.3
- Fix identify ID call.

### 3.1.2
- Added support for Campaigns API

Expand Down
2 changes: 1 addition & 1 deletion klaviyo/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version__ = '3.1.2'
__version__ = '3.1.3'
from .api import Klaviyo
7 changes: 5 additions & 2 deletions klaviyo/public.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ def identify(self, email=None, external_id=None, properties={}, is_test=False):
if not isinstance(properties, dict):
properties = {}

if email: properties['email'] = email
if id: properties['id'] = external_id
if email:
properties['email'] = email

if external_id:
properties['id'] = external_id

params = {
self.TOKEN: self.public_token,
Expand Down
17 changes: 17 additions & 0 deletions tests/fixtures/public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from mock import patch
import pytest
from klaviyo.public import Public
from .api_helper import KlaviyoAPIFixture

class PublicFixture(KlaviyoAPIFixture):
@property
def api(self):
return Public(**self.API_SETTINGS)

@pytest.fixture
def mock_email(self):
return 'thomas.jefferson@mailinator.com'

@pytest.fixture
def mock_external_id(self):
return 123
19 changes: 19 additions & 0 deletions tests/test_public.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
from .fixtures.public import PublicFixture
from klaviyo.exceptions import (
KlaviyoException
)


class TestPublicApi(PublicFixture):
def test_identify_with_id(self, mock_email, mock_external_id, mock_request):
self.api.identify(mock_email, mock_external_id)
mock_request.assert_called_once()

def test_identify_without_id(self, mock_email, mock_request):
self.api.identify(mock_email)
mock_request.assert_called_once()

def test_identify_without_identification(self):
with pytest.raises(KlaviyoException):
self.api.identify()

0 comments on commit cff5edb

Please # to comment.