Esempio n. 1
0
    def test_more_results(self):
        InitiativeFactory.create_batch(19, owner=self.owner, status='approved')
        InitiativeFactory.create(status="approved")

        response = self.client.get(self.url,
                                   HTTP_AUTHORIZATION="JWT {0}".format(
                                       self.owner.get_jwt_token()))
        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 20)
        self.assertEqual(len(data['data']), 8)
Esempio n. 2
0
    def test_filter_owner(self):
        InitiativeFactory.create_batch(2, status='submitted', owner=self.owner)
        InitiativeFactory.create_batch(4, status='submitted')

        response = self.client.get(
            self.url + '?filter[owner.id]={}'.format(self.owner.pk),
            HTTP_AUTHORIZATION="JWT {0}".format(self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 2)
        self.assertEqual(
            data['data'][0]['relationships']['owner']['data']['id'],
            str(self.owner.pk))
Esempio n. 3
0
    def test_filter_promoter(self):
        """
        User should see initiatives where self activity manager when in submitted
        """
        InitiativeFactory.create_batch(2,
                                       status='submitted',
                                       promoter=self.owner)
        InitiativeFactory.create_batch(4, status='approved')

        response = self.client.get(
            self.url + '?filter[owner.id]={}'.format(self.owner.pk),
            HTTP_AUTHORIZATION="JWT {0}".format(self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 2)
Esempio n. 4
0
    def test_export(self):
        from_date = now() - timedelta(weeks=2)
        to_date = now() + timedelta(weeks=1)
        data = {'from_date': from_date, 'to_date': to_date, '_save': 'Confirm'}
        tenant = connection.tenant
        initiatives = InitiativeFactory.create_batch(4)
        for initiative in initiatives:
            EventFactory.create_batch(3, initiative=initiative)
            AssignmentFactory.create_batch(2, initiative=initiative)
            FundingFactory.create_batch(1, initiative=initiative)

        result = plain_export(Exporter, tenant=tenant, **data)
        book = xlrd.open_workbook(result)
        self.assertEqual(book.sheet_by_name('Users').ncols, 11)
        self.assertEqual(book.sheet_by_name('Users').nrows, 41)
        self.assertEqual(book.sheet_by_name('Initiatives').nrows, 5)
        self.assertEqual(book.sheet_by_name('Funding activities').nrows, 5)
        self.assertEqual(book.sheet_by_name('Events').nrows, 13)
        self.assertEqual(
            book.sheet_by_name('Events').cell(0, 13).value, 'Start')
        self.assertEqual(
            book.sheet_by_name('Events').cell(0, 14).value, 'Time needed')

        self.assertEqual(book.sheet_by_name('Tasks').nrows, 9)
        self.assertEqual(
            book.sheet_by_name('Tasks').cell(0, 16).value, 'Preparation time')
        self.assertEqual(
            book.sheet_by_name('Tasks').cell(0, 17).value, 'Start time')
        self.assertEqual(
            book.sheet_by_name('Tasks').cell(0, 19).value, 'End date')
Esempio n. 5
0
    def test_filter_owner_activity(self):
        InitiativeFactory.create_batch(4, status='submitted')

        with_activity = InitiativeFactory.create(status='submitted')
        activity = EventFactory.create(owner=self.owner,
                                       initiative=with_activity)

        response = self.client.get(
            self.url + '?filter[owner.id]={}'.format(self.owner.pk),
            HTTP_AUTHORIZATION="JWT {0}".format(self.owner.get_jwt_token()))

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 1)
        self.assertEqual(
            data['data'][0]['relationships']['activities']['data'][0]['id'],
            str(activity.pk))
Esempio n. 6
0
    def test_filter_not_owner(self):
        """
        Non-owner should only see approved initiatives
        """
        InitiativeFactory.create_batch(2, status='submitted', owner=self.owner)
        InitiativeFactory.create_batch(4, status='approved', owner=self.owner)
        InitiativeFactory.create_batch(3, status='approved')

        response = self.client.get(
            self.url + '?filter[owner.id]={}'.format(self.owner.pk),
            user=self.visitor)

        data = json.loads(response.content)

        self.assertEqual(data['meta']['pagination']['count'], 4)
        self.assertEqual(
            data['data'][0]['relationships']['owner']['data']['id'],
            str(self.owner.pk))