<commit_before>#!/usr/bin/env python2.5
#
# Copyright 2011 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""Tests for GCITask create/edit view.
"""


import datetime

from soc.modules.gci.logic.helper.notifications import (
    DEF_NEW_TASK_COMMENT_SUBJECT)
from soc.modules.gci.models.task import GCITask
from soc.modules.gci.models.profile import GCIProfile

from tests.gci_task_utils import GCITaskHelper
from tests.profile_utils import GCIProfileHelper
from tests.test_utils import GCIDjangoTestCase


class TaskCreateViewTest(GCIDjangoTestCase):
  """Tests GCITask create/edit view.
  """

  def setUp(self):
    """Creates a published task for self.org.
    """
    super(TaskCreateViewTest, self).setUp()
    self.init()

  def createTask(self, status=None, org=None, mentor=None, student=None):
    if not mentor:
      profile_helper = GCIProfileHelper(self.gci, self.dev_test)
      mentor = profile_helper.createOtherUser(
          '<EMAIL>').createMentor(self.org)

    if not student:
      profile_helper = GCIProfileHelper(self.gci, self.dev_test)
      student = profile_helper.createOtherUser(
          '<EMAIL>').createStudent()

    if not org:
      org = self.org

    if not status:
      status = 'Open'

    gci_task_helper = GCITaskHelper(self.program)
    return gci_task_helper.createTask(status, org, mentor, student)

  def assertFullEditTemplatesUsed(self, response):
    """Asserts that all the task creation base templates along with full edit
    template is used.
    """
    self.assertGCITemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gci/task_create/base.html')
    self.assertTemplateUsed(
        response, 'v2/modules/gci/task_create/_full_edit.html')

  def assertPostClaimEditTemplatesUsed(self, response):
    """Asserts that all the task creation base templates along with post claim
    edit template is used.
    """
    self.assertGCITemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gci/task_create/base.html')
    self.assertTemplateUsed(
        response, 'v2/modules/gci/task_create/_post_claim_edit.html')

  def testCreateTaskBeforeOrgsAnnouncedForNoRole(self):
    """Tests the task creation view before the program is public for user with
    no role.
    """
    self.timeline.orgSignup()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createProfile()

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet and no role to create tasks
    self.assertResponseForbidden(response)

  def testCreateTaskBeforeOrgsAnnouncedForOrgAdmin(self):
    """Tests the task creation view before the program is public for org admin.
    """
    self.timeline.orgSignup()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createOrgAdmin(self.org)

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet
    self.assertResponseForbidden(response)

  def testCreateTaskBeforeOrgsAnnouncedForMentor(self):
    """Tests the task creation view before the program is public for org admin.
    """
    self.timeline.orgSignup()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createMentor(self.org)

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet
    self.assertResponseForbidden(response)

  def testCreateTaskBeforeOrgsAnnouncedForStudent(self):
    """Tests the task creation view before the program is public for org admin.
    """
    self.timeline.orgSignup()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createStudent()

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet
    self.assertResponseForbidden(response)

  def testCreateTaskAfterClaimEndForNoRole(self):
    """Tests the task creation view after the task claim deadline for user with
    no role.
    """
    self.timeline.taskClaimEnded()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createProfile()

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet and no role to create tasks
    self.assertResponseForbidden(response)

  def testCreateTaskAfterClaimEndForOrgAdmin(self):
    """Tests the task creation view after the task claim deadline for org admin.
    """
    self.timeline.taskClaimEnded()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createOrgAdmin(self.org)

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet
    self.assertResponseForbidden(response)

  def testCreateTaskAfterClaimEndForMentor(self):
    """Tests the task creation view after the task claim deadline for mentor.
    """
    self.timeline.taskClaimEnded()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createMentor(self.org)

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet
    self.assertResponseForbidden(response)

  def testCreateTaskAfterClaimEndForStudent(self):
    """Tests the task creation view after the task claim deadline for student.
    """
    self.timeline.taskClaimEnded()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createStudent()

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet
    self.assertResponseForbidden(response)
<commit_msg>Comments more accurate.<commit_after>#!/usr/bin/env python2.5
#
# Copyright 2011 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.


"""Tests for GCITask create/edit view.
"""


import datetime

from soc.modules.gci.logic.helper.notifications import (
    DEF_NEW_TASK_COMMENT_SUBJECT)
from soc.modules.gci.models.task import GCITask
from soc.modules.gci.models.profile import GCIProfile

from tests.gci_task_utils import GCITaskHelper
from tests.profile_utils import GCIProfileHelper
from tests.test_utils import GCIDjangoTestCase


class TaskCreateViewTest(GCIDjangoTestCase):
  """Tests GCITask create/edit view.
  """

  def setUp(self):
    """Creates a published task for self.org.
    """
    super(TaskCreateViewTest, self).setUp()
    self.init()

  def createTask(self, status=None, org=None, mentor=None, student=None):
    if not mentor:
      profile_helper = GCIProfileHelper(self.gci, self.dev_test)
      mentor = profile_helper.createOtherUser(
          '<EMAIL>').createMentor(self.org)

    if not student:
      profile_helper = GCIProfileHelper(self.gci, self.dev_test)
      student = profile_helper.createOtherUser(
          '<EMAIL>').createStudent()

    if not org:
      org = self.org

    if not status:
      status = 'Open'

    gci_task_helper = GCITaskHelper(self.program)
    return gci_task_helper.createTask(status, org, mentor, student)

  def assertFullEditTemplatesUsed(self, response):
    """Asserts that all the task creation base templates along with full edit
    template is used.
    """
    self.assertGCITemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gci/task_create/base.html')
    self.assertTemplateUsed(
        response, 'v2/modules/gci/task_create/_full_edit.html')

  def assertPostClaimEditTemplatesUsed(self, response):
    """Asserts that all the task creation base templates along with post claim
    edit template is used.
    """
    self.assertGCITemplatesUsed(response)
    self.assertTemplateUsed(response, 'v2/modules/gci/task_create/base.html')
    self.assertTemplateUsed(
        response, 'v2/modules/gci/task_create/_post_claim_edit.html')

  def testCreateTaskBeforeOrgsAnnouncedForNoRole(self):
    """Tests the task creation view before the program is public for user with
    no role.
    """
    self.timeline.orgSignup()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createProfile()

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet and no role to create tasks
    self.assertResponseForbidden(response)

  def testCreateTaskBeforeOrgsAnnouncedForOrgAdmin(self):
    """Tests the task creation view before the program is public for org admin.
    """
    self.timeline.orgSignup()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createOrgAdmin(self.org)

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet
    self.assertResponseForbidden(response)

  def testCreateTaskBeforeOrgsAnnouncedForMentor(self):
    """Tests the task creation view before the program is public for org admin.
    """
    self.timeline.orgSignup()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createMentor(self.org)

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet
    self.assertResponseForbidden(response)

  def testCreateTaskBeforeOrgsAnnouncedForStudent(self):
    """Tests the task creation view before the program is public for org admin.
    """
    self.timeline.orgSignup()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createStudent()

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet
    self.assertResponseForbidden(response)

  def testCreateTaskAfterClaimEndForNoRole(self):
    """Tests the task creation view after the task claim deadline for user with
    no role.
    """
    self.timeline.taskClaimEnded()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createProfile()

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation has not started yet and no role to create tasks
    self.assertResponseForbidden(response)

  def testCreateTaskAfterClaimEndForOrgAdmin(self):
    """Tests the task creation view after the task claim deadline for org admin.
    """
    self.timeline.taskClaimEnded()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createOrgAdmin(self.org)

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation is not open
    self.assertResponseForbidden(response)

  def testCreateTaskAfterClaimEndForMentor(self):
    """Tests the task creation view after the task claim deadline for mentor.
    """
    self.timeline.taskClaimEnded()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createMentor(self.org)

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation is not open
    self.assertResponseForbidden(response)

  def testCreateTaskAfterClaimEndForStudent(self):
    """Tests the task creation view after the task claim deadline for student.
    """
    self.timeline.taskClaimEnded()

    profile_helper = GCIProfileHelper(self.gci, self.dev_test)
    profile_helper.createStudent()

    url = '/gci/task/create/' + self.org.key().name()
    response = self.get(url)

    # Task creation is not open
    self.assertResponseForbidden(response)

{'fraction_non_alphanumeric': 0.09775692013999364, 'fraction_numerical': 0.0022271714922048997, 'mean_word_length': 3.79336637438048, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3309170', 'n_tokens_mistral': 3821, 'n_tokens_neox': 3727, 'n_words': 985}