def test_bb_project_init_create_new_project(kwargs, expected):
    """Ensures BitbarProject.create_project() is able to create a project if
    the name is unique. Otherwise, the default behavior is raise an exception,
    unless the permit_duplicate flag is set.
    """
    if expected is MozbitbarProjectException:
        with pytest.raises(MozbitbarProjectException):
            project = BitbarProject('new', **kwargs)
    else:
        project = BitbarProject('new', **kwargs)
        assert project.project_id is not None
        assert project.project_name == expected['project_name']
        assert project.project_type == expected['project_type']
예제 #2
0
def initialize_bitbar(recipe, credentials=None):
    """Initializes the Bitbar Project object.

    Given a valid recipe, this method will instantiate and return an instance
    of the BitbarProject object, used to interact with Bitbar and execute
    actions.

    Args:
        recipe (:obj:`Recipe`): An instance of a Recipe object.

    Raises:
        SystemExit: If provided Recipe object contains invalid project
            parameters, or Testdroid credentials were missing or invalid.
    """
    if credentials:
        logger.info('Credential file specified.')
        with open(credentials, 'r') as f:
            loaded_credentials = yaml.load(f.read())
        for c in loaded_credentials:
            recipe.project_arguments.update(c)

    logger.info('Bitbar project initialization...')
    try:
        logger.info('Bitbar project object successfully initialized.')
        return BitbarProject(recipe.project, **recipe.project_arguments)
    except (MozbitbarProjectException, MozbitbarCredentialException) as e:
        logger.critical(e.message)
        sys.exit(1)
def test_bb_project_init_existing(kwargs, expected):
    """Ensures BitbarProject is able to retrieve existing project by id
    or name, and process resulting output of the (mocked) call.

    Directly tests methods involved in:
        - initialization of project
        - retrieve and set project parameters by id or name
    """
    if expected is MozbitbarProjectException:
        with pytest.raises(MozbitbarProjectException):
            BitbarProject('existing', **kwargs)

    else:
        project = BitbarProject('existing', **kwargs)
        if expected.get('id'):
            assert project.project_id == expected.get('id')
        if expected.get('project_name'):
            assert project.project_name == expected.get('name')
예제 #4
0
def initialize_project():
    # initialize a dummy project for when the __init__ method is not
    # under test.
    kwargs = {
        'project_name': 'mock_project',
        'TESTDROID_USERNAME': '******',
        'TESTDROID_PASSWORD': '******',
        'TESTDROID_APIKEY': 'MOCK_ENVIRONMENT_VALUE_TEST',
        'TESTDROID_URL': 'https://www.mock_test_env_var.com',
    }
    return BitbarProject('existing', **kwargs)
def test_bb_project_status(project_status, expected):
    """Ensures BitbarProject raises an exception on invalid project status.
    """
    if expected is MozbitbarProjectException:
        with pytest.raises(MozbitbarProjectException):
            BitbarProject(project_status)