import pytest
from .uploader import BadCodebergCredentialsException, CodebergUploader


def test_from_env(monkeypatch):
    monkeypatch.setenv("CODEBERG_USER", "user")
    monkeypatch.setenv("CODEBERG_TOKEN", "token")

    uploader = CodebergUploader.from_env()

    assert uploader.user == "user"
    assert uploader.token == "token"


def test_from_env_bad_credentials(monkeypatch):
    monkeypatch.setenv("CODEBERG_USER", "")
    monkeypatch.setenv("CODEBERG_TOKEN", "")

    with pytest.raises(BadCodebergCredentialsException):
        CodebergUploader.from_env()
