Example #1
0
    def test_list_inactive(self):
        SegmentTypeFactory.create(is_active=False)

        response = self.client.get(self.url)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(len(response.json()['data']), 5)
Example #2
0
    def test_user_created_segments_missing_create(self, authenticate_request):
        member_settings = MemberPlatformSettings.load()
        member_settings.create_segments = True
        member_settings.save()
        SegmentTypeFactory.create(name='Team')
        SegmentTypeFactory.create(name='Unit')

        with self.settings(TOKEN_AUTH={}):
            user, created = self.auth.authenticate()
            self.assertEqual(user.email, '*****@*****.**')
            self.assertEqual(len(user.segments.all()), 2)
    def setUp(self):

        team_type = SegmentTypeFactory.create(name='Team')
        self.team = SegmentFactory.create(name='Online Marketing',
                                          type=team_type)
        self.other_team = SegmentFactory.create(name='Direct Marketing',
                                                type=team_type)

        unit_type = SegmentTypeFactory.create(name='Unit')
        self.unit = SegmentFactory.create(name='Marketing', type=unit_type)
        SegmentFactory.create(name='Communications', type=unit_type)

        self.user = BlueBottleUserFactory()
        self.user.segments.add(self.team)
        self.user.segments.add(self.unit)

        super(ActivitySegmentsTestCase, self).setUp()
Example #4
0
    def test_user_created_segments_missing(self, authenticate_request):
        BlueBottleUserFactory.create(remote_id='*****@*****.**')
        team = SegmentTypeFactory.create(name='Team')
        SegmentFactory.create(name='Online Marketing', type=team)
        SegmentFactory.create(name='Direct Marketing', type=team)

        unit = SegmentTypeFactory.create(name='Unit')
        SegmentFactory.create(name='Marketing', type=unit)
        SegmentFactory.create(name='Communications', type=unit)

        with self.settings(TOKEN_AUTH={}):
            user, created = self.auth.authenticate()

            self.assertEqual(authenticate_request.call_count, 1)
            self.assertFalse(created)
            self.assertEqual(user.email, '*****@*****.**')
            self.assertEqual(len(user.segments.all()), 0)
Example #5
0
    def test_user_created_segments_list_no_match_create(
            self, authenticate_request):
        member_settings = MemberPlatformSettings.load()
        member_settings.create_segments = True
        member_settings.save()
        SegmentTypeFactory.create(name='Team')

        with self.settings(TOKEN_AUTH={}):
            user, created = self.auth.authenticate()

            self.assertEqual(authenticate_request.call_count, 1)
            self.assertTrue(created)
            self.assertEqual(user.email, '*****@*****.**')
            self.assertEqual(len(user.segments.all()), 1)
            self.assertEqual(user.segments.first().name, 'Online Marketing')
            self.assertEqual(user.segments.first().alternate_names,
                             ['Online Marketing'])
Example #6
0
    def setUp(self):
        super(SegmentListAPITestCase, self).setUp()

        self.client = JSONAPITestClient()

        self.url = reverse('segment-list')
        self.user = BlueBottleUserFactory()
        self.segment_type = SegmentTypeFactory.create()
        self.segments = SegmentFactory.create_batch(20, type=self.segment_type)
Example #7
0
 def test_activity_segment_admin(self):
     event = EventFactory.create()
     event_url = reverse('admin:events_event_change', args=(event.id, ))
     response = self.client.get(event_url)
     self.assertNotContains(response, 'Segment:')
     segment_type = SegmentTypeFactory.create()
     SegmentFactory.create_batch(5, type=segment_type)
     response = self.client.get(event_url)
     self.assertContains(response, 'Segment:')
Example #8
0
    def test_user_created_segments(self, authenticate_request):
        team = SegmentTypeFactory.create(name='Team')
        team_segment = SegmentFactory.create(name='Online Marketing',
                                             type=team)
        SegmentFactory.create(name='Direct Marketing', type=team)

        unit = SegmentTypeFactory.create(name='Unit')
        unit_segment = SegmentFactory.create(name='Marketing', type=unit)
        SegmentFactory.create(name='Communications', type=unit)

        with self.settings(TOKEN_AUTH={}):
            user, created = self.auth.authenticate()

            self.assertEqual(authenticate_request.call_count, 1)
            self.assertTrue(created)
            self.assertEqual(user.email, '*****@*****.**')
            self.assertTrue(team_segment in user.segments.all())
            self.assertTrue(unit_segment in user.segments.all())
Example #9
0
    def setUp(self):
        super(SegmentTypeListAPITestCase, self).setUp()

        self.client = JSONAPITestClient()

        self.url = reverse('segment-type-list')
        self.user = BlueBottleUserFactory()

        for i in range(5):
            segment_type = SegmentTypeFactory.create()
            SegmentFactory.create_batch(3, type=segment_type)
Example #10
0
    def test_segment_admin(self):
        segment_type = SegmentTypeFactory.create()
        SegmentFactory.create_batch(5, type=segment_type)

        segment_url = reverse('admin:segments_segmenttype_change',
                              args=(segment_type.id, ))
        response = self.client.get(segment_url)
        self.assertContains(response, 'Segment')

        list_url = reverse('admin:segments_segmenttype_changelist')
        response = self.client.get(list_url)
        self.assertContains(response, 'Number of segments')
Example #11
0
    def test_user_created_segments_list_no_match(self, authenticate_request):
        member_settings = MemberPlatformSettings.load()
        member_settings.create_segments = False
        member_settings.save()
        team = SegmentTypeFactory.create(name='Team')
        SegmentFactory.create(
            name='Online Marketing',
            type=team,
        )
        SegmentFactory.create(name='Direct Marketing', type=team)

        with self.settings(TOKEN_AUTH={}):
            user, created = self.auth.authenticate()

            self.assertEqual(authenticate_request.call_count, 1)
            self.assertTrue(created)
            self.assertEqual(user.email, '*****@*****.**')
            self.assertEqual(len(user.segments.all()), 0)
Example #12
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