Пример #1
0
    def setUp(self):
        voucher = UserFactory.create()
        country = CountryFactory()
        region = RegionFactory()
        city = CityFactory()
        self.user = UserFactory.create(
            userprofile={'vouched': False,
                         'geo_country': country,
                         'geo_region': region,
                         'geo_city': city})
        self.user.userprofile.vouch(voucher.userprofile)
        group = GroupFactory.create()
        group.add_member(self.user.userprofile)
        skill = SkillFactory.create()
        self.user.userprofile.skills.add(skill)
        self.user.userprofile.externalaccount_set.create(type=ExternalAccount.TYPE_SUMO,
                                                         identifier='Apitest')

        self.resource_url = reverse(
            'api_dispatch_list',
            kwargs={'api_name': 'v1', 'resource_name': 'users'})
        self.mozilla_app = APIAppFactory.create(
            owner=self.user, is_mozilla_app=True)
        self.mozilla_resource_url = urlparams(
            self.resource_url, app_name=self.mozilla_app.name,
            app_key=self.mozilla_app.key)
        self.community_app = APIAppFactory.create(
            owner=self.user, is_mozilla_app=False)
        self.community_resource_url = urlparams(
            self.resource_url, app_name=self.community_app.name,
            app_key=self.community_app.key)
Пример #2
0
    def setUp(self):
        voucher = UserFactory.create()
        country = CountryFactory()
        region = RegionFactory()
        city = CityFactory()
        self.user = UserFactory.create(userprofile={
            'vouched': False,
            'country': country,
            'region': region,
            'city': city
        })
        self.user.userprofile.vouch(voucher.userprofile)
        group = GroupFactory.create()
        group.add_member(self.user.userprofile)
        skill = SkillFactory.create()
        self.user.userprofile.skills.add(skill)
        self.user.userprofile.externalaccount_set.create(
            type=ExternalAccount.TYPE_SUMO, identifier='Apitest')

        self.resource_url = reverse('api_dispatch_list',
                                    kwargs={
                                        'api_name': 'v1',
                                        'resource_name': 'users'
                                    })
        self.mozilla_app = APIAppFactory.create(owner=self.user,
                                                is_mozilla_app=True)
        self.mozilla_resource_url = urlparams(self.resource_url,
                                              app_name=self.mozilla_app.name,
                                              app_key=self.mozilla_app.key)
        self.community_app = APIAppFactory.create(owner=self.user,
                                                  is_mozilla_app=False)
        self.community_resource_url = urlparams(
            self.resource_url,
            app_name=self.community_app.name,
            app_key=self.community_app.key)
Пример #3
0
 def test_request_with_huge_limit(self):
     client = Client()
     url = urlparams(self.mozilla_resource_url, limit=200000000000000000000)
     response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     data = json.loads(response.content)
     eq_(data['meta']['limit'], 1)
Пример #4
0
 def test_get_detail_mozilla_app(self):
     client = Client()
     url = reverse('api_dispatch_detail',
                   kwargs={'api_name': 'v1', 'resource_name': 'users',
                           'pk': self.user.userprofile.id})
     url = urlparams(url, app_name=self.mozilla_app.name,
                     app_key=self.mozilla_app.key)
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     profile = self.user.userprofile
     eq_(response.status_code, 200)
     eq_(data['id'], profile.id)
     eq_(data['full_name'], profile.full_name)
     eq_(data['is_vouched'], profile.is_vouched)
     eq_(data['vouched_by'], profile.vouched_by.id)
     # eq_(data['date_vouched'], profile.date_vouched)
     eq_(data['groups'], list(profile.groups.values_list('name', flat=True)))
     eq_(data['skills'], list(profile.skills.values_list('name', flat=True)))
     eq_(data['accounts'],
         [{'identifier': a.identifier, 'type': a.type}
          for a in profile.externalaccount_set.all()])
     eq_(data['bio'], profile.bio)
     eq_(data['photo'], profile.photo)
     eq_(data['photo_thumbnail'], profile.get_photo_url())
     eq_(data['ircname'], profile.ircname)
     eq_(data['country'], profile.geo_country.code)
     eq_(data['region'], profile.geo_region.name)
     eq_(data['city'], profile.geo_city.name)
     eq_(data['date_mozillian'], profile.date_mozillian)
     eq_(data['timezone'], profile.timezone)
     eq_(data['email'], profile.email)
     eq_(data['url'],
         absolutify(reverse('phonebook:profile_view',
                            args=[profile.user.username])))
