Skip to content

Commit

Permalink
wip: add en_US language to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marta197 committed Mar 10, 2023
1 parent f5eafbd commit 5d55a4f
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 12 deletions.
5 changes: 3 additions & 2 deletions tests/erp_service_double.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def add_dummy_template(self, xml_id, id, **overrides):
'def_subject',
'def_subject_es_ES',
'def_subject_ca_ES',
'def_subject_en_US',
'name',
'def_body_text',
'def_to',
Expand Down Expand Up @@ -61,7 +62,7 @@ async def load_template(self, id):
except KeyError:
raise XmlIdNotFound(f"No template found with id {id}")

supported_languages = 'ca_ES', 'es_ES'
supported_languages = 'ca_ES', 'es_ES', 'en_US'
for lang in supported_languages:
template.setdefault('def_subject_'+lang, '')

Expand All @@ -77,7 +78,7 @@ async def save_template(self, id, **kwds):
if 'id' in kwds: del kwds['id']
if 'model_int_name' in kwds: del kwds['model_int_name']

supported_languages = 'ca_ES', 'es_ES'
supported_languages = 'ca_ES', 'es_ES', 'en_US'
for lang in supported_languages:
subject_lang = 'def_subject_'+lang
kwds.setdefault(subject_lang, '')
Expand Down
26 changes: 17 additions & 9 deletions tests/erp_service_testsuite.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@

existing_template = ns(
# An existing template with semantic id
erp_id = 183, # Extremely fragile
xml_id = 'giscedata_switching.notification_atr_M1_01',
name = 'ATR M101: Solicitud de modificación cambio de titular',
erp_id = 189, # Extremely fragile
xml_id = 'giscedata_switching.notification_atr_M1_06',
name = 'ATR M106: Solicitud de anulación al distribuidor',
model = 'giscedata.switching',
subject_ca_ES =
'Som Energia: Canvi de titular. Verificació de dades. '
'Contracte ${object.polissa_ref_id.name}',
'${object.company_id.name}: Sol·licitada anulació de la modificació de contracte '
'd\'accés la seva distribuidora ${object.partner_id.name}',
subject_es_ES =
'Som Energia: Cambio de titular. Verificación de datos. '
'Contrato ${object.polissa_ref_id.name}',
'${object.company_id.name}: Solicitada anulación de la modificación de contrato '
'de acceso a su distribuidora ${object.partner_id.name}',
subject_en_US = 'Holi :)',
)
def edited_values(**kwds):
result = ns(
def_subject = "New subject",
def_subject = "New subject us", # Why new subject us?
def_subject_es_ES = "New subject es",
def_subject_ca_ES = "New subject ca",
def_subject_en_US = "New subject us",
def_to = "New To",
def_cc = "New CC",
def_bcc = "New BCC",
Expand Down Expand Up @@ -86,20 +88,22 @@ async def test__fixture__existing_template(self, erp_backdoor, erp_translations)

translations = erp_translations.list('def_subject')

assert set(translations.keys()) == set(('ca_ES', 'es_ES')), (
assert set(translations.keys()) == set(('ca_ES', 'es_ES', 'en_US')), (
f"The template {existing_template.xml_id} is expected to have 'def_subject' "
f"translated to all and just the supported languages."
)
assert translations == {
'ca_ES': existing_template.subject_ca_ES,
'es_ES': existing_template.subject_es_ES,
'en_US': existing_template.subject_en_US,
}, (
f"Subject translations changed in the ERP template {existing_template.xml_id} "
f"\nPlease, update existing_template.subject_*"
)
assert erp_translations.list('def_body_text').keys() == {
'es_ES',
'ca_ES',
'en_US',
}, (
f"The template {existing_template.xml_id} is expected to have 'def_body_text' "
f"translated to all and just the supported languages."
Expand Down Expand Up @@ -292,6 +296,7 @@ async def test__save_template__emptySubjectTranslation_removesIt(self, erp_servi

assert erp_translations.list('def_subject') == {
'es_ES': edited.def_subject_es_ES,
'en_US': edited.def_subject_en_US,
# And the ca_ES is missing
}

Expand All @@ -309,6 +314,7 @@ async def test__save_template__missingSubjectTranslations_recreated(self, erp_se
assert erp_translations.list('def_subject') == {
'es_ES': edited.def_subject_es_ES,
'ca_ES': edited.def_subject_ca_ES,
'en_US': edited.def_subject_en_US,
}

async def test__save_template__bodyTranslation_cloneSuppoerted(self, erp_service, erp_translations):
Expand All @@ -322,6 +328,7 @@ async def test__save_template__bodyTranslation_cloneSuppoerted(self, erp_service
assert erp_translations.list('def_body_text') == {
'es_ES': edited.def_body_text,
'ca_ES': edited.def_body_text,
'en_US': edited.def_body_text,
}

async def test__save_template__bodyTranslation_cloneMissingSupported(self, erp_service, erp_translations):
Expand All @@ -337,6 +344,7 @@ async def test__save_template__bodyTranslation_cloneMissingSupported(self, erp_s
assert erp_translations.list('def_body_text') == {
'es_ES': edited.def_body_text,
'ca_ES': edited.def_body_text,
'en_US': edited.def_body_text,
}

async def test__save_template__bodyTranslation_cloneExistingUnsupported(self, erp_service, erp_translations):
Expand Down
2 changes: 2 additions & 0 deletions tests/test_erp_service_double.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,10 @@ def erp_service():
def_subject = "Untranslated subject",
def_subject_es_ES = existing_template.subject_es_ES,
def_subject_ca_ES = existing_template.subject_ca_ES,
def_subject_en_US = existing_template.subject_en_US,
def_body_text_es_ES = "Previous Body",
def_body_text_ca_ES = "Previous Body",
def_body_text_en_US = "Previous Body",
name = existing_template.name,
model_int_name = existing_template.model,
)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ async def test_template_schema():
assert template.def_body_text == 'def_body_text_module.id'
assert set(template.headers().keys()) == set([
'def_subject', 'def_subject_es_ES', 'def_subject_ca_ES',
'def_to', 'def_cc', 'def_bcc', 'lang',
'def_subject_en_US', 'def_to', 'def_cc', 'def_bcc', 'lang',
])
assert set(template.meta_data().keys()) == set(['name', 'model_int_name', 'id'])
assert template.body_text() == {
Expand Down
2 changes: 2 additions & 0 deletions uiqmako_api/schemas/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class Template(BaseModel):
def_subject: str
def_subject_es_ES: str
def_subject_ca_ES: str
def_subject_en_US: str
def_body_text: str
def_to: str
def_cc: str
Expand All @@ -84,6 +85,7 @@ def headers(self):
'lang': self.lang,
'def_subject_es_ES': self.def_subject_es_ES,
'def_subject_ca_ES': self.def_subject_ca_ES,
'def_subject_en_US': self.def_subject_en_US,
}

def meta_data(self):
Expand Down
1 change: 1 addition & 0 deletions uiqmako_api/utils/erp_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class ErpService(object):
_supported_languages = [
'es_ES',
'ca_ES',
'en_US'
]

def __init__(self, erpclient):
Expand Down

1 comment on commit 5d55a4f

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests Skipped Failures Errors Time
106 6 💤 0 ❌ 0 🔥 2m 15s ⏱️

Please sign in to comment.