Skip to content

Commit 2333008

Browse files
Tag line fixes (#273)
1 parent 321a614 commit 2333008

File tree

2 files changed

+55
-2
lines changed

2 files changed

+55
-2
lines changed

tcsocket/app/processing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ async def _set_labels(conn, company_id, labels):
9696

9797
def _get_special_extra_attr(extra_attributes: List[ExtraAttributeModel], machine_name, attr_type):
9898
"""
99-
Find special extra attributes suitable for tag_line and primary_description.
99+
Find special extra attributes suitable for tag_line and primary_description. Uses the first attr of type attr_type
100+
if that machine_name is not found.
100101
"""
101102
eas = [ea for ea in extra_attributes if ea.type == attr_type]
102103
if eas:
@@ -159,7 +160,7 @@ async def contractor_set(
159160
primary_description, ex_attrs = _get_special_extra_attr(ex_attrs, 'primary_description', 'text_extended')
160161
data.update(
161162
extra_attributes=[ea_.dict(exclude={'sort_index'}) for ea_ in sorted(ex_attrs, key=attrgetter('sort_index'))],
162-
tag_line=tag_line,
163+
tag_line=tag_line and tag_line[:255], # Field limit; TC should only send through the first 100 chars.
163164
primary_description=primary_description,
164165
)
165166
v = await conn.execute(

tests/test_set_contractor.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,58 @@ async def test_extra_attributes(cli, db_conn, company):
201201
assert obj['extra_attributes'][2]['value'] == '2032-06-01'
202202

203203

204+
async def test_tag_line_from_short_text(cli, db_conn, company):
205+
eas = [
206+
{
207+
'machine_name': 'whatever',
208+
'type': 'text_short',
209+
'name': 'Should be tag line?',
210+
'value': 'Should be tag line.',
211+
'sort_index': 0
212+
},
213+
]
214+
r = await signed_request(
215+
cli,
216+
f'/{company.public_key}/webhook/contractor',
217+
id=123,
218+
deleted=False,
219+
first_name='Fred',
220+
extra_attributes=eas
221+
)
222+
assert r.status == 201, await r.text()
223+
curr = await db_conn.execute(sa_contractors.select())
224+
result = await curr.first()
225+
assert result.id == 123
226+
assert result.first_name == 'Fred'
227+
assert result.tag_line == 'Should be tag line.'
228+
229+
230+
async def test_shorten_tag_line(cli, db_conn, company):
231+
eas = [
232+
{
233+
'machine_name': 'whatever',
234+
'type': 'text_short',
235+
'name': 'Should be tag line?',
236+
'value': 'Should be tag line.' * 50,
237+
'sort_index': 0
238+
},
239+
]
240+
r = await signed_request(
241+
cli,
242+
f'/{company.public_key}/webhook/contractor',
243+
id=123,
244+
deleted=False,
245+
first_name='Fred',
246+
extra_attributes=eas
247+
)
248+
assert r.status == 201, await r.text()
249+
curr = await db_conn.execute(sa_contractors.select())
250+
result = await curr.first()
251+
assert result.id == 123
252+
assert result.first_name == 'Fred'
253+
assert len(result.tag_line) == 255
254+
255+
204256
async def test_extra_attributes_special(cli, db_conn, company):
205257
eas = [
206258
{

0 commit comments

Comments
 (0)