def test_locales_validation_still_present_after_update(
        fs, get_sync_translations_env):
    get_sync_translations_env['Translations']['B3'] = 'update'
    get_sync_translations_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = TranslationsSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Translations')
    synchronizer.sync()
    synchronizer.save(f'{fs.root_path}/test.xlsx')

    wb = load_workbook(f'{fs.root_path}/test.xlsx')
    assert any(
        (data_validation.formula1 == "'General Information'!$AB$2:$AB$98"
         and data_validation.sqref.ranges[0].coord == 'G2:G3') for
        data_validation in wb['Translations'].data_validations.dataValidation)
def translations_sync(client, config, input_file, stats, save):
    synchronizer = TranslationsSynchronizer(client, config.silent, stats)
    synchronizer.open(input_file, 'Translations')
    synchronizer.sync()
    if save:
        synchronizer.save(input_file)
    return synchronizer
def test_create_translation(
    fs,
    get_sync_translations_env,
    mocked_new_translation_response,
    mocked_responses,
):
    get_sync_translations_env['Translations']['B4'] = 'create'
    get_sync_translations_env['Translations']['G4'] = 'JA (Japanese)'
    get_sync_translations_env['Translations'][
        'H4'] = 'This is the japanese translation'
    get_sync_translations_env['Translations']['I4'] = 'Enabled'
    get_sync_translations_env.save(f'{fs.root_path}/test.xlsx')

    stats = SynchronizerStats()
    synchronizer = TranslationsSynchronizer(
        client=ConnectClient(
            use_specs=False,
            api_key='ApiKey SU:123',
            endpoint='https://localhost/public/v1',
        ),
        silent=True,
        stats=stats,
    )
    mocked_responses.add(
        method='GET',
        url=
        'https://localhost/public/v1/localization/contexts?eq(instance_id,PRD-276-377-545)&limit=1&offset=0',
        headers={
            'Content-Range': 'items 0-0/1',
        },
        json=[{
            'id': 'LCX-1111-2222-3333',
            'instance_id': 'PRD-276-377-545',
            'name': 'My product',
        }],
    )
    mocked_responses.add(
        method='POST',
        url='https://localhost/public/v1/localization/translations',
        status=201,
        match=[
            responses.matchers.json_params_matcher({
                "auto": {
                    "enabled": True
                },
                "context": {
                    "id": "LCX-1111-2222-3333"
                },
                "description": "This is the japanese translation",
                "locale": {
                    "id": "JA"
                },
            }),
        ],
        json=mocked_new_translation_response,
    )

    synchronizer.open(f'{fs.root_path}/test.xlsx', 'Translations')
    synchronizer.sync()
    synchronizer.save(f'{fs.root_path}/test.xlsx')

    assert stats['Translations'].get_counts_as_dict() == {
        'processed': 3,
        'created': 1,
        'updated': 0,
        'deleted': 0,
        'skipped': 2,
        'errors': 0,
    }
    wb = load_workbook(f'{fs.root_path}/test.xlsx')
    assert wb['Translations']['A4'].value == 'TRN-1079-0833-9999'
    assert wb['Translations']['C4'].value == 'PRD-276-377-545'
    assert wb['Translations']['E4'].value == 'VA-392-495'
    assert wb['Translations']['K4'].value == 'inactive'
    assert wb['Translations']['L4'].value == 'No'
    assert wb['Translations']['M4'].value == '2020-10-29T12:00:00+00:00'
    assert wb['Translations']['N4'].value == '2020-10-29T12:00:00+00:00'