Пример #5
0
 def test_search_no_ajax(self):
     user = UserFactory.create()
     group = GroupFactory.create()
     url = urlparams(reverse('groups:search_groups'), term=group.name)
     with self.login(user) as client:
         response = client.get(url, follow=True)
     ok_(isinstance(response, HttpResponseBadRequest))
Пример #6
0
    def process_request(self, request):
        prefixer = urlresolvers.Prefixer(request)
        urlresolvers.set_url_prefix(prefixer)
        full_path = prefixer.fix(prefixer.shortened_path)

        if self._is_lang_change(request):
            # Blank out the locale so that we can set a new one. Remove lang
            # from the query params so we don't have an infinite loop.
            prefixer.locale = ''
            new_path = prefixer.fix(prefixer.shortened_path)
            query = dict((smart_str(k), request.GET[k]) for k in request.GET)
            query.pop('lang')
            return HttpResponsePermanentRedirect(urlparams(new_path, **query))

        if full_path != request.path:
            query_string = request.META.get('QUERY_STRING', '')
            full_path = urllib.quote(full_path.encode('utf-8'))

            if query_string:
                full_path = '%s?%s' % (full_path, query_string)

            response = HttpResponsePermanentRedirect(full_path)

            # Vary on Accept-Language if we changed the locale
            old_locale = prefixer.locale
            new_locale, _ = urlresolvers.split_path(full_path)
            if old_locale != new_locale:
                response['Vary'] = 'Accept-Language'

            return response

        request.path_info = '/' + prefixer.shortened_path
        request.locale = prefixer.locale
        activate(prefixer.locale)
Пример #7
0
 def test_request_with_huge_limit(self):
     client = Client()
     url = urlparams(self.mozilla_resource_url, limit=200000000000000000000)
     response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     data = json.loads(response.content)
     eq_(data['meta']['limit'], 1)
Пример #8
0
 def test_search_no_ajax(self):
     user = UserFactory.create()
     group = GroupFactory.create()
     url = urlparams(reverse('groups:search_groups'), term=group.name)
     with self.login(user) as client:
         response = client.get(url, follow=True)
     ok_(isinstance(response, HttpResponseBadRequest))
Пример #9
0
    def test_filter_all(self):
        """If they specify no filters, they get all the members"""
        # Make user 1 the group curator so they can see requests
        self.group.curators.add(self.user_1.userprofile)
        self.group.accepting_new_members = 'by_request'
        self.group.save()
        # Make user 2 a full member
        self.group.add_member(self.user_2.userprofile, GroupMembership.MEMBER)
        member_membership = self.group.groupmembership_set.get(userprofile__user=self.user_2)

        # Make user 3 a pending member
        self.user_3 = UserFactory.create()
        self.group.add_member(self.user_3.userprofile, GroupMembership.PENDING)
        pending_membership = self.group.groupmembership_set.get(userprofile__user=self.user_3)

        # Make user 4 a pending_terms member
        self.user_4 = UserFactory.create()
        self.group.add_member(self.user_4.userprofile, GroupMembership.PENDING_TERMS)
        pending_terms_membership = self.group.groupmembership_set.get(
            userprofile__user=self.user_4)

        url = urlparams(self.url, filtr='all')
        with self.login(self.user_1) as client:
            response = client.get(url, follow=True)
        people = response.context['people'].object_list
        ok_(member_membership in people)
        ok_(pending_membership in people)
        ok_(pending_terms_membership in people)
