import pytest

from semantic_release import ci_checks
from semantic_release.errors import CiVerificationError


def test_circle_should_pass_if_branch_is_master_and_no_pr(monkeypatch):
    monkeypatch.setenv('CIRCLE_BRANCH', 'master')
    monkeypatch.setenv('CI_PULL_REQUEST', '')

    assert ci_checks.circle('master')


def test_circle_should_pass_if_branch_is_correct_and_no_pr(monkeypatch):
    monkeypatch.setenv('CIRCLE_BRANCH', 'other-branch')
    monkeypatch.setenv('CI_PULL_REQUEST', '')

    assert ci_checks.circle('other-branch')


def test_circle_should_raise_ci_verification_error_for_wrong_branch(monkeypatch):
    monkeypatch.setenv('CIRCLE_BRANCH', 'other-branch')
    monkeypatch.setenv('CI_PULL_REQUEST', '')

    with pytest.raises(CiVerificationError):
        ci_checks.circle('master')


def test_circle_should_raise_ci_verification_error_for_pr(monkeypatch):
    monkeypatch.setenv('CIRCLE_BRANCH', 'other-branch')
    monkeypatch.setenv('CI_PULL_REQUEST', 'http://the-url-of-the-pr')

    with pytest.raises(CiVerificationError):
        ci_checks.circle('master')

Add tests for circle ci checks