def test_create_approvalworkflow(self):
        user_john = factories.User(first_name='John', last_name='Lennon')
        user_paul = factories.User(first_name='Paul', last_name='McCartney')
        assigned_user = factories.TolaUser(user=user_john,
                                           organization=self.organization)
        requested_user = factories.TolaUser(user=user_paul,
                                            organization=self.organization)
        approval_type = factories.ApprovalType()
        assigned_user_url = reverse('tolauser-detail',
                                    kwargs={'pk': assigned_user.id},
                                    request=self.request)
        requested_user_url = reverse('tolauser-detail',
                                     kwargs={'pk': requested_user.id},
                                     request=self.request)
        approval_type_url = reverse('approvaltype-detail',
                                    kwargs={'pk': approval_type.id},
                                    request=self.request)
        user_url = reverse('user-detail', kwargs={'pk': self.user.id},
                           request=self.request)

        data = {'assigned_to': assigned_user_url,
                'requested_from': requested_user_url,
                'approval_type': approval_type_url}
        self.request = APIRequestFactory().post('/api/approvalworkflow/', data)
        self.request.user = self.user
        view = ApprovalWorkflowViewSet.as_view({'post': 'create'})
        response = view(self.request)

        self.assertEqual(response.status_code, 201)
        self.assertEqual(response.data['assigned_to'], assigned_user_url)
        self.assertEqual(response.data['requested_from'], requested_user_url)
        self.assertEqual(response.data['created_by'], user_url)
Esempio n. 2
0
    def test_index_context_data(self):
        user_stranger = factories.User(username='******')
        factories.Silo(owner=user_stranger, name='open', public=True)

        user = factories.User()
        factories.Silo(owner=user, name='pub_1', public=True)
        factories.Silo(owner=user, name='pub_2', public=True)
        factories.Silo(owner=user, name='priv_1', public=False)
        factories.Silo(owner=user, name='shared_1', public=False,
                       shared=[user_stranger])

        request = self.factory.get('', follow=True)
        request.user = user
        context = views.IndexView()._get_context_data(request)
        self.assertEqual(context['site_name'], 'Track')
        self.assertEqual(len(context['silos_user']), 4)
        self.assertEqual(context['silos_user'][0].name, 'pub_1')
        self.assertEqual(context['silos_user'][1].name, 'pub_2')
        self.assertEqual(context['silos_user'][2].name, 'priv_1')
        self.assertEqual(context['silos_user_public_total'], 2)
        self.assertEqual(context['silos_user_shared_total'], 1)
        self.assertEqual(context['silos_public'][0].name, 'open')
        self.assertEqual(len(context['silos_public']), 1)
        self.assertEqual(len(context['readtypes']), 7)
        self.assertEqual(sorted(list(context['readtypes'])),
                         [u'CSV', u'CommCare', u'CustomForm', u'GSheet Import',
                          u'JSON', u'ONA', u'OneDrive'])
        # self.assertEqual(list(context['tags']),
        #                  [{'name': u'security', 'times_tagged': 4},
        #                   {'name': u'report', 'times_tagged': 4}]),
        self.assertEqual(context['site_name'], 'Track'),
Esempio n. 3
0
    def setUp(self):
        self.factory = APIRequestFactory()
        self.tola_user = factories.TolaUser()

        self.tola_user_ringo = factories.TolaUser(
            user=factories.User(first_name='Ringo', last_name='Starr'),
            organization=self.tola_user.organization)
        self.tola_user_george = factories.TolaUser(
            user=factories.User(first_name='George', last_name='Harrison'),
            organization=factories.Organization(name='Other Org'))
    def test_create_workflowteam_org_admin(self):
        WorkflowTeam.objects.create(
            workflow_user=self.tola_user,
            workflowlevel1=self.wflvl1,
            role=factories.Group(name=ROLE_ORGANIZATION_ADMIN))

        wflvl1_url = reverse('workflowlevel1-detail',
                             kwargs={'pk': self.wflvl1.id})
        user_george = factories.User(first_name='George', last_name='Harrison')
        tola_user_george = factories.TolaUser(
            user=user_george, organization=factories.Organization())
        tolauser_url = reverse('tolauser-detail',
                               kwargs={'pk': tola_user_george.id})
        role = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        role_url = reverse('group-detail', kwargs={'pk': role.id})
        data = {
            'role': role_url,
            'workflow_user': tolauser_url,
            'workflowlevel1': wflvl1_url,
        }

        request = self.factory.post(None, data)
        request.user = self.tola_user.user
        view = WorkflowTeamViewSet.as_view({'post': 'create'})
        response = view(request)
        self.assertEqual(response.status_code, 201)

        WorkflowTeam.objects.get(
            workflowlevel1=self.wflvl1,
            workflow_user=tola_user_george,
            role=role,
        )