Пример #10
0
    def test_filter_all(self):
        """If they specify no filters, they get all the members"""
        # Make user 1 the group curator so they can see requests
        self.group.curators.add(self.user_1.userprofile)
        self.group.accepting_new_members = 'by_request'
        self.group.save()
        # Make user 2 a full member
        self.group.add_member(self.user_2.userprofile, GroupMembership.MEMBER)
        member_membership = self.group.groupmembership_set.get(
            userprofile__user=self.user_2)

        # Make user 3 a pending member
        self.user_3 = UserFactory.create()
        self.group.add_member(self.user_3.userprofile, GroupMembership.PENDING)
        pending_membership = self.group.groupmembership_set.get(
            userprofile__user=self.user_3)

        # Make user 4 a pending_terms member
        self.user_4 = UserFactory.create()
        self.group.add_member(self.user_4.userprofile,
                              GroupMembership.PENDING_TERMS)
        pending_terms_membership = self.group.groupmembership_set.get(
            userprofile__user=self.user_4)

        url = urlparams(self.url, filtr='all')
        with self.login(self.user_1) as client:
            response = client.get(url, follow=True)
        people = response.context['people'].object_list
        ok_(member_membership in people)
        ok_(pending_membership in people)
        ok_(pending_terms_membership in people)
Пример #11
0
 def test_community_app_does_not_allow_community_sites(self):
     user = UserFactory.create(userprofile={'allows_community_sites': False})
     client = Client()
     url = urlparams(self.community_resource_url, email=user.email)
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(response.status_code, 200)
     eq_(len(data['objects']), 0)
Пример #12
0
 def test_search_incomplete_profile(self):
     user = UserFactory.create(vouched=True, userprofile={"full_name": ""})
     group = GroupFactory.create(visible=True)
     url = urlparams(reverse("groups:skills-autocomplete"), q=group.name)
     with self.login(user) as client:
         response = client.get(url, follow=True, **{"HTTP_X_REQUESTED_WITH": "XMLHttpRequest"})
     eq_(response.status_code, 200)
     eq_(response.get("content-type"), "application/json")
Пример #13
0
 def test_search_username(self):
     user = UserFactory.create()
     url = urlparams(self.mozilla_resource_url, username=user.username)
     client = Client()
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #14
0
 def test_search_username(self):
     user = UserFactory.create()
     url = urlparams(self.mozilla_resource_url, username=user.username)
     client = Client()
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #15
0
 def test_search_unvouched(self):
     user = UserFactory.create(vouched=False)
     group = GroupFactory.create(visible=True)
     url = urlparams(reverse("groups:search_groups"), term=group.name)
     with self.login(user) as client:
         response = client.get(url, follow=True, **{"HTTP_X_REQUESTED_WITH": "XMLHttpRequest"})
     eq_(response.status_code, 200)
     eq_(response.get("content-type"), "application/json")
Пример #16
0
 def test_is_vouched_true(self):
     UserFactory.create()
     UserFactory.create(vouched=False)
     client = Client()
     url = urlparams(self.mozilla_resource_url, is_vouched='true')
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     for obj in data['objects']:
         ok_(obj['is_vouched'])
Пример #17
0
 def test_mozilla_app_does_allows_mozilla_sites(self):
     user = UserFactory.create(userprofile={'allows_mozilla_sites': True})
     client = Client()
     url = urlparams(self.mozilla_resource_url, email=user.email)
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(response.status_code, 200)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['email'], user.email)
Пример #18
0
 def test_search_name(self):
     user = UserFactory.create(userprofile={'full_name': u'Νίκος Κούκος'})
     client = Client()
     url = urlparams(self.mozilla_resource_url,
                     name=user.userprofile.full_name)
     request = client.get(url, follow=True)
     data = json.loads(request.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #19
0
 def test_query_with_space(self):
     city = CityFactory.create(name='Mountain View')
     user = UserFactory.create(userprofile={'geo_city': city})
     client = Client()
     url = urlparams(self.mozilla_resource_url, city='mountain view')
     request = client.get(url, follow=True)
     data = json.loads(request.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #20
0
 def test_search_incomplete_profile(self):
     user = UserFactory.create(vouched=True, userprofile={'full_name': ''})
     group = GroupFactory.create(visible=True)
     url = urlparams(reverse('groups:skills-autocomplete'), q=group.name)
     with self.login(user) as client:
         response = client.get(url, follow=True,
                               **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})
     eq_(response.status_code, 200)
     eq_(response.get('content-type'), 'application/json')
Пример #21
0
 def test_is_vouched_false(self):
     UserFactory.create()
     user = UserFactory.create(vouched=False)
     client = Client()
     url = urlparams(self.mozilla_resource_url, is_vouched='false')
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #22
0
 def test_get_detail_community_app(self):
     client = Client()
     url = reverse('api_dispatch_detail',
                   kwargs={'api_name': 'v1', 'resource_name': 'users',
                           'pk': self.user.userprofile.id})
     url = urlparams(url, app_name=self.community_app.name,
                     app_key=self.community_app.key)
     response = client.get(url, follow=True)
     eq_(response.status_code, 403)
Пример #23
0
 def test_mozilla_app_does_allows_mozilla_sites(self):
     user = UserFactory.create(userprofile={'allows_mozilla_sites': True})
     client = Client()
     url = urlparams(self.mozilla_resource_url, email=user.email)
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(response.status_code, 200)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['email'], user.email)
Пример #24
0
 def test_search_unvouched(self):
     user = UserFactory.create(vouched=False)
     group = GroupFactory.create(visible=True)
     url = urlparams(reverse('groups:search_groups'), term=group.name)
     with self.login(user) as client:
         response = client.get(url, follow=True,
                               **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})
     eq_(response.status_code, 200)
     eq_(response.get('content-type'), 'application/json')
