# -*- coding: utf-8 -*-
import unittest
from django.test import TestCase

from .policy import ALLOWED_LICENSES
from .check import check_policy, check_policy_js


class OpenSourcePolicySanityTest(TestCase):
    def allowed_licenses(self):
        return ";".join(ALLOWED_LICENSES)

    def test_allowed_licences(self):
        """There should be no NetworkCopyleft or StrongCopyleft licenses in the ALLOWED_LICENSES

        THINK TWICE BEFORE REMOVING THINGS FROM THIS LIST, BECAUSE YOU MIGHT OPEN US UP FOR
        LAWSUITS AND COPYRIGHT CLAIMS
        """
        all_allowed_licenses = " ".join(ALLOWED_LICENSES)
        self.assertNotIn("GNU General Public License", all_allowed_licenses)
        self.assertNotIn("Affero", all_allowed_licenses)
        self.assertNotIn("AGPL", all_allowed_licenses)
        self.assertNotIn("Open Software License", all_allowed_licenses)
        self.assertNotIn("RPSL", all_allowed_licenses)
        self.assertNotIn("RealNetworks Public Source License", all_allowed_licenses)
        self.assertNotIn("Watcom", all_allowed_licenses)
        self.assertNotIn("Sybase Open Watcom Public License", all_allowed_licenses)


class LicencePolicyCheck(unittest.TestCase):
    "Check if opensource policy applies"

    def test_opensource_policy(self):
        result = check_policy()
        self.assertTrue(result.ok, result.msg)

    def test_opensource_policy_js(self):
        result = check_policy_js()
        if result is None:
            self.skipTest("This repo has no package.json")
        else:
            self.assertTrue(result.ok, result.msg)
