Пример #1
0
    def test_export_impact(self):
        from_date = now() - timedelta(weeks=2)
        to_date = now() + timedelta(weeks=1)
        users = BlueBottleUserFactory.create_batch(5)

        co2 = ImpactType.objects.get(slug='co2')
        co2.active = True
        co2.save()
        water = ImpactType.objects.get(slug='water')
        water.active = True
        water.save()

        initiative = InitiativeFactory.create(owner=users[0])

        assignment = AssignmentFactory.create(owner=users[1],
                                              initiative=initiative)
        assignment.goals.create(type=co2, realized=300)
        assignment.goals.create(type=water, realized=750)

        data = {'from_date': from_date, 'to_date': to_date, '_save': 'Confirm'}
        tenant = connection.tenant
        result = plain_export(Exporter, tenant=tenant, **data)
        book = xlrd.open_workbook(result)

        self.assertEqual(
            book.sheet_by_name('Tasks').cell(0, 23).value,
            u'Reduce CO\u2082 emissions')
        self.assertEqual(book.sheet_by_name('Tasks').cell(1, 23).value, 300)
        self.assertEqual(
            book.sheet_by_name('Tasks').cell(0, 24).value, u'Save water')
        self.assertEqual(book.sheet_by_name('Tasks').cell(1, 24).value, 750)
Пример #2
0
    def test_export_custom_user_fields(self):
        from_date = now() - timedelta(weeks=2)
        to_date = now() + timedelta(weeks=1)

        colour = CustomMemberFieldSettings.objects.create(
            name='colour', description='Favourite colour')

        BlueBottleUserFactory.create_batch(2)
        user = BlueBottleUserFactory.create(email='*****@*****.**')
        BlueBottleUserFactory.create_batch(2)

        CustomMemberField.objects.create(member=user,
                                         field=colour,
                                         value='Parblue Yellow')
        initiative = InitiativeFactory.create(owner=user)
        assignment = AssignmentFactory.create(owner=user,
                                              initiative=initiative)
        ApplicantFactory.create(activity=assignment, user=user)

        data = {'from_date': from_date, 'to_date': to_date, '_save': 'Confirm'}
        tenant = connection.tenant
        result = plain_export(Exporter, tenant=tenant, **data)
        book = xlrd.open_workbook(result)

        self.assertEqual(book.sheet_by_name('Users').ncols, 12)
        t = 1
        while t < book.sheet_by_name('Users').nrows:
            if book.sheet_by_name('Users').cell(
                    t, 5).value == '*****@*****.**':
                self.assertEqual(
                    book.sheet_by_name('Users').cell(t, 11).value,
                    'Parblue Yellow')
            t += 1

        self.assertEqual(
            book.sheet_by_name('Task contributions').cell(0, 13).value,
            'Favourite colour')
        self.assertEqual(
            book.sheet_by_name('Task contributions').cell(1, 13).value,
            'Parblue Yellow')
Пример #3
0
    def test_export_user_segments(self):
        from_date = now() - timedelta(weeks=2)
        to_date = now() + timedelta(weeks=1)
        users = BlueBottleUserFactory.create_batch(5)
        segment_type = SegmentTypeFactory.create(name='Department')
        engineering = SegmentFactory.create(type=segment_type,
                                            name='Engineering')
        rubbish = SegmentFactory.create(type=segment_type, name='Rubbish')
        users[0].segments.add(engineering)
        initiative = InitiativeFactory.create(owner=users[0])
        assignment = AssignmentFactory.create(owner=users[1],
                                              initiative=initiative)
        assignment.segments.add(engineering)
        assignment.segments.add(rubbish)
        ApplicantFactory.create(activity=assignment, user=users[2])

        data = {'from_date': from_date, 'to_date': to_date, '_save': 'Confirm'}
        tenant = connection.tenant
        result = plain_export(Exporter, tenant=tenant, **data)
        book = xlrd.open_workbook(result)

        self.assertEqual(book.sheet_by_name('Users').ncols, 12)
        self.assertEqual(
            book.sheet_by_name('Users').cell(0, 11).value, 'Department')

        t = 0
        while t < book.sheet_by_name('Users').nrows:
            if book.sheet_by_name('Users').cell(t, 5).value == users[0].email:
                self.assertEqual(
                    book.sheet_by_name('Users').cell(t, 11).value,
                    'Engineering')
            t += 1

        self.assertEqual(
            book.sheet_by_name('Tasks').cell(0, 23).value, 'Department')

        t = 0
        while t < book.sheet_by_name('Users').nrows:
            if book.sheet_by_name('Users').cell(t, 5).value == users[0].email:
                self.assertTrue(
                    book.sheet_by_name('Tasks').cell(t, 23).value in
                    ['Engineering, Rubbish', 'Rubbish, Engineering'])
            t += 1
Пример #4
0
    def test_fields_appear(self):
        request = self.request_factory.get('/')
        request.user = MockUser()

        for field in ['member_link', 'task_link']:
            self.assertIn(field, self.skill_admin.get_fields(request))

        skill = SkillFactory.create()
        members = BlueBottleUserFactory.create_batch(3)
        for member in members:
            member.skills = [skill]
            member.save()

        TaskFactory.create_batch(2, skill=skill)

        skill_url = reverse('admin:tasks_skill_change', args=(skill.id, ))
        response = self.client.get(skill_url)
        self.assertEqual(response.status_code, 200)

        self.assertContains(response, '3 users')
        self.assertContains(response, '2 tasks')
Пример #5
0
    def initTestData(self):
        self.year = datetime.now().year

        # Project Phases
        done_complete = ProjectPhase.objects.get(slug="done-complete")
        done_incomplete = ProjectPhase.objects.get(slug="done-incomplete")

        # Users
        self.users = BlueBottleUserFactory.create_batch(200)

        # Projects
        some_day = datetime(year=self.year, month=2, day=27, tzinfo=pytz.UTC)
        project1 = ProjectFactory.create(owner=self.users[0],
                                         status=done_complete,
                                         campaign_ended=some_day)
        ProjectFactory.create(owner=self.users[0], status=done_incomplete)

        # Tasks
        task = TaskFactory.create(author=self.users[0],
                                  project=project1,
                                  people_needed=2,
                                  status='realized')

        for month in range(1, 12):
            for x in range(1, 10):
                task_member = TaskMemberFactory.create(
                    time_spent=10,
                    member=self.users[month * 10 + x],
                    task=task,
                    status=TaskMember.TaskMemberStatuses.applied)
                task_member.status = TaskMember.TaskMemberStatuses.realized
                task_member.save()

        # xls export
        self.xls_file_name = 'test.xlsx'
        self.xls_file_path = os.path.join(settings.PROJECT_ROOT,
                                          self.xls_file_name)