Ejemplo n.º 1
0
 def test_list_mozillians_in_location_region_vouched(self):
     country = CountryFactory.create()
     country2 = CountryFactory.create()
     region = RegionFactory.create(country=country)
     region2 = RegionFactory.create(country=country)
     user_listed = UserFactory.create(userprofile={
         'country': country,
         'region': region
     })
     UserFactory.create(userprofile={'country': country, 'region': region2})
     UserFactory.create()
     UserFactory.create(vouched=False)
     UserFactory.create(vouched=False, userprofile={'country': country2})
     user = UserFactory.create()
     with self.login(user) as client:
         url = reverse('phonebook:list_region',
                       kwargs={
                           'country': country.name,
                           'region': region.name
                       })
         response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     self.assertTemplateUsed(response, 'phonebook/location_list.html')
     eq_(response.context['country_name'], country.name)
     eq_(response.context['city_name'], None)
     eq_(response.context['region_name'], region.name)
     eq_(response.context['people'].paginator.count, 1)
     eq_(response.context['people'].object_list[0], user_listed.userprofile)
Ejemplo n.º 2
0
 def test_list_mozillians_in_location_region_vouched(self):
     country = CountryFactory.create()
     country2 = CountryFactory.create()
     region = RegionFactory.create(country=country)
     region2 = RegionFactory.create(country=country)
     user_listed = UserFactory.create(
         userprofile={'country': country,
                      'region': region})
     UserFactory.create(
         userprofile={'country': country,
                      'region': region2})
     UserFactory.create()
     UserFactory.create(vouched=False)
     UserFactory.create(vouched=False, userprofile={'country': country2})
     user = UserFactory.create()
     with self.login(user) as client:
         url = reverse(
             'phonebook:list_region',
             kwargs={'country': country.name, 'region': region.name})
         response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     self.assertTemplateUsed(response, 'phonebook/location_list.html')
     eq_(response.context['country_name'], country.name)
     eq_(response.context['city_name'], None)
     eq_(response.context['region_name'], region.name)
     eq_(response.context['people'].paginator.count, 1)
     eq_(response.context['people'].object_list[0], user_listed.userprofile)
Ejemplo n.º 3
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)
Ejemplo n.º 4
0
 def test_get_country(self):
     context = {"request": self.factory.get("/")}
     country = CountryFactory.create(name="LA", code2="IO")
     user = UserFactory.create(userprofile={"country": country})
     user.userprofile._groups = Group.objects.none()
     serializer = UserProfileDetailedSerializer(user.userprofile,
                                                context=context)
     country = {"code": "IO", "value": "LA", "privacy": "Mozillians"}
     eq_(serializer.data["country"], country)
Ejemplo n.º 5
0
 def test_get_country(self):
     context = {'request': self.factory.get('/')}
     country = CountryFactory.create(name='LA', code2='IO')
     user = UserFactory.create(userprofile={'country': country})
     user.userprofile._groups = Group.objects.none()
     serializer = UserProfileDetailedSerializer(user.userprofile,
                                                context=context)
     country = {'code': 'IO', 'value': 'LA', 'privacy': 'Mozillians'}
     eq_(serializer.data['country'], country)
Ejemplo n.º 6
0
 def test_get_country(self):
     context = {'request': self.factory.get('/')}
     country = CountryFactory.create(name='LA', code2='IO')
     user = UserFactory.create(userprofile={'country': country})
     user.userprofile._groups = Group.objects.none()
     serializer = UserProfileDetailedSerializer(user.userprofile, context=context)
     country = {'code': 'IO',
                'value': 'LA',
                'privacy': 'Mozillians'}
     eq_(serializer.data['country'], country)
Ejemplo n.º 7
0
 def test_search_country(self):
     country = CountryFactory.create(code2='fr')
     user = UserFactory.create(userprofile={'country': country})
     url = urlparams(self.mozilla_resource_url,
                     country=user.userprofile.country.code2)
     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)