Пример #25
0
 def test_request_with_huge_offset(self):
     UserFactory.create()
     UserFactory.create()
     client = Client()
     url = urlparams(self.mozilla_resource_url, offset=100000000)
     response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     data = json.loads(response.content)
     eq_(data['meta']['offset'], data['meta']['total_count'])
Пример #26
0
 def test_community_app_does_not_allow_community_sites(self):
     user = UserFactory.create(
         userprofile={'allows_community_sites': False})
     client = Client()
     url = urlparams(self.community_resource_url, email=user.email)
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(response.status_code, 200)
     eq_(len(data['objects']), 0)
Пример #27
0
 def test_is_vouched_true(self):
     UserFactory.create()
     UserFactory.create(vouched=False)
     client = Client()
     url = urlparams(self.mozilla_resource_url, is_vouched='true')
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     for obj in data['objects']:
         ok_(obj['is_vouched'])
Пример #28
0
 def test_query_with_space(self):
     city = CityFactory.create(name='Mountain View')
     user = UserFactory.create(userprofile={'geo_city': city})
     client = Client()
     url = urlparams(self.mozilla_resource_url, city='mountain view')
     request = client.get(url, follow=True)
     data = json.loads(request.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #29
0
 def test_request_with_huge_offset(self):
     UserFactory.create()
     UserFactory.create()
     client = Client()
     url = urlparams(self.mozilla_resource_url, offset=100000000)
     response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     data = json.loads(response.content)
     eq_(data['meta']['offset'], data['meta']['total_count'])
Пример #30
0
 def test_search_name(self):
     user = UserFactory.create(userprofile={'full_name': u'Νίκος Κούκος'})
     client = Client()
     url = urlparams(self.mozilla_resource_url,
                     name=user.userprofile.full_name)
     request = client.get(url, follow=True)
     data = json.loads(request.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #31
0
    def test_send_invitation_email_no_curator_manager(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile, redeemer=redeemer.userprofile)
        user = UserFactory.create()

        with self.login(user) as client:
            url = urlparams(reverse("groups:send_invitation_email", args=[invite.pk]), "invitation")
            response = client.get(url, follow=True)
            eq_(response.status_code, 404)
Пример #32
0
 def test_is_vouched_false(self):
     UserFactory.create()
     user = UserFactory.create(vouched=False)
     client = Client()
     url = urlparams(self.mozilla_resource_url, is_vouched='false')
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #33
0
 def setUp(self):
     self.resource_url = reverse(
         'api_dispatch_list',
         kwargs={'api_name': 'v1', 'resource_name': 'skills'})
     self.user = UserFactory.create()
     self.app = APIAppFactory.create(owner=self.user,
                                     is_mozilla_app=True)
     self.resource_url = urlparams(self.resource_url,
                                   app_name=self.app.name,
                                   app_key=self.app.key)
Пример #34
0
 def test_search_region(self):
     region = RegionFactory.create(name='la lo')
     user = UserFactory.create(userprofile={'geo_region': region})
     url = urlparams(self.mozilla_resource_url,
                     region=user.userprofile.geo_region.name)
     client = Client()
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #35
0
 def test_search_country(self):
     country = CountryFactory.create(code='fr')
     user = UserFactory.create(userprofile={'geo_country': country})
     url = urlparams(self.mozilla_resource_url,
                     country=user.userprofile.geo_country.code)
     client = Client()
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #36
0
 def test_search_city(self):
     city = CityFactory.create(name=u'αθήνα')
     user = UserFactory.create(userprofile={'geo_city': city})
     url = urlparams(self.mozilla_resource_url,
                     city=user.userprofile.geo_city.name)
     client = Client()
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #37
0
 def test_search_region(self):
     region = RegionFactory.create(name='la lo')
     user = UserFactory.create(userprofile={'geo_region': region})
     url = urlparams(self.mozilla_resource_url,
                     region=user.userprofile.geo_region.name)
     client = Client()
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #38
0
 def test_search_city(self):
     city = CityFactory.create(name=u'αθήνα')
     user = UserFactory.create(userprofile={'geo_city': city})
     url = urlparams(self.mozilla_resource_url,
                     city=user.userprofile.geo_city.name)
     client = Client()
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #39
0
 def test_search_country(self):
     country = CountryFactory.create(code='fr')
     user = UserFactory.create(userprofile={'geo_country': country})
     url = urlparams(self.mozilla_resource_url,
                     country=user.userprofile.geo_country.code)
     client = Client()
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user.userprofile.id)
Пример #40
0
    def test_search_invalid_group(self):
        user = UserFactory.create()
        url = urlparams(reverse("groups:search_groups"), term="invalid")
        with self.login(user) as client:
            response = client.get(url, follow=True, **{"HTTP_X_REQUESTED_WITH": "XMLHttpRequest"})
        eq_(response.status_code, 200)
        eq_(response.get("content-type"), "application/json")

        data = json.loads(response.content)
        eq_(len(data), 0)
Пример #41
0
 def test_list_mozillians_in_location_country_invalid_page(self):
     country = CountryFactory.create()
     UserFactory.create(userprofile={'geo_country': country})
     UserFactory.create(userprofile={'geo_country': country})
     user = UserFactory.create()
     with self.login(user) as client:
         url = reverse('phonebook:list_country', kwargs={'country': country.name})
         url = urlparams(url, page='invalid')
         response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     eq_(response.context['people'].number, 1)
Пример #42
0
    def test_search_invalid_group(self):
        user = UserFactory.create()
        url = urlparams(reverse('groups:search_groups'), term='invalid')
        with self.login(user) as client:
            response = client.get(url, follow=True,
                                  **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})
        eq_(response.status_code, 200)
        eq_(response.get('content-type'), 'application/json')

        data = json.loads(response.content)
        eq_(len(data), 0)
 def test_register_unvouched(self, redeem_invite_mock):
     user = UserFactory.create(vouched=False)
     inviter = UserFactory.create()
     invite = InviteFactory.create(inviter=inviter.userprofile)
     url = urlparams(reverse('phonebook:register'), code=invite.code)
     with self.login(user) as client:
         response = client.get(url, follow=True)
     user = User.objects.get(id=user.id)
     ok_(user.userprofile.is_vouched)
     ok_(redeem_invite_mock.called)
     self.assertTemplateUsed(response, 'phonebook/home.html')