Esempio n. 5
0
    def test_exceeded_seats_not_notify_when_one_of_multiple_role_removed(self):
        """ If user is org admin and program admin at the same time and users
         orgadmin role removed then org admin should not get notification
          because user still has seat as program admin."""
        external_response = self.ExternalResponse(None)
        Subscription.retrieve = Mock(return_value=external_response)
        self.tola_user.user.groups.add(self.group_org_admin)
        self.tola_user.user.save()
        user = factories.User(first_name='John', last_name='Lennon')

        self.org = Organization.objects.get(pk=self.org.id)

        tolauser = factories.TolaUser(user=user, organization=self.org)
        tolauser.user.groups.add(self.group_org_admin)
        tolauser.user.save()
        wflvl1_1 = factories.WorkflowLevel1(name='WorkflowLevel1_1')
        factories.WorkflowTeam(workflow_user=tolauser,
                               workflowlevel1=wflvl1_1,
                               role=self.group_program_admin)

        # It should notify the OrgAdmin
        organization = Organization.objects.get(pk=self.org.id)
        self.assertEqual(organization.chargebee_used_seats, 2)
        self.assertEqual(len(mail.outbox), 2)
        self.assertIn('Edit user exceeding notification',
                      mail.outbox[0].subject)

        tolauser.user.groups.remove(self.group_org_admin)
        self.assertEqual(organization.chargebee_used_seats, 2)
        self.assertEqual(len(mail.outbox), 2)
Esempio n. 6
0
    def test_user_to_hikaya_org_extra_fields(self):
        response = {
            'hikaya_user': {
                'hikaya_user_uuid': '13dac835-3860-4d9d-807e-d36a3c106057',
                'name': 'John Lennon',
                'employee_number': None,
                'title': 'mr',
                'privacy_disclaimer_accepted': True,
            },
            'organization': {
                'name': self.org.name,
                'url': '',
                'industry': '',
                'sector': '',
                'organization_uuid': self.org.organization_uuid,
                'chargebee_subscription_id': '',
                'chargebee_used_seats': ''
            }
        }

        user = factories.User(first_name='John', last_name='Lennon')
        auth_pipeline.user_to_hikaya(None, user, response)
        hikaya_user = HikayaUser.objects.get(name='John Lennon')

        self.assertEqual(hikaya_user.name, response['hikaya_user']['name'])
        self.assertEqual(hikaya_user.organization.name, self.org.name)
Esempio n. 7
0
    def test_user_to_hikaya_without_hikaya_user_data(self):
        # HikayaUser will be created with the default Org
        response = {
            'displayName': 'John Lennon',
            'emails': [{
                'type': 'account',
                'value': '*****@*****.**'
            }]
        }

        user = factories.User(first_name='John', last_name='Lennon')
        auth_pipeline.user_to_hikaya(None, user, response)
        hikaya_user = HikayaUser.objects.get(user=user)

        self.assertEqual(hikaya_user.name, response.get('displayName'))
        self.assertEqual(hikaya_user.organization.name, self.org.name)
        self.assertEqual(hikaya_user.country.country, self.country.country)

        # HikayaUser will be retrieved and Org won't be the default anymore
        new_org = factories.Organization(name='New Organization')
        hikaya_user.organization = new_org
        hikaya_user.save()
        auth_pipeline.user_to_hikaya(None, user, response)
        hikaya_user = HikayaUser.objects.get(user=user)

        self.assertEqual(hikaya_user.organization.name, new_org.name)