Ejemplo n.º 8
0
 def test_list_mozillians_in_location_country_invalid_page(self):
     country = CountryFactory.create()
     UserFactory.create(userprofile={'country': country})
     UserFactory.create(userprofile={'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)
Ejemplo n.º 9
0
 def test_list_mozillians_in_location_region_n_city_vouched(self):
     """
     Test that only vouched users with the correct country, city
     and region show up in the list view.
     """
     country = CountryFactory.create()
     country2 = CountryFactory.create()
     region = RegionFactory.create(country=country)
     city = CityFactory(country=country, region=region)
     city2 = CityFactory(country=country)
     user_listed = UserFactory.create(userprofile={
         'country': country,
         'region': region,
         'city': city
     })
     UserFactory.create(userprofile={
         'country': country,
         'region': region,
         'city': city2
     })
     UserFactory.create()
     UserFactory.create(vouched=False)
     UserFactory.create(vouched=False, userprofile={'country': country2})
     UserFactory.create(userprofile={'country': country})
     UserFactory.create(userprofile={'country': country, 'region': region})
     user = UserFactory.create()
     with self.login(user) as client:
         url = reverse('phonebook:list_region_city',
                       kwargs={
                           'country': country.name,
                           'region': region.name,
                           'city': city.name
                       })
         response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     self.assertTemplateUsed(response, 'phonebook/location_list.html')
     eq_(response.context['country_name'], country.name)
     eq_(response.context['city_name'], city.name)
     eq_(response.context['region_name'], region.name)
     eq_(response.context['people'].paginator.count, 1)
     eq_(response.context['people'].object_list[0], user_listed.userprofile)
Ejemplo n.º 10
0
 def test_list_mozillians_in_location_country_invalid_page(self):
     country = CountryFactory.create()
     UserFactory.create(userprofile={'country': country})
     UserFactory.create(userprofile={'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)
Ejemplo n.º 11
0
 def test_search_combined_skills_country(self):
     country = CountryFactory.create(code2='fr')
     user_1 = UserFactory.create(userprofile={'country': country})
     UserFactory.create(userprofile={'country': country})
     skill = SkillFactory.create()
     user_1.userprofile.skills.add(skill)
     client = Client()
     url = urlparams(self.mozilla_resource_url,
                     skills=skill.name,
                     country=country.code2)
     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)
Ejemplo n.º 12
0
 def test_list_mozillians_in_location_country_second_page(self):
     country = CountryFactory.create()
     UserFactory.create(userprofile={'country': country})
     user_listed_2 = (UserFactory.create(userprofile={'country': country}))
     user = UserFactory.create()
     with self.login(user) as client:
         url = reverse('phonebook:list_country', kwargs={'country': country.name})
         url = urlparams(url, page=2)
         response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     eq_(response.context['people'].paginator.count, 2)
     eq_(response.context['people'].paginator.num_pages, 2)
     eq_(response.context['people'].number, 2)
     eq_(response.context['people'].object_list[0],
         user_listed_2.userprofile)
Ejemplo n.º 13
0
 def test_list_mozillians_in_location_region_n_city_vouched(self):
     """
     Test that only vouched users with the correct country, city
     and region show up in the list view.
     """
     country = CountryFactory.create()
     country2 = CountryFactory.create()
     region = RegionFactory.create(country=country)
     city = CityFactory(country=country, region=region)
     city2 = CityFactory(country=country)
     user_listed = UserFactory.create(
         userprofile={'country': country,
                      'region': region,
                      'city': city})
     UserFactory.create(
         userprofile={'country': country,
                      'region': region,
                      'city': city2})
     UserFactory.create()
     UserFactory.create(vouched=False)
     UserFactory.create(vouched=False, userprofile={'country': country2})
     UserFactory.create(userprofile={'country': country})
     UserFactory.create(userprofile={'country': country, 'region': region})
     user = UserFactory.create()
     with self.login(user) as client:
         url = reverse('phonebook:list_region_city',
                       kwargs={'country': country.name, 'region': region.name,
                               'city': city.name})
         response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     self.assertTemplateUsed(response, 'phonebook/location_list.html')
     eq_(response.context['country_name'], country.name)
     eq_(response.context['city_name'], city.name)
     eq_(response.context['region_name'], region.name)
     eq_(response.context['people'].paginator.count, 1)
     eq_(response.context['people'].object_list[0], user_listed.userprofile)
Ejemplo n.º 14
0
 def test_list_mozillians_in_location_country_second_page(self):
     country = CountryFactory.create()
     UserFactory.create(userprofile={'country': country})
     user_listed_2 = (UserFactory.create(userprofile={'country': country}))
     user = UserFactory.create()
     with self.login(user) as client:
         url = reverse('phonebook:list_country',
                       kwargs={'country': country.name})
         url = urlparams(url, page=2)
         response = client.get(url, follow=True)
     eq_(response.status_code, 200)
     eq_(response.context['people'].paginator.count, 2)
     eq_(response.context['people'].paginator.num_pages, 2)
     eq_(response.context['people'].number, 2)
     eq_(response.context['people'].object_list[0],
         user_listed_2.userprofile)