コード例 #1
0
    def run_test_profile_list(self,
                              api_version,
                              profile_serializer_class,
                              profile_params={},
                              query_dict={},
                              additional_filter_options={}):
        profile_type = profile_params.pop('profile_type', None)
        if not profile_type:
            (profile_type,
             _) = ProfileType.objects.get_or_create(value='temporary-type')
        for _ in range(3):
            profile = ExtendedUserProfileFactory(profile_type=profile_type,
                                                 **profile_params)
            profile.thumbnail = None
            profile.save()

        url = reverse('profile_list', args=[api_version + '/'])
        response = self.client.get('{url}?profile_type={type}&{qs}'.format(
            url=url, type=profile_type.value, qs=urlencode(query_dict)))
        response_profiles = json.loads(str(response.content, 'utf-8'))

        profile_list = profile_serializer_class(
            UserProfile.objects.filter(profile_type=profile_type,
                                       **additional_filter_options),
            context={
                'user': self.user
            },
            many=True,
        ).data

        self.assertListEqual(response_profiles, profile_list)
コード例 #2
0
    def test_v1_profile_data_serialization(self):
        """
        Make sure v1 profiles have "created_entries" array
        """
        location = 'Springfield, IL'
        profile = ExtendedUserProfileFactory(location=location)
        id = profile.id

        response = self.client.get(reverse('profile', args=[
            settings.API_VERSIONS['version_1'] + '/',
            id
        ]))
        response_entries = json.loads(str(response.content, 'utf-8'))

        self.assertEqual(response_entries['location'], location)

        created_entries = []
        entry_creators = EntryCreator.objects.filter(profile=profile).order_by('-id')

        created_entries = [EntrySerializerWithV1Creators(x.entry).data for x in entry_creators]
        self.assertEqual(response_entries['profile_id'], id)
        self.assertEqual(response_entries['created_entries'], created_entries)

        # make sure extended profile data does not show
        self.assertIn('program_type', response_entries)
コード例 #3
0
def generate_fellows(count):
    fellows_profile_type = ProfileType.objects.get(value='fellow')
    program_years = ProgramYear.objects.all()
    program_types = ProgramType.objects.all()

    for (program_year,
         program_type) in list(product(program_years, program_types)):
        for i in range(count):
            ext_profile = ExtendedUserProfileFactory(
                profile_type=fellows_profile_type,
                program_year=program_year,
                program_type=program_type)
            BasicEmailUserFactory.create(active=True, profile=ext_profile)
コード例 #4
0
    def handle(self, *args, **options):
        self.stdout.write('Creating Fellows')
        fellows_profile_type = ProfileType.objects.get(value='fellow')
        program_years = ProgramYear.objects.all()
        program_types = ProgramType.objects.all()

        for program_year in program_years:
            for program_type in program_types:
                for i in range(options['fellows_count']):
                    ext_profile = ExtendedUserProfileFactory(
                        profile_type=fellows_profile_type,
                        program_year=program_year,
                        program_type=program_type)
                    BasicEmailUserFactory.create(active=True,
                                                 profile=ext_profile)
コード例 #5
0
    def run_test_profile_list(
        self,
        api_version,
        profile_serializer_class,
        profile_params={},
        query_dict={},
        additional_filter_options={}
    ):
        profile_type = profile_params.pop('profile_type', None)
        if not profile_type:
            (profile_type, _) = ProfileType.objects.get_or_create(value='temporary-type')
        for _ in range(3):
            profile = ExtendedUserProfileFactory(profile_type=profile_type, **profile_params)
            profile.thumbnail = None
            profile.save()

        # Expected queryset
        ordering = query_dict.get('ordering', '-id').split(',')
        profile_list = UserProfile.objects.filter(
            profile_type=profile_type, **additional_filter_options
        ).order_by(*ordering)

        url = reverse('profile_list', args=[api_version + '/'])

        if api_version == settings.API_VERSIONS['version_1'] or api_version == settings.API_VERSIONS['version_2']:
            # v1 & v2 don't have pagination so we test only once
            response_profiles = json.loads(str(
                self.client.get(
                    '{url}?profile_type={type}&{qs}'.format(
                        url=url,
                        type=profile_type.value,
                        qs=urlencode(query_dict)
                    )
                ).content,
                'utf-8'
            ))
            serialized_profile_list = profile_serializer_class(
                profile_list,
                context={'user': self.user},
                many=True,
            ).data
            self.assertListEqual(response_profiles, serialized_profile_list)
            return None

        page_size = ProfilesPagination().get_page_size(
            request=Request(request=HttpRequest())
        )

        for page_number in range(ceil(len(profile_list) / page_size)):
            start_index = page_number * page_size
            end_index = start_index + page_size
            response_profiles = json.loads(str(
                self.client.get(
                    '{url}?profile_type={type}&{qs}&page={page_number}'.format(
                        url=url,
                        type=profile_type.value,
                        qs=urlencode(query_dict),
                        page_number=page_number + 1
                    )
                ).content,
                'utf-8'
            ))['results']
            serialized_profile_list = profile_serializer_class(
                profile_list[start_index:end_index],
                context={'user': self.user},
                many=True,
            ).data
            self.assertListEqual(response_profiles, serialized_profile_list)