def equals_and_hash_expected_difference_test():
    """
    quick check to make sure I am not causing problems by feeding a dict
    to frozenset.
    """
    bi_builder_C = _create_build_info_builder()
    module_builder_C = Module.Builder(id=Id(group_id="defend.against.fruit",
                                            artifact_id="pointy-stick",
                                            version="5.2"),
                                      properties={'ape', 'lets swing'})
    bi_builder_C.add_module(module_builder_C.build())
    build_info_C = bi_builder_C.build()

    bi_builder_D = _create_build_info_builder()
    module_builder_D = Module.Builder(
        id=Id(group_id="defend.against.fruit",
              artifact_id="pointy-stick",
              version="5.2"),
        properties={'ape', 'lets make funny faces'})
    bi_builder_D.add_module(module_builder_D.build())
    build_info_D = bi_builder_D.build()

    assert build_info_C != build_info_D, \
        "different property values should result in unequal BuildInfo " \
        "instances"

    assert build_info_C.__hash__() != build_info_D.__hash__(), \
        "different property values should result in unequal hash values"
    def from_json_data(cls, json_data):
        agent = nested_object_from_json_data(
            json_data,
            'agent',
            Agent.from_json_data)

        build_agent = nested_object_from_json_data(
            json_data,
            'buildAgent',
            Agent.from_json_data)

        build_retention = nested_object_from_json_data(
            json_data,
            'buildRetention',
            BuildRetention.from_json_data)

        builder = BuildInfo.Builder(
            version=json_data['version'],
            name=json_data['name'],
            number=json_data['number'],
            type=json_data['type'],
            started=json_data['started'],
            duration_millis=json_data['durationMillis'],
            artifactory_principal=json_data['artifactoryPrincipal'],
            agent=agent,
            build_agent=build_agent,
            build_retention=build_retention
        )

        modules = [Module.from_json_data(x) for x in json_data['modules']]

        for module in modules:
            builder.add_module(module)

        return builder.build()
def null_vs_empty_dependencies_test():
    """
    Missing artifacts or dependencies should be None not an empty
    collection.
    """
    module_builder = module_test_helper.create_module_builder(
        treat_none_as_empty=False)

    module = module_builder.build()

    eq_(module.artifacts, None, "artifacts start as None")
    eq_(module.dependencies, None, "dependencies start as None")

    #Take the domain object down to wire-level format
    json_string = json.dumps(module.as_json_data, sort_keys=True, indent=4)

    #Read the wire-level data back into a domain object
    json_data_2 = json.loads(json_string)
    re_hydrated_module = Module.from_json_data(json_data_2)

    eq_(re_hydrated_module.artifacts, None,
        "artifacts of None survives round-trip on the wire")

    eq_(re_hydrated_module.dependencies, None,
        "artifacts of None survives round-trip on the wire")
Esempio n. 4
0
def temp_fn_11():
    """
    pre-existing module file with no dependencies, matching id and
    different properties
    """

    module_output_file_name = _create_temp_file_name()

    early_properties = {'skunk': 'stinks', 'raccoon': 'cleans food'}
    early_module = Module(id=helper.module_id,
                          properties=early_properties,
                          artifacts=(helper.bdist_artifact, ),
                          dependencies=None)
    _write_module_file(early_module, module_output_file_name)

    #conditions prepared, now perform action under test and assert results
    _execute(
        module_id=helper.module_id,
        dist_files_tuple_array=[
            ('sdist', None, helper.sdist_file),
            #        ('bdist', None, bdist_file),
            ('bdist_egg', None, helper.egg_file)
        ],
        freeze_file=helper.full_requirements_file,
        module_file=module_output_file_name,
        force_dependency_rebuild=False,
        force_clean=False,
        expected_module_properties=early_properties,
        expected_artifacts=(helper.bdist_artifact, helper.sdist_artifact,
                            helper.egg_artifact),
        expected_dependencies=(helper.colorama_dependency,
                               helper.mock_dependency, helper.nose_dependency))
    os.unlink(module_output_file_name)
def single_module_with_missing_module_attributes_test():
    module_builder = Module.Builder(
        id=None,
        #id=Id(
        #   group_id="defend.against.fruit",
        #   artifact_id="pointy-stick",
        #   version="5.2"),
        properties={
            'banana': 'monkey love',
            'orange': 'gorilla color'
        })

    module_test_helper.add_some_artifacts(module_builder)

    module_test_helper.add_some_dependencies(module_builder)

    module = module_builder.build()

    bi_builder = _create_build_info_builder()
    bi_builder.add_module(module)

    build_info = bi_builder.build()

    module_test_helper.round_trip_to_and_from_wire_format(
        build_info, BuildInfo.from_json_data, _assert_basic_attributes)
def null_vs_empty_dependencies_test():
    """
    Missing artifacts or dependencies should be None not an empty
    collection.
    """
    module_builder = module_test_helper.create_module_builder(
        treat_none_as_empty=False)

    module = module_builder.build()

    eq_(module.artifacts, None, "artifacts start as None")
    eq_(module.dependencies, None, "dependencies start as None")

    #Take the domain object down to wire-level format
    json_string = json.dumps(module.as_json_data, sort_keys=True, indent=4)

    #Read the wire-level data back into a domain object
    json_data_2 = json.loads(json_string)
    re_hydrated_module = Module.from_json_data(json_data_2)

    eq_(re_hydrated_module.artifacts, None,
        "artifacts of None survives round-trip on the wire")

    eq_(re_hydrated_module.dependencies, None,
        "artifacts of None survives round-trip on the wire")