Пример #44
0
    def test_search_invalid_group(self):
        user = UserFactory.create()
        url = urlparams(reverse('groups:search_groups'), term='invalid')
        with self.login(user) as client:
            response = client.get(url, follow=True,
                                  **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})
        eq_(response.status_code, 200)
        eq_(response.get('content-type'), 'application/json')

        data = json.loads(response.content)
        eq_(len(data), 0)
Пример #45
0
 def test_register_unvouched(self, redeem_invite_mock):
     user = UserFactory.create(vouched=False)
     inviter = UserFactory.create()
     invite = InviteFactory.create(inviter=inviter.userprofile)
     url = urlparams(reverse('phonebook:register'), code=invite.code)
     with self.login(user) as client:
         response = client.get(url, follow=True)
     user = User.objects.get(id=user.id)
     ok_(user.userprofile.is_vouched)
     ok_(redeem_invite_mock.called)
     self.assertJinja2TemplateUsed(response, 'phonebook/home.html')
Пример #46
0
 def setUp(self):
     self.resource_url = reverse('api_dispatch_list',
                                 kwargs={
                                     'api_name': 'v1',
                                     'resource_name': 'skills'
                                 })
     self.user = UserFactory.create()
     self.app = APIAppFactory.create(owner=self.user, is_mozilla_app=True)
     self.resource_url = urlparams(self.resource_url,
                                   app_name=self.app.name,
                                   app_key=self.app.key)
