import pytest
import StringIO
from datetime import datetime, timedelta
import mock

from django.conf import settings
from django.core.management import call_command
from django.core.files.storage import default_storage as storage

from olympia import amo
from olympia.addons.management.commands import approve_addons
from olympia.addons.models import AddonFeatureCompatibility
from olympia.addons.tasks import migrate_preliminary_to_full
from olympia.amo.tests import addon_factory, AMOPaths, version_factory
from olympia.devhub.models import AddonLog
from olympia.editors.models import ReviewerScore
from olympia.versions.models import Version


# Where to monkeypatch "lib.crypto.tasks.sign_addons" so it's correctly mocked.
SIGN_ADDONS = 'olympia.addons.management.commands.sign_addons.sign_addons'


# Test the "sign_addons" command.

def test_no_overridden_settings(monkeypatch):
    assert not settings.SIGNING_SERVER
    assert not settings.PRELIMINARY_SIGNING_SERVER

    def no_endpoint(ids, **kwargs):
        assert not settings.SIGNING_SERVER
        assert not settings.PRELIMINARY_SIGNING_SERVER

    monkeypatch.setattr(SIGN_ADDONS, no_endpoint)
    call_command('sign_addons', 123)


def test_override_SIGNING_SERVER_setting(monkeypatch):
    """You can override the SIGNING_SERVER settings."""
    assert not settings.SIGNING_SERVER

    def signing_server(ids, **kwargs):
        assert settings.SIGNING_SERVER == 'http://example.com'

    monkeypatch.setattr(SIGN_ADDONS, signing_server)
    call_command('sign_addons', 123, signing_server='http://example.com')


def test_override_PRELIMINARY_SIGNING_SERVER_setting(monkeypatch):