from __future__ import absolute_import

from changes.lib import project_lib
from changes.models.plan import PlanStatus
from changes.testutils import TestCase


class AutogeneratedPlansTestCase(TestCase):
    def test_false(self):
        project = self.create_project()
        assert not project_lib.contains_active_autogenerated_plan(project)

    def test_false_value(self):
        project = self.create_project()
        plan = self.create_plan(project, status=PlanStatus.active)
        self.create_option(item_id=plan.id, name='bazel.autogenerate', value='0')
        assert not project_lib.contains_active_autogenerated_plan(project)

    def test_false_inactive(self):
        project = self.create_project()
        plan = self.create_plan(project, status=PlanStatus.inactive)
        self.create_option(item_id=plan.id, name='bazel.autogenerate', value='1')
        assert not project_lib.contains_active_autogenerated_plan(project)

    def test_true(self):
        project = self.create_project()
        plan = self.create_plan(project, status=PlanStatus.active)
        self.create_option(item_id=plan.id, name='bazel.autogenerate', value='1')
        assert project_lib.contains_active_autogenerated_plan(project)

    def test_true_multiple(self):
        project = self.create_project()
        plan = self.create_plan(project, status=PlanStatus.active)
        self.create_option(item_id=plan.id, name='bazel.autogenerate', value='0')
        plan = self.create_plan(project, status=PlanStatus.active)
        self.create_option(item_id=plan.id, name='bazel.autogenerate', value='1')
        assert project_lib.contains_active_autogenerated_plan(project)