def merge_module_info_files(build_info_files, env_info):
    if env_info.build_agent_name and env_info.build_agent_version:
        build_agent = Agent(
            name=env_info.build_agent_name,
            version=env_info.build_agent_version)
    else:
        build_agent = None

    bi_builder = BuildInfo.Builder(
        version=env_info.build_version,
        name=env_info.build_name,
        number=env_info.build_number,
        type='GENERIC',
        started=ISOTime.now().as_str,
        build_agent=build_agent,
        artifactory_principal="admin",
        agent=Agent(name="defend_against_fruit", version="5.2"),
        build_retention=BuildRetention(
            count=-1,
            delete_build_artifacts=False))

    if build_info_files:
        for build_info_file in build_info_files:
            with open(build_info_file, 'r') as f:
                bi_builder.add_module(Module.from_json_data(
                    json.loads(f.read())))

    return bi_builder.build()
Esempio n. 8
0
def _build_info(args):
    my_build_number = args.number
    my_build_name = args.name

    bi_builder = BuildInfo.Builder(
        version="2.2.2",
        name=my_build_name,
        number=my_build_number,
        # Looks like valid values are "GENERIC", "MAVEN", "ANT", "IVY" and
        # "GRADLE".
        type='GENERIC',
        # Looks like time format is very specific
        started="2013-03-21T10:49:01.143-0500",
        duration_millis=10000,
        artifactory_principal="dude",
        agent=Agent(name="defend_against_fruit", version="5.2"),
        build_agent=Agent(name="TeamCity", version="1.3"),
        build_retention=BuildRetention(
            count=-1,
            delete_build_artifacts=False,
            # Is this for TeamCity "pinned" builds?
            build_numbers_not_to_be_discarded=[111, 999]))
    module_builder = Module.Builder(id=Id(
        group_id="python", artifact_id="daf_fruit_dist", version="1.2.15"))
    module_builder.add_artifact(
        type=PYTHON_SDIST,
        name="daf_fruit_dist-1.2.15.tar.gz",
        sha1="0a66f5619bcce7a441740e154cd97bad04189d86",
        md5="2a17acbb714e7b696c58b4ca6e07c611")
    module_builder.add_artifact(
        type=PYTHON_FREEZE,
        name="daf_fruit_dist-1.2.15-requirements.txt",
        sha1="06e5f0080b6b15704be9d78e801813d802a90625",
        md5="254c0e43bbf5979f8b34ff0428ed6931")
    module_builder.add_dependency(
        type=PYTHON_SDIST,
        id=Id(group_id="python", artifact_id="nose", version="1.2.1"),
        sha1="02cc3ffdd7a1ce92cbee388c4a9e939a79f66ba5",
        md5="735e3f1ce8b07e70ee1b742a8a53585a")

    bi_builder.add_module(module_builder.build())
    build_info = bi_builder.build()
    logging.debug(build_info_to_text(build_info))

    publish_build_info(username=args.username,
                       password=args.password,
                       repo_base_url=args.base_url,
                       build_info=build_info,
                       verify_cert=not args.ignore_cert_errors)
def create_module_builder(
        artifacts=None,
        dependencies=None,
        treat_none_as_empty=True):

    module_builder = Module.Builder(
        id=Id(
            group_id="defend.against.fruit",
            artifact_id="pointy-stick",
            version="5.2"),
        properties={'banana': 'monkey love', 'orange': 'gorilla color'},
        artifacts=artifacts,
        dependencies=dependencies,
        treat_none_as_empty=treat_none_as_empty
    )
    return module_builder
Esempio n. 10
0
def temp_fn_07():
    """pre-existing module file with non-matching module id"""

    module_output_file_name = _create_temp_file_name()

    early_properties = {'skunk': 'stinks', 'raccoon': 'cleans food'}
    early_module = Module(id=helper.alternate_module_id,
                          properties=early_properties,
                          artifacts=(helper.bdist_artifact, ),
                          dependencies=(helper.colorama_dependency, ))
    _write_module_file(early_module, module_output_file_name)

    exception_caught = False

    #conditions prepared, now perform action under test and assert results
    try:
        _execute(
            module_id=helper.module_id,
            dist_files_tuple_array=[
                ('sdist', None, helper.sdist_file),
                #        ('bdist', None, bdist_file),
                ('bdist_egg', None, helper.egg_file)
            ],
            freeze_file=helper.full_requirements_file,
            module_file=module_output_file_name,
            force_dependency_rebuild=False,
            force_clean=False,
            expected_module_properties=early_properties,
            expected_artifacts=(helper.bdist_artifact, helper.sdist_artifact,
                                helper.egg_artifact),
            expected_dependencies=(helper.colorama_dependency, ))
    except ValueError:
        exception_caught = True

    assert exception_caught, "Expect ValueError to be encountered"
    os.unlink(module_output_file_name)
Esempio n. 11
0
def _read_module_file(module_file):
    with open(module_file, 'r') as f:
        module_as_json = f.read()
        json_data = json.loads(module_as_json)
        module = Module.from_json_data(json_data)
    return module
def _read_module_file(module_file):
    with open(module_file, 'r') as f:
        module_as_json = f.read()
        json_data = json.loads(module_as_json)
        module = Module.from_json_data(json_data)
    return module