Esempio n. 8
0
    def test_get_or_create_user_with_user(self):
        """
        As we already have a user, it will be fetched and not updated
        """
        user = factories.User()
        strategy = StrategyTest()
        details = {'username': user.username}
        kwargs = {
            'username': '******',
            'email': '*****@*****.**'
        }
        backend = BackendTest()

        response = auth_pipeline.get_or_create_user(strategy,
                                                    details,
                                                    backend,
                                                    user=None,
                                                    args=None,
                                                    **kwargs)

        self.assertFalse(response['is_new'])
        self.assertEqual(response['user'].username, user.username)
        self.assertEqual(response['user'].email, user.email)
        self.assertNotEqual(kwargs['username'], user.username)
        self.assertNotEqual(kwargs['email'], user.email)
Esempio n. 9
0
    def test_response_201_create(self, mock_requests):
        external_response = {
            'url': 'http://testserver/api/tolauser/2',
            'tola_user_uuid': 1234567890,
            'name': 'John Lennon',
        }
        mock_requests.post.return_value = Mock(
            status_code=201, content=json.dumps(external_response))

        self.tola_user.user.is_staff = True
        self.tola_user.user.is_superuser = True
        self.tola_user.user.save()

        user = factories.User(first_name='John', last_name='Lennon')
        tolauser = factories.TolaUser(user=user, tola_user_uuid=1234567890)
        data = {
            'first_name': user.first_name,
            'last_name': user.last_name,
            'email': user.email,
            'username': user.username,
            'tola_user_uuid': tolauser.tola_user_uuid
        }

        response = register_user(data, tolauser)
        result = json.loads(response.content)

        self.assertEqual(result['tola_user_uuid'], 1234567890)
        mock_requests.post.assert_called_once_with(
            'https://tolatrack.com/accounts/register/',
            data={'username': '******',
                  'first_name': 'John',
                  'last_name': 'Lennon',
                  'tola_user_uuid': tolauser.tola_user_uuid,
                  'email': '*****@*****.**'},
            headers={'Authorization': 'Token TheToken'})
Esempio n. 10
0
    def test_filter_checklist_owner_org_admin(self):
        group_org_admin = factories.Group(name=ROLE_ORGANIZATION_ADMIN)
        self.tola_user.user.groups.add(group_org_admin)

        another_user = factories.User(first_name='Johnn', last_name='Lennon')
        another_tola = factories.TolaUser(user=another_user)
        wkflvl1_1 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wkflvl1_2 = factories.WorkflowLevel1(
            organization=self.tola_user.organization)
        wkflvl2_1 = factories.WorkflowLevel2(name='WorkflowLevel2 A',
                                             workflowlevel1=wkflvl1_1)
        wkflvl2_2 = factories.WorkflowLevel2(name='WorkflowLevel2 B',
                                             workflowlevel1=wkflvl1_2)
        checklist1 = factories.Checklist(name='Checklist A',
                                         owner=self.tola_user,
                                         workflowlevel2=wkflvl2_1)
        factories.Checklist(name='Checklist B',
                            owner=another_tola,
                            workflowlevel2=wkflvl2_2)

        request = self.factory.get('/api/checklist'
                                   '/?owner=%s' % self.tola_user.pk)
        request.user = self.tola_user.user
        view = ChecklistViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
        self.assertEqual(response.data[0]['name'], checklist1.name)
Esempio n. 11
0
    def test_demo_workflowteam_assignment_not_reassigned_on_update(
            self, mock_tsync):
        os.environ['APP_BRANCH'] = DEMO_BRANCH
        mock_tsync.create_instance.return_value = Mock()
        role = factories.Group(name=ROLE_VIEW_ONLY)
        wflvl1_0 = factories.WorkflowLevel1(
            id=DEFAULT_WORKFLOW_LEVEL_1S[0][0],
            name=DEFAULT_WORKFLOW_LEVEL_1S[0][1])
        wflvl1_1 = factories.WorkflowLevel1(
            id=DEFAULT_WORKFLOW_LEVEL_1S[1][0],
            name=DEFAULT_WORKFLOW_LEVEL_1S[1][1])

        tola_user = factories.TolaUser(user=factories.User(
            first_name='Ringo', last_name='Starr'))  # triggers the signal
        tola_user.name = 'Laura Pausini'
        tola_user.save()

        num_results = WorkflowTeam.objects.filter(
            workflow_user=tola_user, role=role,
            workflowlevel1=wflvl1_0).count()
        self.assertEqual(num_results, 1)
        num_results = WorkflowTeam.objects.filter(
            workflow_user=tola_user, role=role,
            workflowlevel1=wflvl1_1).count()
        self.assertEqual(num_results, 1)
