Esempio n. 1
0
def test_bug_initial_build_id_comment(mocker, bug_fixture_prefetch, code_wrap,
                                      bid):
    """Test parsing of initial_build_id from comment"""
    if code_wrap:
        bid_str = f"`{bid}`"
    else:
        bid_str = bid

    data = copy.deepcopy(bug_fixture_prefetch)
    data["comments"][0][
        "text"] = f"Found while fuzzing mozilla-central rev {bid_str}"
    bug = EnhancedBug(bugsy=None, **data)

    # Disable verification
    mocker.patch("bugmon.bug._get_url", return_value=0)

    # Set fixed branch
    bug._branch = "mozilla-central"

    if bid == BUILD_ID:
        assert bug.initial_build_id == bid.split("-")[1]
    elif bid in (REV, SHORT_REV):
        assert bug.initial_build_id == bid
    else:
        assert bug.initial_build_id == data["creation_time"].split("T")[0]
Esempio n. 2
0
def test_bug_get_comments_prefetch(bug_fixture_prefetch, comment_fixture):
    """Test that get_attachments with cached data returns correct attacment"""
    bug = EnhancedBug(bugsy=None, **bug_fixture_prefetch)
    comments = bug.get_comments()
    assert len(comments) == 1
    raw_data = json.loads(json.dumps(comments[0], default=sanitize_bug))
    assert raw_data == comment_fixture
Esempio n. 3
0
def test_bug_command_setter_append(bug_fixture_prefetch):
    """Test appending commands to whiteboard"""
    bug = EnhancedBug(bugsy=None, **bug_fixture_prefetch)
    commands = bug.commands
    commands["fake_command"] = None
    bug.commands = commands
    assert bug.whiteboard == "[bugmon:confirmed,verify,fake_command]"
Esempio n. 4
0
def test_bug_command_setter_empty_whiteboard(bug_fixture_prefetch):
    """Test initialization of bugmon command on whiteboard"""
    data = copy.deepcopy(bug_fixture_prefetch)
    data["whiteboard"] = ""
    bug = EnhancedBug(bugsy=None, **data)
    bug.commands = {"fake_command": None}

    assert bug.whiteboard == "[bugmon:fake_command]"
Esempio n. 5
0
def test_bug_command_setter_remove_command(bug_fixture_prefetch):
    """Test removing command from whiteboard"""
    data = copy.deepcopy(bug_fixture_prefetch)
    data["whiteboard"] = "[something-else][bugmon:verify]"
    bug = EnhancedBug(bugsy=None, **data)
    bug.commands = {}

    assert bug.whiteboard == "[something-else]"
Esempio n. 6
0
def test_bug_command_setter_empty_bugmon(bug_fixture_prefetch):
    """Test setting command where bugmon exists on whiteboard with no commands"""
    data = copy.deepcopy(bug_fixture_prefetch)
    data["whiteboard"] = "[bugmon:]"
    bug = EnhancedBug(bugsy=None, **data)
    bug.commands = {"fake_command": None}

    assert bug.whiteboard == "[bugmon:fake_command]"
Esempio n. 7
0
def test_bug_version(mocker, bug_fixture_prefetch, use_trunk):
    """Simple test of version helper"""
    if use_trunk:
        bug = EnhancedBug(bugsy=None, **bug_fixture_prefetch)
        mocker.patch("bugmon.bug._get_milestone", return_value=81)
    else:
        data = copy.deepcopy(bug_fixture_prefetch)
        data["version"] = 81
        bug = EnhancedBug(bugsy=None, **data)

    assert bug.version == 81
Esempio n. 8
0
def test_bug_branch(mocker, bug_fixture_prefetch, alias, version):
    """Test that branch matches alias of current version"""
    mocker.patch("bugmon.bug.Fetcher.resolve_esr",
                 side_effect=["esr78", "esr68"])
    bug = EnhancedBug(bugsy=None, **bug_fixture_prefetch)

    # Set fixed central version and bug version
    bug._central_version = 81
    bug._bug["version"] = version

    assert bug.branch == alias
