Repository navigation
Expand file tree
/
Copy pathtest_contacts.py
More file actions
136 lines (97 loc) · 3.57 KB
/
Copy pathtest_contacts.py
File metadata and controls
136 lines (97 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
import pytest
from hubspot.crm.contacts import PublicObjectSearchRequest
CONTACT_PROPERTIES = {
"email": "rRocket@TestCompany.net",
"lastname": "Rocket",
"firstname": "Racoon"
}
@pytest.fixture
def create_contact(api_client):
contact = api_client.crm.contacts.basic_api.create(CONTACT_PROPERTIES)
yield contact
api_client.crm.contacts.basic_api.archive(contact_id=contact.id)
@pytest.fixture
def create_company(api_client):
properties = {
"domain": "TestCompany.net",
"name": "TestCompany",
}
company = api_client.crm.companies.basic_api.create(properties)
yield company
api_client.crm.companies.basic_api.archive(company_id=company.id)
def get_or_create_contact_associated_with_company(api_client, create_company):
contact_data = {
"associations": [
{
"to": {"id": create_company.id},
"types": [
{
"associationCategory": "HUBSPOT_DEFINED",
"associationTypeId": 1
}
]
}
],
"properties": CONTACT_PROPERTIES
}
public_object_search_request = PublicObjectSearchRequest(
filter_groups=[
{
"filters": [
{
"value": contact_data["properties"]["email"],
"propertyName": "email",
"operator": "EQ"
}
]
}
]
)
contact_response = api_client.crm.contacts.search_api.do_search(public_object_search_request)
if contact_response.results:
return contact_response.results[0]
else:
return api_client.crm.contacts.basic_api.create(contact_data)
def test_create_contact_with_company_association(api_client, create_company):
contact = get_or_create_contact_associated_with_company(api_client, create_company)
assert contact
def test_contact__create(api_client):
contact = api_client.crm.contacts.basic_api.create(CONTACT_PROPERTIES)
assert contact
api_client.crm.contacts.basic_api.archive(contact_id=contact.id)
def test_contact__get_page(api_client):
result = api_client.crm.companies.basic_api.get_page()
assert result
def test_contact__get_by_id(api_client, create_contact):
result = api_client.crm.contacts.basic_api.get_by_id(create_contact.id)
assert result
def test_contact__get_all(api_client):
result = api_client.crm.contacts.get_all()
assert result
def test_contact__update(api_client, create_contact):
simple_public_object_input = {
"properties": {
"firstname": "updated_name"
}
}
result = api_client.crm.contacts.basic_api.update(create_contact.id, simple_public_object_input)
assert result.properties["firstname"] == simple_public_object_input["properties"]["firstname"]
def test_contact__archive(api_client, create_contact):
result = api_client.crm.contacts.basic_api.archive(create_contact.id)
assert result is None
def test_contact__do_search(api_client, create_contact):
public_object_search_request = PublicObjectSearchRequest(
filter_groups=[
{
"filters": [
{
"value": "rRocket@TestCompany.net",
"propertyName": "email",
"operator": "EQ"
}
]
}
]
)
contact = api_client.crm.contacts.search_api.do_search(public_object_search_request)
assert contact.results