Esempio n. 12
0
 def setUp(self):
     self.client = Client()
     self.user = factories.User()
     self.user.set_password('tola123')
     self.user.save()
     factories.TolaUser(user=self.user)
     self.client.login(username=self.user.username, password='******')
Esempio n. 13
0
    def test_save_data_customform_default_columns(self):
        user = factories.User(first_name='Homer', last_name='Simpson')
        sender_hikaya_user = factories.TolaUser(user=user)

        data = {
            'silo_id': self.silo.id,
            'data': {
                'name': 'John Lennon',
                'age': 40,
                'city': 'Liverpool'
            },
            'submitted_by': sender_hikaya_user.hikaya_user_uuid.__str__(),
        }

        request = self.factory.post('api/customform/save_data',
                                    data=json.dumps(data),
                                    content_type='application/json')
        request.user = self.hikaya_user.user
        view = CustomFormViewSet.as_view({'post': 'save_data'})
        response = view(request)

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.data['detail'], 'It was successfully saved.')
        self.assertEqual(self.silo.data_count, 1)

        # check if the default columns were created
        customform_silo = LabelValueStore.objects.get(silo_id=self.silo.id)
        table_column_names = customform_silo._dynamic_fields.keys()
        for default_col in CustomFormViewSet._default_columns:
            self.assertIn(default_col['name'], table_column_names)

        self.assertEqual(len(table_column_names), 6)
Esempio n. 14
0
    def test_check_seats_save_team_retrieve_subscription_fails(self):
        """
        The number of seats will be increased in the system but it's not
        possible to check the quantity of the plan because the retrieve
        failed.
        """
        self.tola_user.user.groups.add(self.group_org_admin)
        self.tola_user.user.save()
        self.org = Organization.objects.get(pk=self.org.id)
        user = factories.User(first_name='John', last_name='Lennon')
        tolauser = factories.TolaUser(user=user, organization=self.org)

        json_obj = {
            'message': "Sorry, we couldn't find that resource",
            'error_code': 'resource_not_found'
        }
        sub_response = APIError(404, json_obj)
        Subscription.retrieve = Mock(side_effect=sub_response)
        wflvl1 = factories.WorkflowLevel1(name='WorkflowLevel1')
        factories.WorkflowTeam(workflow_user=tolauser,
                               workflowlevel1=wflvl1,
                               role=self.group_program_admin)

        organization = Organization.objects.get(pk=self.org.id)
        self.assertEqual(organization.chargebee_used_seats, 2)
        self.assertEqual(len(mail.outbox), 0)
Esempio n. 15
0
    def test_form_validate_fail_owner_from_diff_org(self,
                                                    mock_get_workflowteams):
        mock_get_workflowteams.return_value = []
        user = factories.User(first_name='Homer', last_name='Simpson')
        factories.TolaUser(user=user, organization=self.tola_user.organization)
        another_user = factories.User(username='******')
        factories.TolaUser(user=another_user)
        silo = factories.Silo(owner=self.user)

        data = {
            'name': silo.name,
            'owner': another_user.id,
            'shared': [user.id],
        }
        form = forms.SiloForm(user=self.user, data=data, instance=silo)

        self.assertFalse(form.is_valid())
Esempio n. 16
0
 def setUp(self):
     self.client = Client()
     self.user = factories.User()
     self.user.set_password('hikaya123')
     self.user.save()
     factories.TolaUser(user=self.user)
     self.silo = factories.Silo(owner=self.user)
     self.client.login(username=self.user.username, password='******')
Esempio n. 17
0
 def setUp(self):
     factories.Organization(id=1)
     self.user = factories.User(first_name='Homer', last_name='Simpson')
     self.hikaya_user = factories.TolaUser(user=self.user)
     self.read = factories.Read(read_name="test_data",
                                owner=self.hikaya_user.user)
     self.silo = factories.Silo(owner=self.hikaya_user.user,
                                reads=[self.read])
     self.factory = APIRequestFactory()