Пример #47
0
    def test_search_groups_pending_membership(self):
        client = Client()
        group = GroupFactory.create()
        user_1 = UserFactory.create()
        user_2 = UserFactory.create()
        group.add_member(user_1.userprofile, GroupMembership.PENDING)
        group.add_member(user_2.userprofile, GroupMembership.PENDING)

        url = urlparams(self.mozilla_resource_url, groups=group.name)
        response = client.get(url, follow=True)
        data = json.loads(response.content)
        eq_(len(data['objects']), 0)
Пример #48
0
def edit_profile(request):
    """Edit user profile view."""
    # Don't use request.user
    user = User.objects.get(pk=request.user.id)
    profile = user.userprofile
    sections = {
        "basic_section": ["user_form", "basic_information_form"],
    }

    curr_sect = next((s for s in list(sections.keys()) if s in request.POST), None)

    def get_request_data(form):
        if curr_sect and form in sections[curr_sect]:
            return request.POST
        return None

    ctx = {}
    ctx["user_form"] = forms.UserForm(get_request_data("user_form"), instance=user)
    basic_information_data = get_request_data("basic_information_form")
    ctx["basic_information_form"] = forms.BasicInformationForm(
        basic_information_data, request.FILES or None, instance=profile
    )

    forms_valid = True
    if request.POST:
        if not curr_sect:
            raise Http404
        curr_forms = [ctx[x] for x in sections[curr_sect]]
        forms_valid = all([x.is_valid() for x in curr_forms])
        if forms_valid:
            old_username = request.user.username
            for f in curr_forms:
                f.save()

            next_section = request.GET.get("next")
            next_url = urlparams(reverse("phonebook:profile_edit"), next_section)
            if user.username != old_username:
                msg = _(
                    "You changed your username; "
                    "please note your profile URL has also changed."
                )
                messages.info(request, _(msg))
            return HttpResponseRedirect(next_url)

    ctx.update(
        {
            "profile": request.user.userprofile,
            "vouch_threshold": settings.CAN_VOUCH_THRESHOLD,
            "forms_valid": forms_valid,
        }
    )

    return render(request, "phonebook/edit_profile.html", ctx)
Пример #49
0
    def test_search_groups_pending_membership(self):
        client = Client()
        group = GroupFactory.create()
        user_1 = UserFactory.create()
        user_2 = UserFactory.create()
        group.add_member(user_1.userprofile, GroupMembership.PENDING)
        group.add_member(user_2.userprofile, GroupMembership.PENDING)

        url = urlparams(self.mozilla_resource_url, groups=group.name)
        response = client.get(url, follow=True)
        data = json.loads(response.content)
        eq_(len(data['objects']), 0)
Пример #50
0
    def test_send_invitation_email_no_curator_manager(self):
        inviter, redeemer = UserFactory.create_batch(2)
        invite = InviteFactory.create(inviter=inviter.userprofile,
                                      redeemer=redeemer.userprofile)
        user = UserFactory.create()

        with self.login(user) as client:
            url = urlparams(
                reverse('groups:send_invitation_email', args=[invite.pk]),
                'invitation')
            response = client.get(url, follow=True)
            eq_(response.status_code, 404)
