# Path: gg/main.py
# class Config:
#     def __init__(self):
#         self.verbose = False  # default
#         self.configfile = DEFAULT_CONFIGFILE
#         try:
#             self.repo = get_repo()
#         except git.InvalidGitRepositoryError as exception:
#             error_out(f"{exception.args[0]} is not a git repository")
# 
# Path: gg/builtins/bugzilla.py
# @cli.group()
# @click.option(
#     "-u",
#     "--bugzilla-url",
#     default=BUGZILLA_URL,
#     help=f"URL to Bugzilla instance (default: {BUGZILLA_URL})",
# )
# @pass_config
# def bugzilla(config, bugzilla_url):
#     """General tool for connecting to Bugzilla. The default URL
#     is that for bugzilla.mozilla.org but you can override that.
#     Once you're signed in you can use those credentials to automatically
#     fetch bug summaries even of private bugs.
#     """
#     config.bugzilla_url = bugzilla_url


import json
from click.testing import CliRunner
from gg.main import Config
from gg.builtins import bugzilla

    requestsmock.get(
        "https://example.com/rest/whoami?api_key=secret",
        content=json.dumps(
            {"real_name": "John Doe", "name": "peterbe@example.com", "id": 1}
        ).encode("utf-8"),
    )

    runner = CliRunner()
    config = Config()
    config.configfile = temp_configfile
    config.bugzilla_url = "https://example.com"
    result = runner.invoke(bugzilla.test, [], obj=config)
    if result.exception:
        raise result.exception
    assert result.exit_code == 0
    assert not result.exception
    assert "John Doe" in result.output


def test_logout(temp_configfile, mocker):

    with open(temp_configfile, "w") as f:
        saved = {"BUGZILLA": {"api_key": "secret"}}
        json.dump(saved, f)

    runner = CliRunner()
    config = Config()
    config.configfile = temp_configfile
    config.bugzilla_url = "https://example.com"

# Path: gg/main.py
# class Config:
#     def __init__(self):
#         self.verbose = False  # default
#         self.configfile = DEFAULT_CONFIGFILE
#         try:
#             self.repo = get_repo()
#         except git.InvalidGitRepositoryError as exception:
#             error_out(f"{exception.args[0]} is not a git repository")
# 
# Path: gg/builtins/bugzilla.py
# @cli.group()
# @click.option(
#     "-u",
#     "--bugzilla-url",
#     default=BUGZILLA_URL,
#     help=f"URL to Bugzilla instance (default: {BUGZILLA_URL})",
# )
# @pass_config
# def bugzilla(config, bugzilla_url):
#     """General tool for connecting to Bugzilla. The default URL
#     is that for bugzilla.mozilla.org but you can override that.
#     Once you're signed in you can use those credentials to automatically
#     fetch bug summaries even of private bugs.
#     """
#     config.bugzilla_url = bugzilla_url


# Path: tests/test_bugzilla.py
import json
from click.testing import CliRunner
from gg.main import Config
from gg.builtins import bugzilla


    requestsmock.get(
        "https://example.com/rest/whoami?api_key=secret",
        content=json.dumps(
            {"real_name": "John Doe", "name": "peterbe@example.com", "id": 1}
        ).encode("utf-8"),
    )

    runner = CliRunner()
    config = Config()
    config.configfile = temp_configfile
    config.bugzilla_url = "https://example.com"
    result = runner.invoke(bugzilla.test, [], obj=config)
    if result.exception:
        raise result.exception
    assert result.exit_code == 0
    assert not result.exception
    assert "John Doe" in result.output


def test_logout(temp_configfile, mocker):

    with open(temp_configfile, "w") as f:
        saved = {"BUGZILLA": {"api_key": "secret"}}
        json.dump(saved, f)

    runner = CliRunner()
    config = Config()
    config.configfile = temp_configfile
    config.bugzilla_url = "https://example.com"

    result = runner.invoke(bugzilla.logout, [], obj=config)