Esempio n. 18
0
    def test_check_seats_save_team_exceed_notify(self):
        os.environ['APP_BRANCH'] = PRODUCTION_BRANCH
        header = {'category': ['exceed_paid_plan', 'from_production_email']}
        headers = {'X-SMTPAPI': json.dumps(header)}

        self.tola_user.user.groups.add(self.group_org_admin)
        self.tola_user.user.save()
        self.org = Organization.objects.get(pk=self.org.id)
        user = factories.User(first_name='John', last_name='Lennon')
        tolauser = factories.TolaUser(user=user, organization=self.org)

        external_response = self.ExternalResponse(None)
        Subscription.retrieve = Mock(return_value=external_response)
        wflvl1 = factories.WorkflowLevel1(name='WorkflowLevel1')
        factories.WorkflowTeam(workflow_user=tolauser,
                               workflowlevel1=wflvl1,
                               role=self.group_program_admin)

        # It should notify the OrgAdmin
        organization = Organization.objects.get(pk=self.org.id)
        self.assertEqual(organization.chargebee_used_seats, 2)
        self.assertEqual(len(mail.outbox), 1)
        self.assertIn('Edit user exceeding notification',
                      mail.outbox[0].subject)
        self.assertEqual(mail.outbox[0].to, [self.tola_user.user.email])
        self.assertEqual(mail.outbox[0].reply_to, ['*****@*****.**'])
        self.assertEqual(mail.outbox[0].bcc, ['*****@*****.**'])
        self.assertEqual(mail.outbox[0].extra_headers, headers)

        # Text body
        org_admin_name = 'Hi {},'.format(self.tola_user.name)
        self.assertIn(org_admin_name, mail.outbox[0].body)

        available_seats = 'Purchased user seats: 1'
        self.assertIn(available_seats, mail.outbox[0].body)

        used_seats = 'Current edit users in the system: 2'
        self.assertIn(used_seats, mail.outbox[0].body)

        payment_portal_url = 'example.com'
        self.assertIn(payment_portal_url, mail.outbox[0].body)

        # HTML body
        org_admin_name = '<br>Hi {},</span>'.format(self.tola_user.name)
        self.assertIn(org_admin_name, mail.outbox[0].alternatives[0][0])

        available_seats = 'Purchased user seats: <b>1</b>'
        self.assertIn(available_seats, mail.outbox[0].alternatives[0][0])

        used_seats = 'Current edit users in the system: <b>2</b>'
        self.assertIn(used_seats, mail.outbox[0].alternatives[0][0])

        payment_portal_url = '<a href="example.com" target="_blank">Payment ' \
                             'portal</a>'
        self.assertIn(payment_portal_url, mail.outbox[0].alternatives[0][0])
        self.assertIn('Payment portal', mail.outbox[0].alternatives[0][0])
Esempio n. 19
0
 def setUp(self):
     self.mapping_data = """{
             "0": {
                 "left_table_cols": ["number"],
                 "right_table_col": "number",
                 "merge_type": ""
             },
             "left_unmapped_cols": ["first name"],
             "right_unmapped_cols": ["last name"]
         }"""
     self.user = factories.User(username='******')
Esempio n. 20
0
    def test_list_silo_shared(self):
        user = factories.User(first_name='Marge', last_name='Simpson')
        factories.Silo(owner=user, shared=[self.user])

        request = self.factory.get('/api/silo/?user_uuid={}'.format(
            self.tola_user.tola_user_uuid))
        request.user = self.tola_user.user
        view = SiloViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
