Skip to content

Commit

Permalink
Merge pull request #97 from edelwi/master
Browse files Browse the repository at this point in the history
fix for issue #96
  • Loading branch information
Krukov authored Jul 31, 2023
2 parents 346a56a + 6eb29d0 commit 662b6a1
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 2 additions & 2 deletions amocrm/v2/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _model(self):

@property
def _manager(self):
return self.__manager or self._model.objects
return self.__manager or self._model.objects if self._model else None

def on_get(self, data):
return self._manager.get(object_id=data)
Expand All @@ -131,7 +131,7 @@ def __init__(self, data, instance, model, manager=None, links=LinksInteraction()
self._data = data
self._model = model
self._instance = instance
self._manager = manager or model.objects
self._manager = manager or model.objects if model else None
self._links = links

def __iter__(self):
Expand Down
24 changes: 24 additions & 0 deletions tests/data/companies.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,27 @@
"_links": {"self": {"href": "https://exmaple.amocrm.ru/api/v4/companies/1"}},
"_embedded": {"tags": []},
}

DETAIL_INFO_2 = {
"id": 1,
"name": "АО Копыта и рыла",
"responsible_user_id": 504141,
"group_id": 0,
"created_by": 504141,
"updated_by": 504141,
"created_at": 1582117331,
"updated_at": 1586361223,
"closest_task_at": None,
"custom_fields_values": [
{
"field_id": 3,
"field_name": "Телефон",
"field_code": "PHONE",
"field_type": "multitext",
"values": [{"value": "123213", "enum_id": 1, "enum": "WORK"}],
}
],
"account_id": 10,
"_links": {"self": {"href": "https://exmaple.amocrm.ru/api/v4/companies/1"}},
"_embedded": {"tags": []},
}
14 changes: 13 additions & 1 deletion tests/test_contacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from amocrm.v2 import Contact, exceptions, filters

from .data.companies import DETAIL_INFO as COMPANY_DETAIL_INFO
from .data.companies import DETAIL_INFO as COMPANY_DETAIL_INFO, DETAIL_INFO_2
from .data.contacts import (CREATE_DATA, DETAIL_INFO, LIST_PAGE_1, LIST_PAGE_2,
UPDATE)
from .data.users import DETAIL_INFO as USER_DETAIL_INFO
Expand Down Expand Up @@ -75,3 +75,15 @@ def test_update(response_mock):
contact.last_name = "e"
contact.tags.add("tag")
contact.save()


def test_repr(response_mock):
response_mock.add("GET", "https://test.amocrm.ru/api/v4/contacts/3", match_querystring=False, json=DETAIL_INFO)
response_mock.add("GET",
"https://test.amocrm.ru/api/v4/companies/1?with=contacts%2Ccustomers%2Cleads%2Ctags",
match_querystring=False,
json=DETAIL_INFO_2)
contact = Contact.objects.get(3)

representation = repr(contact)
assert representation

0 comments on commit 662b6a1

Please sign in to comment.