コード例 #1
0
def test_successful_publish(col_id, col_version, publication_message,
                            legacy_username, legacy_password):
    # GIVEN the latest version of a collection available
    with Neb.get(verbose=True,
                 env="staging",
                 col_id=col_id,
                 col_version="latest") as coll_dir:
        # WHEN we make an edit
        with edit_collXML(coll_dir) as collection:
            elem = collection.xpath("//md:title",
                                    namespaces=COLLECTION_NSMAP)[0]
            elem.text = "a different collection title {}".format(
                random.randint(0, 99999))

        # THEN we are able to successfully publish it
        stdout, stderr, returncode = Neb.run(
            "publish",
            "staging",
            coll_dir,
            "--message",
            publication_message,
            "--username",
            legacy_username,
            "--password",
            legacy_password,
        )
        assert "Great work!!! =D" in stderr
コード例 #2
0
def test_get_help():
    # GIVEN neb

    # WHEN we run `neb get --help`
    with Neb.get(help=True) as help:
        # THEN the usage message is displayed
        assert "Usage: neb get " in help
        assert "Options:" in help
        assert "--help" in help
コード例 #3
0
def test_publish_help():
    # GIVEN neb

    # WHEN we run `neb publish --help`
    with Neb.publish(help=True) as help:
        # THEN the usage message is displayed
        assert "Usage: neb publish " in help
        assert "Options:" in help
        assert "--help" in help
コード例 #4
0
def test_get_no_col_version(neb_env, col_id):
    # GIVEN neb, an environment, and a collection id

    # WHEN we run `neb get env col_id`
    stdout, stderr, returncode = Neb.run("get", neb_env, col_id)

    # THEN neb exits with an error and the usage message is displayed
    assert returncode > 0
    assert "Usage: neb get " in stderr
    assert re.compile("Error: Missing argument [\"']COL_VERSION[\"']").search(stderr)
コード例 #5
0
def test_get_no_col_id(neb_env):
    # GIVEN neb and an environment

    # WHEN we run `neb get env`
    stdout, stderr, returncode = Neb.run("get", neb_env)

    # THEN neb exits with an error and the usage message is displayed
    assert returncode > 0
    assert "Usage: neb get " in stderr
    assert re.compile("Error: Missing argument [\"']COL_ID[\"']").search(stderr)
コード例 #6
0
def test_get_no_env():
    # GIVEN neb

    # WHEN we run `neb get`
    stdout, stderr, returncode = Neb.run("get")

    # THEN neb exits with an error and the usage message is displayed
    assert returncode > 0
    assert "Usage: neb get " in stderr
    assert re.compile("Error: Missing argument [\"']ENV[\"']").search(stderr)
コード例 #7
0
def test_publish_no_commit_message(neb_env):
    # GIVEN neb, an environment, and a content dir
    try:
        with TemporaryDirectory() as content_dir:

            # WHEN we run `neb publish env content_dir`
            stdout, stderr, returncode = Neb.run("publish",
                                                 neb_env,
                                                 content_dir,
                                                 timeout=1)
    except subprocess.TimeoutExpired as e:
        # THEN neb prompts for a publication message and waits for user to enter it until it times out
        assert "Publication message:" in str(e.stdout)
コード例 #8
0
def test_get_col_minor_version(insecure, neb_env, col_id, col_version, snapshot):
    # GIVEN neb, an environment name, a collection id, a collection version, and the snapshot tool
    snapshot_name = get_neb_snapshot_name(col_id, col_version)

    # WHEN we run `neb get --verbose env col_id col_version`
    with Neb.get(
        verbose=True,
        insecure=insecure,
        env=neb_env,
        col_id=col_id,
        col_version=col_version,
        input="y",
    ) as zip_dir:
        # THEN the complete zip is downloaded and matches the snapshot
        snapshot.assert_file_or_dir_match(zip_dir, snapshot_name)
コード例 #9
0
def test_get_col_latest(insecure, neb_env, col_id, col_minimum_version):
    # GIVEN neb, an environment name, a collection id, and a collection minimum version

    # WHEN we run `neb get --verbose env col_id latest`
    with Neb.get(
        verbose=True, insecure=insecure, env=neb_env, col_id=col_id, col_version="latest"
    ) as zip_dir:
        # THEN the complete zip is downloaded and has a collection.xml
        # with the minimum version or higher
        path = join(zip_dir, "collection.xml")
        with open(path) as file:
            colxml = file.read()

    collection = ET.fromstring(colxml)
    metadata = collection.find("{http://cnx.rice.edu/collxml}metadata")
    version_string = metadata.find("{http://cnx.rice.edu/mdml}version").text
    version = parse_version(version_string)
    minimum_version = parse_version(col_minimum_version)
    assert version >= minimum_version
コード例 #10
0
def test_publish_invalid_cnxml(
    neb_env,
    col_id,
    col_version,
    publication_message,
    expected_validation_errors,
    snapshot,
    legacy_username,
    legacy_password,
):
    # GIVEN neb, an environment, a content dir, a publication message,
    # the expected errors, and the snapshot tool
    snapshot_name = get_neb_snapshot_name(col_id, col_version)

    with TemporaryDirectory() as content_dir:
        snapshot.extract(snapshot_name, content_dir)

        # WHEN we run `neb publish env content_dir publication_message`
        stdout, stderr, returncode = Neb.run(
            "publish",
            neb_env,
            content_dir,
            "--message",
            publication_message,
            "--username",
            legacy_username,
            "--password",
            legacy_password,
        )

    # THEN neb exits with an error and the CNXML validation failure message is displayed

    assert returncode > 0
    assert "Stop the Press!!! =()" in stderr

    for validation_error in expected_validation_errors:
        assert validation_error in stderr