{"action":"created","comment":{"url":"https://api.github.com/repos/HackSoftware/Loki/pulls/comments/70598640","id":70598640,"diff_hunk":"@@ -0,0 +1,1020 @@\n+from django.core.urlresolvers import reverse\n+from post_office import mail\n+\n+from rest_framework import status\n+from rest_framework.test import APIClient\n+from test_plus.test import TestCase\n+from post_office.models import EmailTemplate\n+\n+from ..helper import date_increase, date_decrease\n+from ..models import (TeamMembership,\n+                      Season, Team, Invitation,\n+                      TeamMentorship)\n+\n+from seed import factories\n+\n+from faker import Factory\n+\n+faker = Factory.create()\n+\n+\n+class SkillTests(TestCase):\n+\n+    def setUp(self):\n+        self.skill = factories.SkillFactory()\n+\n+    def test_get_skill(self):\n+        url = reverse('hack_fmi:skills')\n+        response = self.client.get(url)\n+        self.assertEqual(response.status_code, status.HTTP_200_OK)\n+\n+\n+class MentorListAPIViewTest(TestCase):\n+\n+    def setUp(self):\n+        self.client = APIClient()\n+\n+        self.student = factories.StudentFactory(\n+            email=faker.email()\n+        )\n+        self.company = factories.HackFmiPartnerFactory()\n+        self.active_season = factories.SeasonFactory(\n+            is_active=True)\n+\n+        self.non_active_season = factories.SeasonFactory(\n+            is_active=False)\n+\n+        self.mentor = factories.MentorFactory(\n+            from_company=self.company\n+        )\n+        self.active_season.mentor_set.add(self.mentor)\n+        self.active_season.save()\n+\n+        self.mentor2 = factories.MentorFactory(\n+            from_company=self.company\n+        )\n+        self.non_active_season.mentor_set.add(self.mentor2)\n+        self.non_active_season.save()\n+\n+        self.mentor3 = factories.MentorFactory(\n+            from_company=self.company\n+        )\n+        self.active_season.mentor_set.add(self.mentor3)\n+        self.active_season.save()\n+\n+    def test_get_mentor_for_active_season(self):\n+        self.client.force_authenticate(self.student)\n+        url = reverse('hack_fmi:mentors')\n+        response = self.client.get(url)\n+        self.assertEqual(response.status_code, status.HTTP_200_OK)\n+        self.assertEqual(response.data[0]['name'], self.mentor.name)\n+\n+    def test_get_active_mentors_from_active_season(self):\n+        self.client.force_authenticate(self.student)\n+        url = reverse('hack_fmi:mentors')\n+        response = self.client.get(url)\n+        self.assertEqual(response.status_code, status.HTTP_200_OK)\n+        active_seasons = Season.objects.filter(is_active=True)\n+        self.assertEqual(active_seasons[0].mentor_set.count(), 2)\n+\n+\n+class SeasonViewTest(TestCase):\n+\n+    def setUp(self):\n+        self.client = APIClient()\n+\n+        self.company = factories.HackFmiPartnerFactory()\n+        self.mentor = factories.MentorFactory(\n+            from_company=self.company\n+        )\n+        self.active_season = factories.SeasonFactory(\n+            is_active=True)\n+\n+        self.non_active_season = factories.SeasonFactory(\n+            is_active=False)\n+\n+    def test_get_active_season(self):\n+        url = reverse('hack_fmi:season')\n+\n+        response = self.client.get(url)\n+\n+        self.assertEqual(response.status_code, status.HTTP_200_OK)\n+\n+        self.assertEqual(response.data['name'], self.active_season.name)\n+        self.assertEqual(Season.objects.filter(is_active=True).count(), 1)\n+\n+    def test_season_deactivates_automatically(self):\n+        new_active_season = factories.SeasonFactory(\n+            is_active=True,\n+        )\n+\n+        self.assertEqual(Season.objects.filter(is_active=True).count(), 1)\n+        self.assertFalse(Season.objects.get(name=self.active_season.name).is_active)\n+        self.assertTrue(Season.objects.get(name=new_active_season.name).is_active)\n+\n+\n+class PublicTeamViewTest(TestCase):\n+\n+    def setUp(self):\n+        self.client = APIClient()\n+\n+        self.active_season = factories.SeasonFactory(\n+            is_active=True)\n+\n+        self.room = factories.RoomFactory(season=self.active_season)\n+\n+        self.team = factories.TeamFactory(\n+            season=self.active_season,\n+            room=self.room)\n+\n+    def get_team_from_active_season(self):\n+        url = reverse('hack_fmi:public_teams')\n+\n+        response = self.client.get(url)\n+\n+        self.assertEqual(response.status_code, status.HTTP_200_OK)\n+        self.assertEqual(response.data[0]['name'], self.team.name)\n+\n+    def get_team_from_non_active_season(self):\n+        url = reverse('hack_fmi:public_teams')\n+\n+        non_active_season = factories.SeasonFactory(\n+            is_active=False)\n+        non_active_team = factories.TeamFactory(season=non_active_season)\n+\n+        response = self.client.get(url)\n+\n+        self.assertEqual(response.status_code, status.HTTP_200_OK)\n+        self.assertNotEqual(response.data[0]['name'], non_active_team.name)\n+\n+\n+class TeamAPITest(TestCase):\n+\n+    def setUp(self):\n+        self.client = APIClient()\n+        self.active_season = factories.SeasonFactory(\n+            is_active=True,\n+            make_team_dead_line=date_decrease(30),\n+            max_mentor_pick=100,\n+        )\n+\n+        self.non_active_season = factories.SeasonFactory(\n+            is_active=False)\n+\n+        self.room = factories.RoomFactory(season=self.active_season)\n+\n+        self.team = factories.TeamFactory(\n+            season=self.active_season,\n+            room=self.room)\n+\n+        self.non_active_team = factories.TeamFactory(\n+            season=self.non_active_season,\n+            room=self.room)\n+\n+        self.competitor = factories.CompetitorFactory(\n+            email=faker.email()\n+        )\n+\n+        self.competitor2 = factories.CompetitorFactory(\n+            email=faker.email()\n+        )\n+\n+        self.company = factories.HackFmiPartnerFactory()\n+        self.mentor = factories.MentorFactory(\n+            from_company=self.company)\n+\n+    def test_get_team_without_IsHackFMIUser_permission(self):\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=True,\n+        )\n+        url = reverse('hack_fmi:teams')\n+\n+        response = self.client.get(url, kwargs={'pk': faker.random_number(digits=1)})\n+\n+        self.response_401(response)\n+\n+    def test_get_team_with_IsHackFMIUser_IsTeamInActiveSeason_IsSeasonDeadlineUpToDate_permissions(self):\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=True,\n+        )\n+        self.client.force_authenticate(self.competitor)\n+        url = reverse('hack_fmi:teams')\n+\n+        response = self.client.get(url, kwargs={'pk': self.team.id})\n+\n+        self.response_200(response)\n+\n+    def test_get_team_without_IsTeamLeader_permission(self):\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=False,\n+        )\n+        self.client.force_authenticate(self.competitor)\n+\n+        url = reverse('hack_fmi:teams')\n+\n+        response = self.client.get(url, kwargs={'pk': self.team.id})\n+\n+        self.response_200(response)\n+\n+    def test_change_team_without_IsTeamLeader_permission(self):\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=False,\n+        )\n+        self.client.force_authenticate(self.competitor)\n+        data = {\n+            'name': faker.name(),\n+            'idea_description': faker.paragraph(),\n+        }\n+        url = reverse('hack_fmi:teams', kwargs={'pk': self.team.id})\n+\n+        response = self.client.patch(url, data)\n+\n+        self.response_403(response)\n+\n+    def test_change_team_with_IsTeamLeader_permission(self):\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=True,\n+        )\n+        self.client.force_authenticate(self.competitor)\n+        data = {\n+            'name': faker.name(),\n+            'idea_description': faker.paragraph(),\n+        }\n+        url = reverse('hack_fmi:teams', kwargs={'pk': self.team.id})\n+\n+        response = self.client.patch(url, data)\n+\n+        self.response_200(response)\n+        self.assertIsNotNone(Team.objects.get(name=data['name']))\n+        self.assertIsNotNone(Team.objects.get(idea_description=data['idea_description']))\n+\n+    def test_get_team_of_non_active_season_with_pk(self):\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.non_active_team,\n+            is_leader=True,\n+        )\n+        self.client.force_authenticate(self.competitor)\n+        url = reverse('hack_fmi:teams', kwargs={'pk': self.non_active_team.id})\n+\n+        response = self.client.get(url)\n+\n+        self.response_200(response)\n+\n+    def test_change_team_of_non_active_season_with_pk(self):\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.non_active_team,\n+            is_leader=True,\n+        )\n+        self.client.force_authenticate(self.competitor)\n+        data = {\n+            'name': faker.name(),\n+            'idea_description': faker.paragraph(),\n+        }\n+        url = reverse('hack_fmi:teams', kwargs={'pk': self.non_active_team.id})\n+\n+        response = self.client.patch(url, data)\n+\n+        self.response_403(response)\n+\n+    def test_get_team_with_IsSeasonDeadlineUpToDate_permission(self):\n+        self.active_season.make_team_dead_line = date_increase(100)\n+        self.active_season.save()\n+\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=True,\n+        )\n+        self.client.force_authenticate(self.competitor)\n+        url = reverse('hack_fmi:teams', kwargs={'pk': self.team.id})\n+\n+        response = self.client.get(url)\n+\n+        self.response_200(response)\n+\n+    def test_change_team_without_IsSeasonDeadlineUpToDate_permission(self):\n+        self.active_season.make_team_dead_line = date_increase(100)\n+        self.active_season.save()\n+\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=True,\n+        )\n+        data = {\n+            'name': faker.name(),\n+            'idea_description': faker.paragraph(),\n+        }\n+\n+        self.client.force_authenticate(self.competitor)\n+\n+        url = reverse('hack_fmi:teams', kwargs={'pk': self.team.id})\n+\n+        response = self.client.patch(url, data)\n+\n+        self.response_403(response)\n+\n+\n+class TeamMembershipAPITest(TestCase):\n+\n+    def setUp(self):\n+        self.company = factories.HackFmiPartnerFactory()\n+        self.mentor = factories.MentorFactory(\n+            from_company=self.company)\n+        self.client = APIClient()\n+\n+        self.active_season = factories.SeasonFactory(\n+            is_active=True\n+        )\n+        self.non_active_season = factories.SeasonFactory(\n+            is_active=False)\n+\n+        self.room = factories.RoomFactory(\n+            season=self.active_season)\n+        self.team = factories.TeamFactory(\n+            season=self.active_season,\n+        )\n+        self.non_active_team = factories.TeamFactory(\n+            season=self.non_active_season)\n+\n+        self.competitor = factories.CompetitorFactory(\n+            email=faker.email())\n+        self.delete_team = EmailTemplate.objects.create(\n+            name='delete_team',\n+            subject='Delete team',\n+            content=faker.paragraph()\n+        )\n+\n+    def test_delete_team_membership_if_not_member_of_team(self):\n+        other_competitor = factories.CompetitorFactory(\n+            email=faker.email())\n+        other_membership = factories.TeamMembershipFactory(\n+            competitor=other_competitor,\n+            team=self.team,\n+            is_leader=True,\n+        )\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=False,\n+        )\n+        self.client.force_authenticate(self.competitor)\n+\n+        url = reverse('hack_fmi:team_membership', kwargs={'pk': other_membership.id})\n+\n+        response = self.client.delete(url)\n+\n+        self.response_403(response)\n+\n+    def test_delete_team_membership_if_not_hack_fmi_user(self):\n+        other_competitor = factories.StudentFactory(\n+            email=faker.email())\n+        membership = factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=True,\n+        )\n+\n+        self.client.force_authenticate(other_competitor)\n+\n+        url = reverse('hack_fmi:team_membership', kwargs={'pk': membership.id})\n+\n+        response = self.client.delete(url)\n+\n+        self.response_403(response)\n+\n+    def test_delete_team_membership_if_not_active_season(self):\n+        membership = factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.non_active_team,\n+            is_leader=True,\n+        )\n+\n+        self.client.force_authenticate(self.competitor)\n+\n+        url = reverse('hack_fmi:team_membership', kwargs={'pk': membership.id})\n+\n+        response = self.client.delete(url)\n+\n+        self.response_403(response)\n+\n+    def test_delete_team_membership_if_competitor_not_teamleader(self):\n+        membership = factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=False,\n+        )\n+\n+        self.client.force_authenticate(self.competitor)\n+\n+        url = reverse('hack_fmi:team_membership', kwargs={'pk': membership.id})\n+\n+        response = self.client.delete(url)\n+\n+        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)\n+        # self.assertEqual(Team.objects.filter(name=self.team.name).count(), 1)\n+        self.assertEqual(TeamMembership.objects.filter(competitor=self.competitor).count(), 0)\n+\n+    def test_delete_team_if_competitor_is_leader(self):\n+        team = factories.TeamFactory(\n+            name=faker.name(),\n+            season=self.active_season,\n+        )\n+        membership = factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=team,\n+            is_leader=True,\n+        )\n+        self.assertEqual(team.get_leader(), self.competitor)\n+\n+        self.client.force_authenticate(self.competitor)\n+\n+        url = reverse('hack_fmi:team_membership', kwargs={'pk': membership.id})\n+\n+        response = self.client.delete(url)\n+\n+        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)\n+        self.assertEqual(Team.objects.filter(name=team.name).count(), 0)\n+        self.assertEqual(TeamMembership.objects.filter(competitor=self.competitor).count(), 0)\n+\n+\n+# @unittest.skip('Skip until further implementation of Hackathon system')\n+# class TeamRegistrationTests(TestCase):\n+\n+#     def setUp(self):\n+#         self.skills = Skill.objects.create(name=\"C#\")\n+#         self.season = Season.objects.create(\n+#             name=\"season\",\n+#             topic='TestTopic',\n+#             is_active=True,\n+#             sign_up_deadline=date_increase(10),\n+#             mentor_pick_start_date=date_increase(15),\n+#             mentor_pick_end_date=date_increase(25),\n+#             make_team_dead_line=date_increase(20)\n+#         )\n+#         self.competitor = Competitor.objects.create(\n+#             email='ivo@abv.bg',\n+#             full_name='Ivo Naidobriq',\n+#             faculty_number='123',\n+#         )\n+#         self.team_data = {\n+#             'name': 'Pandas',\n+#             'idea_description': 'GameDevelopers',\n+#             'repository': 'https://github.com/HackSoftware',\n+#             'technologies': [self.skills.id]\n+#         }\n+#         self.client = APIClient()\n+#         self.client.force_authenticate(user=self.competitor)\n+\n+#     def test_register_team(self):\n+#         url = reverse('hack_fmi:teams')\n+#         response = self.client.post(url, self.team_data, format='json')\n+#         self.assertEqual(len(response.data['members']), 1)\n+#         self.assertEqual(response.status_code, status.HTTP_201_CREATED)\n+#         self.assertEqual(len(response.data['technologies']), 1)\n+#         self.assertEqual(len(response.data['technologies_full']), 1)\n+\n+#     def test_registered_team_has_leader(self):\n+#         url = reverse('hack_fmi:teams')\n+#         self.client.post(url, self.team_data, format='json')\n+#         team_membership = TeamMembership.objects.first()\n+#         self.assertEqual(self.competitor, team_membership.competitor)\n+#         self.assertTrue(team_membership.is_leader)\n+\n+    # def test_register_more_than_one_team(self):\n+    #     url = reverse('hack_fmi:register_team')\n+    #     first_response = self.client.post(url, self.team_data, format='json')\n+\n+    #     data = {\n+    #         'name': 'Pandass',\n+    #         'idea_description': 'GameDeveloperss',\n+    #         'repository': 'https://github.com/HackSoftwares',\n+    #         'technologies': [self.skills.id],\n+    #     }\n+    #     url = reverse('hack_fmi:register_team')\n+    #     second_response = self.client.post(url, data, format='json')\n+    #     self.assertEqual(first_response.status_code, status.HTTP_201_CREATED)\n+    #     self.assertEqual(second_response.status_code, status.HTTP_400_BAD_REQUEST)\n+    #     self.assertEqual(Team.objects.count(), 1)\n+\n+\n+class InvitationTests(TestCase):\n+\n+    def setUp(self):\n+        self.client = APIClient()\n+\n+        self.template = EmailTemplate.objects.create(\n+            name='hackfmi_team_invite',\n+            subject='Invitation for HackFMI membership',\n+            content=faker.paragraph(),\n+        )\n+\n+        self.season = factories.SeasonFactory(\n+            is_active=True,\n+            max_team_members_count=3,\n+        )\n+        self.competitor = factories.CompetitorFactory(\n+            email=faker.email(),\n+        )\n+        self.competitor_not_leader = factories.CompetitorFactory(\n+            email=faker.email(),\n+        )\n+        self.team = factories.TeamFactory(\n+            name=faker.name(),\n+            season=self.season,\n+        )\n+        self.team_membership = factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=True,\n+        )\n+\n+    def test_send_invitation_for_team(self):\n+        self.client.force_authenticate(user=self.competitor)\n+\n+        url = reverse('hack_fmi:invitation-list')\n+        data = {'competitor_email': self.competitor_not_leader.email}\n+        response = self.client.post(url, data)\n+\n+        self.response_201(response)\n+        self.assertEquals(Invitation.objects.count(), 1)\n+        self.assertEqual(Invitation.objects.all()[0].team.id, self.team.id)\n+        self.assertEqual(Invitation.objects.all()[0].competitor.id, self.competitor_not_leader.id)\n+        self.assertEqual(mail.get_queued().last().message, self.template.content)\n+\n+    def test_send_invitation_not_from_leader(self):\n+        competitor = factories.CompetitorFactory(\n+            email=faker.email(),\n+        )\n+\n+        factories.TeamMembershipFactory(\n+            competitor=competitor,\n+            team=self.team,\n+            is_leader=False,\n+        )\n+        self.client.force_authenticate(user=competitor)\n+\n+        url = reverse('hack_fmi:invitation-list')\n+        data = {'competitor_email': self.competitor_not_leader.email}\n+        response = self.client.post(url, data,)\n+\n+        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)\n+\n+    def test_send_invitation_to_not_existing_user(self):\n+        self.client.force_authenticate(user=self.competitor)\n+\n+        url = reverse('hack_fmi:invitation-list')\n+        data = {'competitor_email': faker.email()}\n+        response = self.client.post(url, data)\n+\n+        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)\n+\n+    def test_send_invitation_twice_to_same_competitor(self):\n+        self.client.force_authenticate(user=self.competitor)\n+\n+        Invitation.objects.create(\n+            team=self.team,\n+            competitor=self.competitor_not_leader,\n+        )\n+        url = reverse('hack_fmi:invitation-list')\n+        data = {'competitor_email': self.competitor_not_leader.email}\n+        response = self.client.post(url, data)\n+        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)\n+\n+    def test_send_invitation_when_team_is_full(self):\n+        self.client.force_authenticate(user=self.competitor)\n+\n+        competitor2 = factories.CompetitorFactory(\n+            email=faker.email()\n+        )\n+        competitor3 = factories.CompetitorFactory(\n+            email=faker.email()\n+        )\n+\n+        factories.TeamMembershipFactory(\n+            competitor=competitor2,\n+            team=self.team,\n+            is_leader=False,\n+        )\n+        factories.TeamMembershipFactory(\n+            competitor=competitor3,\n+            team=self.team,\n+            is_leader=False,\n+        )\n+        self.assertEqual(TeamMembership.objects.filter(team=self.team).count(), 3)\n+\n+        url = reverse('hack_fmi:invitation-list')\n+        data = {'competitor_email': self.competitor_not_leader.email}\n+\n+        response = self.client.post(url, data)\n+\n+        self.response_403(response)\n+        self.assertEqual(TeamMembership.objects.filter(team=self.team).count(), 3)\n+\n+    def test_get_invitations_if_not_hackFMI_user(self):\n+        user = factories.BaseUserFactory(\n+            email=faker.email()\n+        )\n+        self.client.force_authenticate(user=user)\n+\n+        url = reverse('hack_fmi:invitation-list')\n+        response = self.client.get(url)\n+\n+        self.response_403(response)\n+\n+    def test_get_invitations_if_not_leader_and_hackFMI_user(self):\n+        factories.InvitationFactory(\n+            team=self.team,\n+            competitor=self.competitor_not_leader\n+        )\n+        self.client.force_authenticate(user=self.competitor_not_leader)\n+\n+        url = reverse('hack_fmi:invitation-list')\n+        response = self.client.get(url)\n+\n+        self.assertEqual(response.status_code, status.HTTP_200_OK)\n+        self.assertEqual(len(response.data), 1)\n+\n+    def test_get_invitations_if_leader_and_hackFMI_user(self):\n+        factories.InvitationFactory(\n+            team=self.team,\n+            competitor=self.competitor\n+        )\n+        self.client.force_authenticate(user=self.competitor)\n+\n+        url = reverse('hack_fmi:invitation-list')\n+        response = self.client.get(url)\n+\n+        self.assertEqual(response.status_code, status.HTTP_200_OK)\n+        self.assertEqual(len(response.data), 1)\n+        self.assertEqual(Invitation.objects.all().count(), 1)\n+\n+    def test_send_invitation_to_user_that_already_has_team(self):\n+        self.client.force_authenticate(self.competitor)\n+\n+        team = factories.TeamFactory(\n+            name=faker.name(),\n+            season=self.season,\n+        )\n+\n+        factories.TeamMembershipFactory(\n+            team=team,\n+            competitor=self.competitor_not_leader,\n+        )\n+\n+        url = reverse('hack_fmi:invitation-list')\n+        data = {\n+            'competitor_email': self.competitor_not_leader.email\n+        }\n+        response = self.client.post(url, data)\n+\n+        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)\n+\n+    def test_accept_invitation(self):\n+        self.client.force_authenticate(user=self.competitor_not_leader)\n+\n+        inv = factories.InvitationFactory(\n+            team=self.team,\n+            competitor=self.competitor_not_leader\n+        )\n+        url = reverse('hack_fmi:invitation-accept', kwargs={'pk': inv.id})\n+\n+        response = self.client.post(url)\n+        self.response_200(response)\n+        self.assertEqual(Invitation.objects.all().count(), 0)\n+        self.\\\n+            assertEqual(TeamMembership.objects.filter(team=inv.team, competitor=inv.competitor).count(), 1)\n+\n+    def test_accept_invitation_already_has_team(self):\n+        team = factories.TeamFactory(\n+            season=self.season\n+        )\n+        factories.TeamMembershipFactory(\n+            competitor=self.competitor_not_leader,\n+            team=team,\n+        )\n+\n+        inv = factories.InvitationFactory(\n+            team=team,\n+            competitor=self.competitor_not_leader\n+        )\n+        self.client.force_authenticate(user=self.competitor_not_leader)\n+\n+        url = reverse('hack_fmi:invitation-accept', kwargs={'pk': inv.id})\n+\n+        response = self.client.post(url)\n+\n+        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)\n+\n+    def test_can_not_accept_invitation_if_leader(self):\n+        self.client.force_authenticate(self.competitor)\n+\n+        inv = factories.InvitationFactory(\n+            team=self.team,\n+            competitor=self.competitor_not_leader\n+        )\n+\n+        url = reverse('hack_fmi:invitation-accept', kwargs={'pk': inv.id})\n+\n+        response = self.client.post(url)\n+\n+        self.response_403(response)\n+\n+    def test_accept_invitation_that_is_not_yours(self):\n+        competitor = factories.CompetitorFactory(\n+            email=faker.email()\n+        )\n+        self.client.force_authenticate(user=competitor)\n+\n+        inv = factories.InvitationFactory(\n+            team=self.team,\n+            competitor=self.competitor_not_leader\n+        )\n+\n+        url = reverse('hack_fmi:invitation-accept', kwargs={'pk': inv.id})\n+\n+        response = self.client.post(url)\n+\n+        self.response_403(response)\n+\n+    def test_decline_invitation_if_leader(self):\n+        self.client.force_authenticate(user=self.competitor)\n+\n+        factories.TeamMembershipFactory(\n+            team=self.team,\n+            competitor=self.competitor_not_leader,\n+        )\n+\n+        invitation = factories.InvitationFactory(\n+            team=self.team,\n+            competitor=self.competitor_not_leader\n+        )\n+\n+        self.assertEqual(Invitation.objects.all().count(), 1)\n+\n+        url = reverse('hack_fmi:invitation-detail', kwargs={'pk': invitation.id})\n+\n+        response = self.client.delete(url)\n+\n+        self.assertEqual(response.status_code, 204)\n+        self.assertEqual(Invitation.objects.all().count(), 0)\n+\n+    def test_decline_invitation_if_not_leader(self):\n+        self.client.force_authenticate(user=self.competitor_not_leader)\n+\n+        factories.TeamMembershipFactory(\n+            team=self.team,\n+            competitor=self.competitor_not_leader,\n+        )\n+\n+        invitation = factories.InvitationFactory(\n+            team=self.team,\n+            competitor=self.competitor_not_leader\n+        )\n+        self.assertEqual(Invitation.objects.all().count(), 1)\n+\n+        url = reverse('hack_fmi:invitation-detail', kwargs={'pk': invitation.id})\n+        response = self.client.delete(url)\n+\n+        self.assertEqual(response.status_code, 204)\n+        self.assertEqual(Invitation.objects.all().count(), 0)\n+\n+    def test_decline_invitation_that_is_not_yours(self):\n+        competitor = factories.CompetitorFactory(\n+            email=faker.email()\n+        )\n+\n+        self.client.force_authenticate(user=competitor)\n+\n+        invitation = factories.InvitationFactory(\n+            team=self.team,\n+            competitor=self.competitor_not_leader\n+        )\n+        self.assertEqual(Invitation.objects.all().count(), 1)\n+        url = reverse('hack_fmi:invitation-detail', kwargs={'pk': invitation.id})\n+\n+        response = self.client.delete(url)\n+\n+        self.response_403(response)\n+        self.assertEqual(TeamMembership.objects.filter(competitor=invitation.competitor).count(), 0)\n+        self.assertEqual(Invitation.objects.all().count(), 1)\n+\n+\n+class TeamMentorshipTest(TestCase):\n+\n+    def setUp(self):\n+        self.client = APIClient()\n+        self.skills = factories.SkillFactory()\n+\n+        self.season = factories.SeasonFactory(\n+            is_active=True,\n+            # max_mentor_pick=1,\n+        )\n+        self.competitor = factories.CompetitorFactory(\n+            email=faker.email(),\n+        )\n+        self.team = factories.TeamFactory(\n+            season=self.season,\n+        )\n+        self.team_membership = factories.TeamMembershipFactory(\n+            competitor=self.competitor,\n+            team=self.team,\n+            is_leader=True,\n+        )\n+        self.company = factories.HackFmiPartnerFactory()\n+        self.mentor = factories.MentorFactory(\n+            from_company=self.company,\n+        )\n+        self.mentor2 = factories.MentorFactory(\n+            from_company=self.company,\n+        )\n+\n+    def test_assign_mentor_if_not_hackFMI_user(self):\n+        competitor = factories.CompetitorFactory(\n+            email=faker.email(),)\n+\n+        self.client.force_authenticate(competitor)\n+\n+        url = reverse('hack_fmi:team_mentorship')\n+\n+        data = {'team': self.team.id,\n+                'mentor': self.mentor.id,\n+                }\n+\n+        response = self.client.post(url, data)\n+\n+        self.response_403(response)\n+\n+    def test_assign_mentor_if_not_leader_team(self):\n+        self.team.season.mentor_pick_start_date = date_decrease(10)\n+        self.team.season.mentor_pick_end_date = date_increase(10)\n+        self.team.save()\n+\n+        self.team_membership.is_leader = False\n+        self.team_membership.save()\n+\n+        self.client.force_authenticate(user=self.competitor)\n+\n+        url = reverse('hack_fmi:team_mentorship')\n+\n+        data = {'team': self.team.id,\n+                'mentor': self.mentor.id,\n+                }\n+\n+        response = self.client.post(url, data)\n+\n+        self.response_403(response)\n+\n+    # def test_assign_more_than_allowed_mentors(self):\n+    #     self.client.force_authenticate(user=self.competitor)\n+\n+    #     url = reverse('hack_fmi:team_mentorship')\n+\n+    #     data = {'id': self.mentor.id, 'team_id': self.team.id}\n+    #     self.client.put(url, data)\n+\n+    #     data = {'id': self.mentor2.id, 'team_id': self.team.id}\n+\n+    #     response = self.client.put(url, data)\n+\n+    #     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)\n+\n+    def test_assign_mentor_before_startdate(self):\n+        self.team.season.mentor_pick_start_date = date_increase(10)\n+        self.team.season.mentor_pick_end_date = date_increase(10)\n+        self.team.season.save()\n+\n+        self.client.force_authenticate(user=self.competitor)\n+\n+        url = reverse('hack_fmi:team_mentorship')\n+\n+        data = {'team': self.team.id,\n+                'mentor': self.mentor.id,\n+                }\n+        response = self.client.post(url, data)\n+\n+        self.response_403(response)\n+\n+    def test_assign_mentor_after_enddate(self):\n+        self.team.season.mentor_pick_start_date = date_decrease(10)\n+        self.team.season.mentor_pick_end_date = date_decrease(10)\n+        self.team.season.save()\n+\n+        self.client.force_authenticate(user=self.competitor)\n+\n+        url = reverse('hack_fmi:team_mentorship')\n+\n+        data = {'team': self.team.id,\n+                'mentor': self.mentor.id,\n+                }\n+\n+        response = self.client.post(url, data)\n+\n+        self.response_403(response)\n+\n+    def test_remove_mentor_from_team_if_not_teamleader(self):\n+        self.team_membership.is_leader = False\n+        self.team_membership.save()\n+\n+        self.client.force_authenticate(user=self.competitor)\n+\n+        mentorship = factories.TeamMentorshipFactory(\n+            team=self.team,\n+            mentor=self.mentor)\n+\n+        url = reverse('hack_fmi:team_mentorship', kwargs={'pk': mentorship.id})\n+\n+        response = self.client.delete(url)\n+\n+        self.response_403(response)\n+\n+    def test_remove_mentor_from_team(self):","path":"loki/hack_fmi/tests/test_apis.py","position":943,"original_position":943,"commit_id":"4c24b1e9e2f2bc80d95b3eb87750b852af42e14d","original_commit_id":"20f619f28a32430b0e1169bdd55c95786e619294","user":{"login":"RadoRado","id":387867,"avatar_url":"https://avatars.githubusercontent.com/u/387867?v=3","gravatar_id":"","url":"https://api.github.com/users/RadoRado","html_url":"https://github.com/RadoRado","followers_url":"https://api.github.com/users/RadoRado/followers","following_url":"https://api.github.com/users/RadoRado/following{/other_user}","gists_url":"https://api.github.com/users/RadoRado/gists{/gist_id}","starred_url":"https://api.github.com/users/RadoRado/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/RadoRado/subscriptions","organizations_url":"https://api.github.com/users/RadoRado/orgs","repos_url":"https://api.github.com/users/RadoRado/repos","events_url":"https://api.github.com/users/RadoRado/events{/privacy}","received_events_url":"https://api.github.com/users/RadoRado/received_events","type":"User","site_admin":false},"body":"`if_leader`","created_at":"2016-07-13T10:08:27Z","updated_at":"2016-07-13T10:08:27Z","html_url":"https://github.com/HackSoftware/Loki/pull/79#discussion_r70598640","pull_request_url":"https://api.github.com/repos/HackSoftware/Loki/pulls/79","_links":{"self":{"href":"https://api.github.com/repos/HackSoftware/Loki/pulls/comments/70598640"},"html":{"href":"https://github.com/HackSoftware/Loki/pull/79#discussion_r70598640"},"pull_request":{"href":"https://api.github.com/repos/HackSoftware/Loki/pulls/79"}}},"pull_request":{"url":"https://api.github.com/repos/HackSoftware/Loki/pulls/79","id":76433011,"html_url":"https://github.com/HackSoftware/Loki/pull/79","diff_url":"https://github.com/HackSoftware/Loki/pull/79.diff","patch_url":"https://github.com/HackSoftware/Loki/pull/79.patch","issue_url":"https://api.github.com/repos/HackSoftware/Loki/issues/79","number":79,"state":"open","locked":false,"title":"Hack fmi apis","user":{"login":"kbadova","id":10941065,"avatar_url":"https://avatars.githubusercontent.com/u/10941065?v=3","gravatar_id":"","url":"https://api.github.com/users/kbadova","html_url":"https://github.com/kbadova","followers_url":"https://api.github.com/users/kbadova/followers","following_url":"https://api.github.com/users/kbadova/following{/other_user}","gists_url":"https://api.github.com/users/kbadova/gists{/gist_id}","starred_url":"https://api.github.com/users/kbadova/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kbadova/subscriptions","organizations_url":"https://api.github.com/users/kbadova/orgs","repos_url":"https://api.github.com/users/kbadova/repos","events_url":"https://api.github.com/users/kbadova/events{/privacy}","received_events_url":"https://api.github.com/users/kbadova/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-06T13:36:06Z","updated_at":"2016-07-13T10:08:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f51fca16f9b7e2c87b1bc26844c64d474b761155","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/HackSoftware/Loki/pulls/79/commits","review_comments_url":"https://api.github.com/repos/HackSoftware/Loki/pulls/79/comments","review_comment_url":"https://api.github.com/repos/HackSoftware/Loki/pulls/comments{/number}","comments_url":"https://api.github.com/repos/HackSoftware/Loki/issues/79/comments","statuses_url":"https://api.github.com/repos/HackSoftware/Loki/statuses/4c24b1e9e2f2bc80d95b3eb87750b852af42e14d","head":{"label":"HackSoftware:hack_fmi_apis","ref":"hack_fmi_apis","sha":"4c24b1e9e2f2bc80d95b3eb87750b852af42e14d","user":{"login":"HackSoftware","id":11139128,"avatar_url":"https://avatars.githubusercontent.com/u/11139128?v=3","gravatar_id":"","url":"https://api.github.com/users/HackSoftware","html_url":"https://github.com/HackSoftware","followers_url":"https://api.github.com/users/HackSoftware/followers","following_url":"https://api.github.com/users/HackSoftware/following{/other_user}","gists_url":"https://api.github.com/users/HackSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/HackSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HackSoftware/subscriptions","organizations_url":"https://api.github.com/users/HackSoftware/orgs","repos_url":"https://api.github.com/users/HackSoftware/repos","events_url":"https://api.github.com/users/HackSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/HackSoftware/received_events","type":"Organization","site_admin":false},"repo":{"id":32721618,"name":"Loki","full_name":"HackSoftware/Loki","owner":{"login":"HackSoftware","id":11139128,"avatar_url":"https://avatars.githubusercontent.com/u/11139128?v=3","gravatar_id":"","url":"https://api.github.com/users/HackSoftware","html_url":"https://github.com/HackSoftware","followers_url":"https://api.github.com/users/HackSoftware/followers","following_url":"https://api.github.com/users/HackSoftware/following{/other_user}","gists_url":"https://api.github.com/users/HackSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/HackSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HackSoftware/subscriptions","organizations_url":"https://api.github.com/users/HackSoftware/orgs","repos_url":"https://api.github.com/users/HackSoftware/repos","events_url":"https://api.github.com/users/HackSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/HackSoftware/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/HackSoftware/Loki","description":"Loki is the Learning Management System for HackBulgaria's courses","fork":false,"url":"https://api.github.com/repos/HackSoftware/Loki","forks_url":"https://api.github.com/repos/HackSoftware/Loki/forks","keys_url":"https://api.github.com/repos/HackSoftware/Loki/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HackSoftware/Loki/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HackSoftware/Loki/teams","hooks_url":"https://api.github.com/repos/HackSoftware/Loki/hooks","issue_events_url":"https://api.github.com/repos/HackSoftware/Loki/issues/events{/number}","events_url":"https://api.github.com/repos/HackSoftware/Loki/events","assignees_url":"https://api.github.com/repos/HackSoftware/Loki/assignees{/user}","branches_url":"https://api.github.com/repos/HackSoftware/Loki/branches{/branch}","tags_url":"https://api.github.com/repos/HackSoftware/Loki/tags","blobs_url":"https://api.github.com/repos/HackSoftware/Loki/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HackSoftware/Loki/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HackSoftware/Loki/git/refs{/sha}","trees_url":"https://api.github.com/repos/HackSoftware/Loki/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HackSoftware/Loki/statuses/{sha}","languages_url":"https://api.github.com/repos/HackSoftware/Loki/languages","stargazers_url":"https://api.github.com/repos/HackSoftware/Loki/stargazers","contributors_url":"https://api.github.com/repos/HackSoftware/Loki/contributors","subscribers_url":"https://api.github.com/repos/HackSoftware/Loki/subscribers","subscription_url":"https://api.github.com/repos/HackSoftware/Loki/subscription","commits_url":"https://api.github.com/repos/HackSoftware/Loki/commits{/sha}","git_commits_url":"https://api.github.com/repos/HackSoftware/Loki/git/commits{/sha}","comments_url":"https://api.github.com/repos/HackSoftware/Loki/comments{/number}","issue_comment_url":"https://api.github.com/repos/HackSoftware/Loki/issues/comments{/number}","contents_url":"https://api.github.com/repos/HackSoftware/Loki/contents/{+path}","compare_url":"https://api.github.com/repos/HackSoftware/Loki/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HackSoftware/Loki/merges","archive_url":"https://api.github.com/repos/HackSoftware/Loki/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HackSoftware/Loki/downloads","issues_url":"https://api.github.com/repos/HackSoftware/Loki/issues{/number}","pulls_url":"https://api.github.com/repos/HackSoftware/Loki/pulls{/number}","milestones_url":"https://api.github.com/repos/HackSoftware/Loki/milestones{/number}","notifications_url":"https://api.github.com/repos/HackSoftware/Loki/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HackSoftware/Loki/labels{/name}","releases_url":"https://api.github.com/repos/HackSoftware/Loki/releases{/id}","deployments_url":"https://api.github.com/repos/HackSoftware/Loki/deployments","created_at":"2015-03-23T09:12:43Z","updated_at":"2016-07-13T08:07:45Z","pushed_at":"2016-07-13T09:16:10Z","git_url":"git://github.com/HackSoftware/Loki.git","ssh_url":"git@github.com:HackSoftware/Loki.git","clone_url":"https://github.com/HackSoftware/Loki.git","svn_url":"https://github.com/HackSoftware/Loki","homepage":"","size":6769,"stargazers_count":4,"watchers_count":4,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":11,"forks":0,"open_issues":11,"watchers":4,"default_branch":"master"}},"base":{"label":"HackSoftware:master","ref":"master","sha":"0e67487b5168bef6dda241c8e63cf06b004d8484","user":{"login":"HackSoftware","id":11139128,"avatar_url":"https://avatars.githubusercontent.com/u/11139128?v=3","gravatar_id":"","url":"https://api.github.com/users/HackSoftware","html_url":"https://github.com/HackSoftware","followers_url":"https://api.github.com/users/HackSoftware/followers","following_url":"https://api.github.com/users/HackSoftware/following{/other_user}","gists_url":"https://api.github.com/users/HackSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/HackSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HackSoftware/subscriptions","organizations_url":"https://api.github.com/users/HackSoftware/orgs","repos_url":"https://api.github.com/users/HackSoftware/repos","events_url":"https://api.github.com/users/HackSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/HackSoftware/received_events","type":"Organization","site_admin":false},"repo":{"id":32721618,"name":"Loki","full_name":"HackSoftware/Loki","owner":{"login":"HackSoftware","id":11139128,"avatar_url":"https://avatars.githubusercontent.com/u/11139128?v=3","gravatar_id":"","url":"https://api.github.com/users/HackSoftware","html_url":"https://github.com/HackSoftware","followers_url":"https://api.github.com/users/HackSoftware/followers","following_url":"https://api.github.com/users/HackSoftware/following{/other_user}","gists_url":"https://api.github.com/users/HackSoftware/gists{/gist_id}","starred_url":"https://api.github.com/users/HackSoftware/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HackSoftware/subscriptions","organizations_url":"https://api.github.com/users/HackSoftware/orgs","repos_url":"https://api.github.com/users/HackSoftware/repos","events_url":"https://api.github.com/users/HackSoftware/events{/privacy}","received_events_url":"https://api.github.com/users/HackSoftware/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/HackSoftware/Loki","description":"Loki is the Learning Management System for HackBulgaria's courses","fork":false,"url":"https://api.github.com/repos/HackSoftware/Loki","forks_url":"https://api.github.com/repos/HackSoftware/Loki/forks","keys_url":"https://api.github.com/repos/HackSoftware/Loki/keys{/key_id}","collaborators_url":"https://api.github.com/repos/HackSoftware/Loki/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/HackSoftware/Loki/teams","hooks_url":"https://api.github.com/repos/HackSoftware/Loki/hooks","issue_events_url":"https://api.github.com/repos/HackSoftware/Loki/issues/events{/number}","events_url":"https://api.github.com/repos/HackSoftware/Loki/events","assignees_url":"https://api.github.com/repos/HackSoftware/Loki/assignees{/user}","branches_url":"https://api.github.com/repos/HackSoftware/Loki/branches{/branch}","tags_url":"https://api.github.com/repos/HackSoftware/Loki/tags","blobs_url":"https://api.github.com/repos/HackSoftware/Loki/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/HackSoftware/Loki/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/HackSoftware/Loki/git/refs{/sha}","trees_url":"https://api.github.com/repos/HackSoftware/Loki/git/trees{/sha}","statuses_url":"https://api.github.com/repos/HackSoftware/Loki/statuses/{sha}","languages_url":"https://api.github.com/repos/HackSoftware/Loki/languages","stargazers_url":"https://api.github.com/repos/HackSoftware/Loki/stargazers","contributors_url":"https://api.github.com/repos/HackSoftware/Loki/contributors","subscribers_url":"https://api.github.com/repos/HackSoftware/Loki/subscribers","subscription_url":"https://api.github.com/repos/HackSoftware/Loki/subscription","commits_url":"https://api.github.com/repos/HackSoftware/Loki/commits{/sha}","git_commits_url":"https://api.github.com/repos/HackSoftware/Loki/git/commits{/sha}","comments_url":"https://api.github.com/repos/HackSoftware/Loki/comments{/number}","issue_comment_url":"https://api.github.com/repos/HackSoftware/Loki/issues/comments{/number}","contents_url":"https://api.github.com/repos/HackSoftware/Loki/contents/{+path}","compare_url":"https://api.github.com/repos/HackSoftware/Loki/compare/{base}...{head}","merges_url":"https://api.github.com/repos/HackSoftware/Loki/merges","archive_url":"https://api.github.com/repos/HackSoftware/Loki/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/HackSoftware/Loki/downloads","issues_url":"https://api.github.com/repos/HackSoftware/Loki/issues{/number}","pulls_url":"https://api.github.com/repos/HackSoftware/Loki/pulls{/number}","milestones_url":"https://api.github.com/repos/HackSoftware/Loki/milestones{/number}","notifications_url":"https://api.github.com/repos/HackSoftware/Loki/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/HackSoftware/Loki/labels{/name}","releases_url":"https://api.github.com/repos/HackSoftware/Loki/releases{/id}","deployments_url":"https://api.github.com/repos/HackSoftware/Loki/deployments","created_at":"2015-03-23T09:12:43Z","updated_at":"2016-07-13T08:07:45Z","pushed_at":"2016-07-13T09:16:10Z","git_url":"git://github.com/HackSoftware/Loki.git","ssh_url":"git@github.com:HackSoftware/Loki.git","clone_url":"https://github.com/HackSoftware/Loki.git","svn_url":"https://github.com/HackSoftware/Loki","homepage":"","size":6769,"stargazers_count":4,"watchers_count":4,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":11,"forks":0,"open_issues":11,"watchers":4,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/HackSoftware/Loki/pulls/79"},"html":{"href":"https://github.com/HackSoftware/Loki/pull/79"},"issue":{"href":"https://api.github.com/repos/HackSoftware/Loki/issues/79"},"comments":{"href":"https://api.github.com/repos/HackSoftware/Loki/issues/79/comments"},"review_comments":{"href":"https://api.github.com/repos/HackSoftware/Loki/pulls/79/comments"},"review_comment":{"href":"https://api.github.com/repos/HackSoftware/Loki/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/HackSoftware/Loki/pulls/79/commits"},"statuses":{"href":"https://api.github.com/repos/HackSoftware/Loki/statuses/4c24b1e9e2f2bc80d95b3eb87750b852af42e14d"}}}}
{"actor":{"display_login":"RadoRado"}}