예제 #1
0
def test_delete_glossary(capsys):
    # setup
    glossary_id = "test-{}".format(uuid.uuid4())
    translate_v3_create_glossary.create_glossary(PROJECT_ID,
                                                 GLOSSARY_INPUT_URI,
                                                 glossary_id)

    # assert
    translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
    out, _ = capsys.readouterr()
    assert "Deleted:" in out
def test_delete_glossary(capsys):
    # setup
    glossary_id = "must-start-with-letters-" + str(uuid.uuid1())
    translate_v3_create_glossary.create_glossary(PROJECT_ID,
                                                 GLOSSARY_INPUT_URI,
                                                 glossary_id)

    # assert
    translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
    out, _ = capsys.readouterr()
    assert "Deleted:" in out
예제 #3
0
def glossary():
    """Get the ID of a glossary available to session (do not mutate/delete)."""
    glossary_id = "must-start-with-letters-" + str(uuid.uuid1())
    translate_v3_create_glossary.create_glossary(PROJECT_ID,
                                                 GLOSSARY_INPUT_URI,
                                                 glossary_id)

    yield glossary_id

    try:
        translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
    except Exception:
        pass
예제 #4
0
def glossary():
    """Get the ID of a glossary available to session (do not mutate/delete)."""
    glossary_id = "test-{}".format(uuid.uuid4())
    translate_v3_create_glossary.create_glossary(
        PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
    )

    yield glossary_id

    try:
        translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
    except Exception:
        pass
예제 #5
0
def test_create_glossary(capsys):
    glossary_id = "test-{}".format(uuid.uuid4())
    translate_v3_create_glossary.create_glossary(PROJECT_ID,
                                                 GLOSSARY_INPUT_URI,
                                                 glossary_id)
    out, _ = capsys.readouterr()
    # assert
    assert "Created:" in out
    assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out

    # clean up after use
    try:
        translate_v3_delete_glossary.delete_glossary(PROJECT_ID, glossary_id)
    except Exception:
        pass
예제 #6
0
def glossary():
    """Get the ID of a glossary available to session (do not mutate/delete)."""
    glossary_id = "test-{}".format(uuid.uuid4())
    translate_v3_create_glossary.create_glossary(PROJECT_ID,
                                                 GLOSSARY_INPUT_URI,
                                                 glossary_id)

    yield glossary_id

    # cleanup
    @backoff.on_exception(backoff.expo, (DeadlineExceeded, GoogleAPICallError),
                          max_time=60)
    def delete_glossary():
        try:
            translate_v3_delete_glossary.delete_glossary(
                PROJECT_ID, glossary_id)
        except NotFound as e:
            # Ignoring this case.
            print("Got NotFound, detail: {}".format(str(e)))

    delete_glossary()
예제 #7
0
def test_create_glossary(capsys):
    try:
        glossary_id = "test-{}".format(uuid.uuid4())
        translate_v3_create_glossary.create_glossary(
            PROJECT_ID, GLOSSARY_INPUT_URI, glossary_id
        )
        out, _ = capsys.readouterr()
        # assert
        assert "Created:" in out
        assert "gs://cloud-samples-data/translation/glossary_ja.csv" in out
    finally:
        # cleanup
        @backoff.on_exception(
            backoff.expo, (DeadlineExceeded, GoogleAPICallError), max_time=60
        )
        def delete_glossary():
            try:
                translate_v3_delete_glossary.delete_glossary(
                    PROJECT_ID, glossary_id)
            except NotFound as e:
                # Ignoring this case.
                print("Got NotFound, detail: {}".format(str(e)))
        delete_glossary()