Пример #51
0
 def test_view_profile_mine_as_private(self):
     user = UserFactory.create()
     url = reverse('phonebook:profile_view',
                   kwargs={'username': user.username})
     url = urlparams(url, view_as='private')
     with self.login(user) as client:
         response = client.get(url, follow=True)
     self.assertTemplateUsed(response, 'phonebook/profile.html')
     eq_(response.context['shown_user'], user)
     eq_(response.context['profile'], user.userprofile)
     eq_(response.context['profile']._privacy_level, PRIVATE)
     eq_(response.context['privacy_mode'], 'private')
 def test_view_profile_mine_as_private(self):
     user = UserFactory.create()
     url = reverse("phonebook:profile_view",
                   kwargs={"username": user.username})
     url = urlparams(url, view_as="private")
     with self.login(user) as client:
         response = client.get(url, follow=True)
     self.assertTemplateUsed(response, "phonebook/profile.html")
     eq_(response.context["shown_user"], user)
     eq_(response.context["profile"], user.userprofile)
     eq_(response.context["profile"]._privacy_level, PRIVATE)
     eq_(response.context["privacy_mode"], "private")
Пример #53
0
 def test_view_profile_mine_as_privileged(self):
     user = UserFactory.create()
     url = reverse('phonebook:profile_view',
                   kwargs={'username': user.username})
     url = urlparams(url, view_as='privileged')
     with self.login(user) as client:
         response = client.get(url, follow=True)
     self.assertTemplateUsed(response, 'phonebook/profile.html')
     eq_(response.context['shown_user'], user)
     eq_(response.context['profile'], user.userprofile)
     eq_(response.context['profile']._privacy_level, PRIVILEGED)
     eq_(response.context['privacy_mode'], 'privileged')
Пример #54
0
 def test_search_combined_skills_country(self):
     country = CountryFactory.create(code='fr')
     user_1 = UserFactory.create(userprofile={'geo_country': country})
     UserFactory.create(userprofile={'geo_country': country})
     skill = SkillFactory.create()
     user_1.userprofile.skills.add(skill)
     client = Client()
     url = urlparams(self.mozilla_resource_url,
                     skills=skill.name, country=country.code)
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user_1.userprofile.id)
Пример #55
0
 def test_distinct_results(self):
     user = UserFactory.create()
     group_1 = GroupFactory.create()
     group_2 = GroupFactory.create()
     group_1.add_member(user.userprofile)
     group_2.add_member(user.userprofile)
     client = Client()
     url = urlparams(self.mozilla_resource_url,
                     groups=','.join([group_1.name, group_2.name]))
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(response.status_code, 200)
     eq_(len(data['objects']), 1)
Пример #56
0
 def test_get_detail_community_app(self):
     client = Client()
     url = reverse('api_dispatch_detail',
                   kwargs={
                       'api_name': 'v1',
                       'resource_name': 'users',
                       'pk': self.user.userprofile.id
                   })
     url = urlparams(url,
                     app_name=self.community_app.name,
                     app_key=self.community_app.key)
     response = client.get(url, follow=True)
     eq_(response.status_code, 403)
Пример #57
0
 def test_distinct_results(self):
     user = UserFactory.create()
     group_1 = GroupFactory.create()
     group_2 = GroupFactory.create()
     group_1.add_member(user.userprofile)
     group_2.add_member(user.userprofile)
     client = Client()
     url = urlparams(self.mozilla_resource_url,
                     groups=','.join([group_1.name, group_2.name]))
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(response.status_code, 200)
     eq_(len(data['objects']), 1)
Пример #58
0
    def test_search_skills(self):
        user = UserFactory.create()
        skill_1 = SkillFactory.create()
        SkillFactory.create()
        url = urlparams(reverse('groups:skills-autocomplete'), q=skill_1.name)
        with self.login(user) as client:
            response = client.get(url, follow=True,
                                  **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})
        eq_(response.status_code, 200)
        eq_(response.get('content-type'), 'application/json')

        data = json.loads(response.content)
        eq_(len(data['results']), 1, 'Non autocomplete skills are included in search')
        eq_(data['results'][0]['id'], skill_1.id)
Пример #59
0
    def test_search_existing_group(self):
        user = UserFactory.create()
        group_1 = GroupFactory.create(visible=True)
        GroupFactory.create()
        url = urlparams(reverse('groups:search_groups'), term=group_1.name)
        with self.login(user) as client:
            response = client.get(url, follow=True,
                                  **{'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest'})
        eq_(response.status_code, 200)
        eq_(response.get('content-type'), 'application/json')

        data = json.loads(response.content)
        eq_(len(data), 1, 'Non autocomplete groups are included in search')
        eq_(data[0], group_1.name)