Esempio n. 9
0
def test_bug_initial_build_id_whiteboard(mocker, bug_fixture_prefetch, bid):
    """Test parsing of initial_build_id from whiteboard"""
    data = copy.deepcopy(bug_fixture_prefetch)
    data["whiteboard"] = f"[bugmon:origRev={bid}]"
    bug = EnhancedBug(bugsy=None, **data)

    # Disable verification
    mocker.patch("bugmon.bug._get_url", return_value=0)

    # Set fixed branch
    bug._branch = "central"

    assert bug.initial_build_id == bid
Esempio n. 10
0
def test_monitor_is_actionable(mocker, tmp_path, bug_fixture, command):
    """Test that BugMonitorTask.is_actionable matches expected state"""
    mocker.patch("bugmon.BugMonitor.is_supported", return_value=True)
    monitor = BugMonitorTask("key", "root", tmp_path, dry_run=True)
    bug_fixture["whiteboard"] = f"[bugmon:{command}"
    bug = EnhancedBug(bugsy=None, **bug_fixture)

    # Change status to avoid unspecified actions
    bug.status = "RESOLVED"

    if command is None:
        assert monitor.is_actionable(bug) is False
    else:
        assert monitor.is_actionable(bug) is True
Esempio n. 11
0
def test_bug_cache_bug(mocker, bug_fixture, comment_fixture,
                       attachment_fixture):
    """Test EnhancedBug.cache_bug()"""
    data = copy.deepcopy(bug_fixture)
    bug = EnhancedBug(bugsy=True, **data)

    attachments = [LocalAttachment(**attachment_fixture)]
    mocker.patch("bugmon.bug.EnhancedBug.get_attachments",
                 return_value=attachments)
    comments = [LocalComment(**comment_fixture)]
    mocker.patch("bugmon.bug.EnhancedBug.get_comments", return_value=comments)

    cached_bug = EnhancedBug.cache_bug(bug)
    assert cached_bug.get_attachments() == attachments
    assert cached_bug.get_comments() == comments
Esempio n. 12
0
def test_bug_remote_methods(bug_fixture_prefetch, method):
    """Test that EnhancedBug with prefetch enabled throws on remote methods"""
    bug = EnhancedBug(bugsy=None, **bug_fixture_prefetch)
    with pytest.raises(TypeError) as e:
        getattr(bug, method)(None)

    assert str(e.value) == "Method not supported when using a cached bug"
Esempio n. 13
0
def test_bug_branches(mocker, bug_fixture_prefetch):
    """Test branch enumeration"""
    mocker.patch("bugmon.bug.Fetcher.resolve_esr",
                 side_effect=["esr78", "esr68"])
    bug = EnhancedBug(bugsy=None, **bug_fixture_prefetch)
    # Set fixed central version
    bug._central_version = 81

    for alias, version in bug.branches.items():
        if alias == "central":
            assert version == 81
        elif alias == "beta":
            assert version == 80
        elif alias == "release":
            assert version == 79
        elif alias == "esr78":
            assert version == 78
        elif alias == "esr68":
            assert version == 68
Esempio n. 14
0
def test_bug_build_flags(bug_fixture_prefetch):
    """Simple test of bug.build_flags"""
    data = copy.deepcopy(bug_fixture_prefetch)
    data["comments"][0][
        "text"] = "Built with --enable-address-sanitizer --enable-debug"
    bug = EnhancedBug(bugsy=None, **data)

    assert bug.build_flags.asan
    assert bug.build_flags.debug
    assert bug.build_flags.tsan is False
    assert bug.build_flags.valgrind is False
Esempio n. 15
0
def test_monitor_fetch_bug(mocker, tmp_path, bug_fixture):
    """Test bug retrieval and iteration"""
    bug_response = {"bugs": [bug_fixture]}
    mocker.patch("bugsy.Bugsy.request", return_value=bug_response)
    mocker.patch("bugmon.BugMonitor.is_supported", return_value=True)

    cached_bug = EnhancedBug(None, **bug_fixture)
    mocker.patch("bugmon.bug.EnhancedBug.cache_bug", return_value=cached_bug)

    monitor = BugMonitorTask("key", "root", tmp_path, dry_run=True)
    result = list(monitor.fetch_bugs())
    assert len(result) == 1
    assert isinstance(result[0], EnhancedBug)