Esempio n. 21
0
    def test_merge_silo_with_specified_merge_type(self):
        mapping_data = """{
                        "0": {
                              "left_table_cols": ["number", "points"],
                              "right_table_col": "number",
                              "merge_type": "Avg"
                        },
                        "left_unmapped_cols": [],
                        "right_unmapped_cols": []
                    }"""

        user = factories.User(username='******')
        left_silo = factories.Silo(owner=user, name='left_silo', public=True)
        left_silo_r = factories.LabelValueStore(silo_id=left_silo.pk)
        left_silo_r['number'] = 1
        left_silo_r['points'] = 5
        left_silo_r.save()
        left_silo_r2 = factories.LabelValueStore(silo_id=left_silo.pk)
        left_silo_r2['number'] = 2
        left_silo_r2['points'] = 7
        left_silo_r2.save()
        factories.UniqueFields(silo=left_silo, name='number')

        right_silo = factories.Silo(owner=user, name='right_silo', public=True)
        right_silo_r = factories.LabelValueStore(silo_id=right_silo.pk)
        right_silo_r['number'] = 1
        right_silo_r.save()
        right_silo_r2 = factories.LabelValueStore(silo_id=right_silo.pk)
        right_silo_r2['number'] = 2
        right_silo_r2.save()
        factories.UniqueFields(silo=right_silo, name='number')

        merged_silo = factories.Silo(owner=user,
                                     name='merged_silo',
                                     public=True)

        response = merge_two_silos(mapping_data, left_silo.pk, right_silo.pk,
                                   merged_silo.pk)

        self.assertEqual(response, {
            'status': "success",
            'message': "Merged data successfully"
        })

        merged_silo = Silo.objects.get(pk=merged_silo.pk)
        self.assertEqual(
            LabelValueStore.objects.filter(silo_id=merged_silo.pk).count(), 4)

        merged_silo_rows = LabelValueStore.objects.filter(
            silo_id=merged_silo.pk)
        self.assertEqual(merged_silo_rows[0]['number'], 1)
        self.assertEqual(merged_silo_rows[1]['number'], 2)
        self.assertEqual(merged_silo_rows[2]['number'], 3.0)
        self.assertEqual(merged_silo_rows[3]['number'], 4.5)
Esempio n. 22
0
    def test_demo_env_no_wflvl1_matching(self):
        os.environ['APP_BRANCH'] = DEMO_BRANCH
        factories.WorkflowLevel1(name=DEFAULT_WORKFLOWLEVEL1_NAME)
        factories.TolaUser()  # triggers the signal
        self.assertEqual(WorkflowTeam.objects.all().count(), 0)

        factories.WorkflowLevel1(id=DEFAULT_WORKFLOWLEVEL1_ID, name='Any')
        factories.TolaUser(
            user=factories.User(first_name='Ringo', last_name='Starr')
        )  # triggers the signal
        self.assertEqual(WorkflowTeam.objects.all().count(), 0)
        os.environ['APP_BRANCH'] = ''
Esempio n. 23
0
    def test_form_validate_success_change_owner(self, mock_get_workflowteams):
        mock_get_workflowteams.return_value = []
        user = factories.User(first_name='Homer', last_name='Simpson')
        factories.TolaUser(user=user, organization=self.tola_user.organization)
        silo = factories.Silo(owner=self.user)

        data = {
            'name': silo.name,
            'owner': user.id,
        }
        form = forms.SiloForm(user=self.user, data=data, instance=silo)
        self.assertTrue(form.is_valid())
Esempio n. 24
0
    def test_demo_workflowteam_assignment(self):
        os.environ['APP_BRANCH'] = DEMO_BRANCH
        role = factories.Group(name=ROLE_VIEW_ONLY)
        wflvl1 = factories.WorkflowLevel1(id=DEFAULT_WORKFLOWLEVEL1_ID,
                                          name=DEFAULT_WORKFLOWLEVEL1_NAME)

        tola_user = factories.TolaUser(
            user=factories.User(first_name='Ringo', last_name='Starr')
        )  # triggers the signal
        WorkflowTeam.objects.get(
            workflow_user=tola_user, role=role, workflowlevel1=wflvl1)
        os.environ['APP_BRANCH'] = ''
Esempio n. 25
0
 def setUp(self):
     self.client = Client()
     self.user = factories.User()
     self.user.set_password('tola123')
     self.user.save()
     self.read_type = ReadType.objects.create(read_type="Ona")
     self.read = Read.objects.create(
         read_name="test_read1", owner=self.user, type=self.read_type,
         read_url='http://mysafeinfo.com/api/data?list='
                  'englishmonarchs&format=json')
     self.silo = factories.Silo(owner=self.user, reads=[self.read])
     factories.TolaUser(user=self.user)
     self.client.login(username=self.user.username, password='******')
    def setUp(self):
        self.factory = APIRequestFactory()
        self.tola_user = factories.TolaUser()

        user_ringo = factories.User(first_name='Ringo', last_name='Starr')
        tola_user_ringo = factories.TolaUser(
            user=user_ringo, organization=factories.Organization())
        self.wflvl1 = factories.WorkflowLevel1(
            organization=tola_user_ringo.organization)
        factories.WorkflowTeam(workflow_user=tola_user_ringo,
                               workflowlevel1=self.wflvl1,
                               partner_org=self.wflvl1.organization,
                               role=factories.Group(name=ROLE_VIEW_ONLY))
