Exemple #1
0
def in_process(monkeypatch, safe_environ, request, config):
    """Set up an environment to run moz-phab within the current process."""
    monkeypatch.setattr("mozphab.config.config", config)
    monkeypatch.setattr("mozphab.git.config", config)
    monkeypatch.setattr("mozphab.mercurial.config", config)
    # Make sure other tests didn't leak and mess up the module-level
    # global variables :/
    monkeypatch.setattr(environment, "DEBUG", True)
    monkeypatch.setattr(environment, "HAS_ANSI", False)
    # Constructing the Mercurial() object modifies os.environ for all tests.
    # Disable update checking.  It modifies the program on disk which we do /not/ want
    # to do during a test run.
    monkeypatch.setattr(updater, "check_for_updates", mock.MagicMock())

    # Disable calls to sys.exit() at the end of the script.  Re-raise errors instead
    # to make test debugging easier.
    def reraise(*args, **kwargs):
        raise

    monkeypatch.setattr(sys, "exit", reraise)

    # Disable uploading a new commit title and summary to Phabricator.  This operation
    # is safe to skip and doing so makes it easier to test other conduit call sites.
    monkeypatch.setattr(submit, "update_revision_description",
                        mock.MagicMock())

    # Modify user_data object to not touch the file
    user.USER_INFO_FILE = mock.Mock()
    user.USER_INFO_FILE.exists.return_value = False
    user.user_data = user.UserData()
    user.user_data.update_from_dict(
        dict(
            user_code="#" * 32,
            is_employee=True,
            installation_id="#" * 32,
            last_check=time.time(),
        ))

    # Allow to define the check_call_by_line function in the testing module
    def check_call_by_line_static(*args, **kwargs):
        return ["Revision URI: http://example.test/D123"]

    def call_conduit_static(self, *args):
        # Return alice as the only valid reviewer name from Phabricator.
        # See https://phabricator.services.mozilla.com/api/user.search
        return [{"userName": "******"}]

    call_conduit = getattr(request.module, "call_conduit", call_conduit_static)
    monkeypatch.setattr(conduit.ConduitAPI, "call", call_conduit)

    def read_json_field_local(self, *args):
        if args[0][0] == "phabricator.uri":
            return "http://example.test"
        elif args[0][0] == "repository.callsign":
            return "TEST"

    read_json_field = getattr(request.module, "read_json_field",
                              read_json_field_local)
    monkeypatch.setattr(repository, "read_json_field", read_json_field)
Exemple #2
0
def user_data(m_file):
    m_file.exists.return_value = False
    return user.UserData()