Esempio n. 16
0
def test_monitor_create_tasks_taskcluster(mocker, tmp_path, bug_fixture):
    """Test task creation in simulated TC environment"""
    bug_response = {"bugs": [bug_fixture]}
    mocker.patch("bugsy.Bugsy.request", return_value=bug_response)
    mocker.patch("bugmon.BugMonitor.is_supported", return_value=True)
    mocker.patch(
        "bugmon_tc.monitor.monitor.BugMonitorTask.in_taskcluster",
        new_callable=mocker.PropertyMock,
        return_value=True,
    )

    cached_bug = EnhancedBug(None, **bug_fixture)
    mocker.patch("bugmon.bug.EnhancedBug.cache_bug", return_value=cached_bug)

    monitor = BugMonitorTask("key", "root", tmp_path, dry_run=True)

    mocked_create_task = mocker.patch("bugmon_tc.common.queue.createTask")
    monitor.create_tasks()
    assert mocked_create_task.call_count == 2
Esempio n. 17
0
    def fetch_artifact(self):
        """
        Retrieve artifact for processing

        :return: EnhancedBug
        """
        if self.in_taskcluster:
            task = queue.task(os.getenv("TASK_ID"))
            parent_id = task.get("taskGroupId")
            LOG.info(f"Fetching artifact: {parent_id} {self.artifact_path}")
            data = queue.getLatestArtifact(parent_id, self.artifact_path)
        else:
            with open(self.artifact_path, "r") as file:
                data = json.load(file)

        if data is None:
            raise ProcessorError("Failed to retrieve artifact")

        return EnhancedBug(bugsy=None, **data)
Esempio n. 18
0
def test_monitor_create_tasks_local(mocker, tmp_path, bug_fixture):
    """Test task creation"""
    bug_response = {"bugs": [bug_fixture]}
    mocker.patch("bugsy.Bugsy.request", return_value=bug_response)
    mocker.patch("bugmon.BugMonitor.is_supported", return_value=True)
    mocker.patch("bugmon_tc.monitor.tasks.slugId", return_value="1")
    mocker.patch(
        "bugmon_tc.monitor.monitor.BugMonitorTask.in_taskcluster",
        new_callable=mocker.PropertyMock,
        return_value=False,
    )

    cached_bug = EnhancedBug(None, **bug_fixture)
    mocker.patch("bugmon.bug.EnhancedBug.cache_bug", return_value=cached_bug)
    mocker.patch("bugmon_tc.monitor.monitor.slugId", return_value=123)

    monitor = BugMonitorTask("key", "root", tmp_path, dry_run=True)
    monitor.create_tasks()
    monitor_artifact = tmp_path / f"monitor-{bug_fixture['id']}-123.json"

    with monitor_artifact.open() as f:
        assert json.load(f) == bug_fixture
Esempio n. 19
0
def test_new_bug_prefetch_exclusion(bug_fixture_prefetch):
    """Test that new Bug with prefetch excludes attachments and comments"""
    result = EnhancedBug(None, **bug_fixture_prefetch).to_dict()
    assert "attachments" not in result
    assert "comments" not in result
Esempio n. 20
0
def test_new_bug_without_bugsy_or_prefetch(bug_fixture):
    """Test that new Bug without bugsy or cached data throws"""
    with pytest.raises(BugException):
        EnhancedBug(None, **bug_fixture)
Esempio n. 21
0
def test_new_bug(bug_fixture_prefetch):
    """Test that new Bug is the same as fixture"""
    result = EnhancedBug(None, **bug_fixture_prefetch).to_dict()
    for key in result:
        assert bug_fixture_prefetch[key] == result[key]
Esempio n. 22
0
def test_bug_central_version(mocker, bug_fixture_prefetch):
    """Simple test of bug.central_version"""
    mocker.patch("bugmon.bug._get_milestone", return_value=81)
    bug = EnhancedBug(bugsy=None, **bug_fixture_prefetch)

    assert bug.central_version == 81
Esempio n. 23
0
def test_bug_comment_zero(bug_fixture_prefetch):
    """Simple test of bug.comment_zero"""
    bug = EnhancedBug(bugsy=None, **bug_fixture_prefetch)

    assert bug.comment_zero == bug_fixture_prefetch["comments"][0]["text"]
Esempio n. 24
0
def test_bug_command_setter_replace(bug_fixture_prefetch):
    """Test replacing commands"""
    bug = EnhancedBug(bugsy=None, **bug_fixture_prefetch)
    bug.commands = {"fake_command": None}

    assert bug.whiteboard == "[bugmon:fake_command]"