Esempio n. 27
0
    def test_exceeded_seats_not_notify_when_role_removed(self):
        """ If user has already seat as an orgadmin and when its role removed
         than org admin should not get notification email """
        external_response = self.ExternalResponse(None)
        Subscription.retrieve = Mock(return_value=external_response)

        self.tola_user.user.groups.add(self.group_org_admin)
        self.tola_user.user.save()
        self.org = Organization.objects.get(pk=self.org.id)
        self.assertEqual(self.org.chargebee_used_seats, 1)
        self.assertEqual(len(mail.outbox), 0)

        user = factories.User(first_name='John', last_name='Lennon')
        tolauser = factories.TolaUser(user=user, organization=self.org)
        tolauser.user.groups.add(self.group_org_admin)
        tolauser.user.save()
        self.org = Organization.objects.get(pk=self.org.id)

        self.assertEqual(self.org.chargebee_used_seats, 2)
        self.assertEqual(len(mail.outbox), 2)
        self.assertIn('Edit user exceeding notification',
                      mail.outbox[0].subject)

        user2 = factories.User(first_name='Leonard', last_name='Cohen')
        tolauser2 = factories.TolaUser(user=user2, organization=self.org)
        tolauser2.user.groups.add(self.group_org_admin)
        tolauser2.user.save()

        self.org = Organization.objects.get(pk=self.org.id)
        self.assertEqual(self.org.chargebee_used_seats, 3)
        self.assertEqual(len(mail.outbox), 5)

        # org admin removed but mail outbox still should be same
        tolauser2.user.groups.remove(self.group_org_admin)

        organization = Organization.objects.get(pk=self.org.id)
        self.assertEqual(organization.chargebee_used_seats, 2)
        self.assertEqual(len(mail.outbox), 5)
Esempio n. 28
0
    def test_demo_env_no_wflvl1_matching(self, mock_tsync):
        os.environ['APP_BRANCH'] = DEMO_BRANCH
        mock_tsync.create_instance.return_value = Mock()
        factories.WorkflowLevel1(name=DEFAULT_WORKFLOW_LEVEL_1S[0][1])
        factories.TolaUser()  # triggers the signal
        self.assertEqual(WorkflowTeam.objects.all().count(), 0)

        factories.WorkflowLevel1(name=DEFAULT_WORKFLOW_LEVEL_1S[1][1])
        factories.TolaUser(user=factories.User(
            first_name='George', last_name='Harrison'))  # triggers the signal
        self.assertEqual(WorkflowTeam.objects.all().count(), 0)

        factories.WorkflowLevel1(id=DEFAULT_WORKFLOW_LEVEL_1S[0][0],
                                 name='Any')
        factories.TolaUser(user=factories.User(
            first_name='Ringo', last_name='Starr'))  # triggers the signal
        self.assertEqual(WorkflowTeam.objects.all().count(), 0)

        factories.WorkflowLevel1(id=DEFAULT_WORKFLOW_LEVEL_1S[1][0],
                                 name='Any')
        factories.TolaUser(user=factories.User(
            first_name='Paul', last_name='McCartney'))  # triggers the signal
        self.assertEqual(WorkflowTeam.objects.all().count(), 0)
Esempio n. 29
0
    def test_list_read_shared(self):
        request = self.factory.get('/api/read/')
        request.user = self.hikaya_user.user
        view = ReadViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        owner = factories.User()
        read = factories.Read(read_name='It is shared', owner=owner)
        factories.Silo(shared=[self.hikaya_user.user], reads=[read])

        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)
Esempio n. 30
0
    def test_list_read_public(self):
        request = self.factory.get('/api/read/')
        request.user = self.tola_user.user
        view = ReadViewSet.as_view({'get': 'list'})
        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 0)

        owner = factories.User()
        read = factories.Read(read_name='It is public', owner=owner)
        factories.Silo(public=True, reads=[read])

        response = view(request)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(response.data), 1)