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={'geo_country': country,
                      'geo_region': region})
     UserFactory.create(
         userprofile={'geo_country': country,
                      'geo_region': region2})
     UserFactory.create()
     UserFactory.create(vouched=False)
     UserFactory.create(vouched=False, userprofile={'geo_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)
示例#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={
         'geo_country': country,
         'geo_region': region
     })
     UserFactory.create(userprofile={
         'geo_country': country,
         'geo_region': region2
     })
     UserFactory.create()
     UserFactory.create(vouched=False)
     UserFactory.create(vouched=False,
                        userprofile={'geo_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)
示例#3
0
    def test_duplicate_results(self):
        """Test that in case mapbox API returns a region already stored in DB
        with diferrent mapbox_id, we gracefully update all entries and foreign keys
        with the latest mapbox data."""

        region = RegionFactory.create(mapbox_id='42')
        user = UserFactory.create(userprofile={'geo_region': region})
        result = {
            'province': {
                'name': region.name,
                'id': '24'
            }
        }

        result_to_region(result, region.country)
        lookup_args = {
            'name': region.name,
            'country': region.country
        }

        region_qs = Region.objects.filter(**lookup_args)
        ok_(region_qs.count(), 1)
        eq_(region_qs[0].mapbox_id, '24')
        ok_(not Region.objects.filter(mapbox_id='42').exists())

        userprofile = UserProfile.objects.get(pk=user.userprofile.id)
        eq_(userprofile.geo_region.name, region.name)
        eq_(userprofile.geo_region.mapbox_id, '24')
示例#4
0
    def test_location_city_region_optout(self, mock_reverse_geocode):
        country = CountryFactory.create(mapbox_id='country1', name='Petoria')
        region = RegionFactory.create(country=country, mapbox_id='region1', name='Ontario')
        city = CityFactory.create(region=region, mapbox_id='city1', name='Toronto')
        mock_reverse_geocode.return_value = (country, region, city)
        user = UserFactory.create(email='*****@*****.**')
        data = {'full_name': user.userprofile.full_name,
                'email': user.email,
                'username': user.username,
                'lat': 40.005814,
                'lng': -3.42071,
                'externalaccount_set-MAX_NUM_FORMS': '1000',
                'externalaccount_set-INITIAL_FORMS': '0',
                'externalaccount_set-TOTAL_FORMS': '0',
                'language_set-MAX_NUM_FORMS': '1000',
                'language_set-INITIAL_FORMS': '0',
                'language_set-TOTAL_FORMS': '0',
            }
        data.update(_get_privacy_fields(MOZILLIANS))

        form = ProfileForm(data=data)
        eq_(form.is_valid(), True)
        eq_(form.instance.geo_country, country)
        eq_(form.instance.geo_region, None)
        eq_(form.instance.geo_city, None)
示例#5
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)
示例#6
0
 def test_transform_region(self):
     region = RegionFactory.create(name='LA')
     user = UserFactory.create(userprofile={'geo_region': region})
     data = UserProfileDetailedSerializer(user.userprofile).data
     region = {'value': 'LA',
               'privacy': 'Mozillians'}
     eq_(data['region'], region)
示例#7
0
 def test_transform_region(self):
     region = RegionFactory.create(name='LA')
     user = UserFactory.create(userprofile={'geo_region': region})
     data = UserProfileDetailedSerializer(user.userprofile).data
     region = {'value': 'LA',
               'privacy': 'Mozillians'}
     eq_(data['region'], region)
示例#8
0
 def setUp(self):
     self.user = UserFactory.create(email='*****@*****.**',
                                    userprofile={
                                        'geo_country': None,
                                        'geo_region': None,
                                        'geo_city': None
                                    })
     self.data = {
         'full_name': self.user.userprofile.full_name,
         'email': self.user.email,
         'username': self.user.username,
         'lat': 40.005814,
         'lng': -3.42071,
         'externalaccount_set-MAX_NUM_FORMS': '1000',
         'externalaccount_set-INITIAL_FORMS': '0',
         'externalaccount_set-TOTAL_FORMS': '0',
         'language_set-MAX_NUM_FORMS': '1000',
         'language_set-INITIAL_FORMS': '0',
         'language_set-TOTAL_FORMS': '0',
         'location_section': ''
     }
     self.country = CountryFactory.create(mapbox_id='country1',
                                          name='Petoria')
     self.region = RegionFactory.create(country=self.country,
                                        mapbox_id='reg1',
                                        name='Ontario')
     self.city = CityFactory.create(region=self.region,
                                    mapbox_id='city1',
                                    name='Toronto')
示例#9
0
 def test_transform_region(self):
     region = RegionFactory.create(name='LA')
     user = UserFactory.create(userprofile={'geo_region': region})
     context = {'request': self.factory.get('/')}
     serializer = UserProfileDetailedSerializer(user.userprofile, context=context)
     region = {'value': 'LA',
               'privacy': 'Mozillians'}
     eq_(serializer.data['region'], region)
示例#10
0
 def test_transform_region(self):
     region = RegionFactory.create(name='LA')
     user = UserFactory.create(userprofile={'geo_region': region})
     context = {'request': self.factory.get('/')}
     serializer = UserProfileDetailedSerializer(user.userprofile,
                                                context=context)
     region = {'value': 'LA', 'privacy': 'Mozillians'}
     eq_(serializer.data['region'], region)
示例#11
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)
示例#12
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)
示例#13
0
 def test_update_name(self):
     # If region name has changed, we update our database
     country = CountryFactory.create()
     region = RegionFactory.create(country=country)
     new_name = 'New %s' % region.name
     result = {
         'province': {
             'name': new_name,
             'id': region.mapbox_id,
         }
     }
     result_to_region(result, country)
     region = Region.objects.get(pk=region.pk)
     eq_(new_name, region.name)
示例#14
0
 def test_update_name(self):
     # If region name has changed, we update our database
     country = CountryFactory.create()
     region = RegionFactory.create(country=country)
     new_name = 'New %s' % region.name
     result = {
         'province': {
             'name': new_name,
             'id': region.mapbox_id,
         }
     }
     result_to_region(result, country)
     region = Region.objects.get(pk=region.pk)
     eq_(new_name, region.name)
示例#15
0
 def test_with_city(self):
     country = CountryFactory.create()
     region = RegionFactory.create(country=country)
     result = {
         'city': {
             'name': 'Carrboro',
             'id': '1234',
             'lat': 0.0,
             'lon': 0.0,
         }
     }
     city = result_to_city(result, country, region)
     eq_('Carrboro', city.name)
     eq_('1234', city.mapbox_id)
     eq_(region, city.region)
     eq_(country, city.country)
示例#16
0
 def test_with_city(self):
     country = CountryFactory.create()
     region = RegionFactory.create(country=country)
     result = {
         'city': {
             'name': 'Carrboro',
             'id': '1234',
             'lat': 0.0,
             'lon': 0.0,
         }
     }
     city = result_to_city(result, country, region)
     eq_('Carrboro', city.name)
     eq_('1234', city.mapbox_id)
     eq_(region, city.region)
     eq_(country, city.country)
示例#17
0
    def test_extract_document(self):
        country = CountryFactory.create(name='Greece', code='gr')
        region = RegionFactory.create(name='attika', country=country)
        city = CityFactory.create(name='athens',
                                  region=region,
                                  country=country)
        user = UserFactory.create(
            userprofile={
                'geo_city': city,
                'geo_region': region,
                'allows_community_sites': False,
                'allows_mozilla_sites': False,
                'geo_country': country,
                'full_name': 'Nikos Koukos',
                'bio': 'This is my bio'
            })
        profile = user.userprofile
        group_1 = GroupFactory.create()
        group_2 = GroupFactory.create()
        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        LanguageFactory.create(code='fr', userprofile=profile)
        LanguageFactory.create(code='en', userprofile=profile)
        group_1.add_member(profile)
        group_2.add_member(profile)
        profile.skills.add(skill_1)
        profile.skills.add(skill_2)

        result = UserProfile.extract_document(user.userprofile.id)
        ok_(isinstance(result, dict))
        eq_(result['id'], profile.id)
        eq_(result['is_vouched'], profile.is_vouched)
        eq_(result['region'], region.name)
        eq_(result['city'], city.name)
        eq_(result['allows_community_sites'], profile.allows_community_sites)
        eq_(result['allows_mozilla_sites'], profile.allows_mozilla_sites)
        eq_(set(result['country']), set(['gr', 'Greece']))
        eq_(result['fullname'], profile.full_name.lower())
        eq_(result['name'], profile.full_name.lower())
        eq_(result['bio'], profile.bio)
        eq_(result['has_photo'], False)
        eq_(result['groups'], [group_1.name, group_2.name])
        eq_(result['skills'], [skill_1.name, skill_2.name])
        eq_(set(result['languages']),
            set([u'en', u'fr', u'english', u'french', u'français']))
示例#18
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={
         'geo_country': country,
         'geo_region': region,
         'geo_city': city
     })
     UserFactory.create(userprofile={
         'geo_country': country,
         'geo_region': region,
         'geo_city': city2
     })
     UserFactory.create()
     UserFactory.create(vouched=False)
     UserFactory.create(vouched=False,
                        userprofile={'geo_country': country2})
     UserFactory.create(userprofile={'geo_country': country})
     UserFactory.create(userprofile={
         'geo_country': country,
         'geo_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)
示例#19
0
 def setUp(self):
     self.user = UserFactory.create(email='*****@*****.**')
     self.data = {
         'full_name': self.user.userprofile.full_name,
         'email': self.user.email,
         'username': self.user.username,
         'lat': 40.005814,
         'lng': -3.42071,
         'externalaccount_set-MAX_NUM_FORMS': '1000',
         'externalaccount_set-INITIAL_FORMS': '0',
         'externalaccount_set-TOTAL_FORMS': '0',
         'language_set-MAX_NUM_FORMS': '1000',
         'language_set-INITIAL_FORMS': '0',
         'language_set-TOTAL_FORMS': '0',
     }
     self.country = CountryFactory.create(mapbox_id='country1', name='Petoria')
     self.region = RegionFactory.create(country=self.country, mapbox_id='reg1', name='Ontario')
     self.city = CityFactory.create(region=self.region, mapbox_id='city1', name='Toronto')
示例#20
0
    def test_extract_document(self):
        country = CountryFactory.create(name="Greece", code="gr")
        region = RegionFactory.create(name="attika", country=country)
        city = CityFactory.create(name="athens", region=region, country=country)
        user = UserFactory.create(
            userprofile={
                "geo_city": city,
                "geo_region": region,
                "allows_community_sites": False,
                "allows_mozilla_sites": False,
                "geo_country": country,
                "full_name": "Nikos Koukos",
                "bio": "This is my bio",
            }
        )
        profile = user.userprofile
        group_1 = GroupFactory.create()
        group_2 = GroupFactory.create()
        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        LanguageFactory.create(code="fr", userprofile=profile)
        LanguageFactory.create(code="en", userprofile=profile)
        group_1.add_member(profile)
        group_2.add_member(profile)
        profile.skills.add(skill_1)
        profile.skills.add(skill_2)

        result = UserProfile.extract_document(user.userprofile.id)
        ok_(isinstance(result, dict))
        eq_(result["id"], profile.id)
        eq_(result["is_vouched"], profile.is_vouched)
        eq_(result["region"], region.name)
        eq_(result["city"], city.name)
        eq_(result["allows_community_sites"], profile.allows_community_sites)
        eq_(result["allows_mozilla_sites"], profile.allows_mozilla_sites)
        eq_(result["country"], country.name)
        eq_(result["fullname"], profile.full_name.lower())
        eq_(result["name"], profile.full_name.lower())
        eq_(result["bio"], profile.bio)
        eq_(result["has_photo"], False)
        eq_(result["groups"], [group_1.name, group_2.name])
        eq_(result["skills"], [skill_1.name, skill_2.name])
        eq_(set(result["languages"]), set([u"en", u"fr", u"english", u"french", u"français"]))
示例#21
0
 def setUp(self):
     self.user = UserFactory.create(
         email="*****@*****.**", userprofile={"geo_country": None, "geo_region": None, "geo_city": None}
     )
     self.data = {
         "full_name": self.user.userprofile.full_name,
         "email": self.user.email,
         "username": self.user.username,
         "lat": 40.005814,
         "lng": -3.42071,
         "externalaccount_set-MAX_NUM_FORMS": "1000",
         "externalaccount_set-INITIAL_FORMS": "0",
         "externalaccount_set-TOTAL_FORMS": "0",
         "language_set-MAX_NUM_FORMS": "1000",
         "language_set-INITIAL_FORMS": "0",
         "language_set-TOTAL_FORMS": "0",
     }
     self.country = CountryFactory.create(mapbox_id="country1", name="Petoria")
     self.region = RegionFactory.create(country=self.country, mapbox_id="reg1", name="Ontario")
     self.city = CityFactory.create(region=self.region, mapbox_id="city1", name="Toronto")
示例#22
0
    def test_duplicate_results(self):
        """Test that in case mapbox API returns a region already stored in DB
        with diferrent mapbox_id, we gracefully update all entries and foreign keys
        with the latest mapbox data."""

        region = RegionFactory.create(mapbox_id='42')
        user = UserFactory.create(userprofile={'geo_region': region})
        result = {'province': {'name': region.name, 'id': '24'}}

        result_to_region(result, region.country)
        lookup_args = {'name': region.name, 'country': region.country}

        region_qs = Region.objects.filter(**lookup_args)
        ok_(region_qs.count(), 1)
        eq_(region_qs[0].mapbox_id, '24')
        ok_(not Region.objects.filter(mapbox_id='42').exists())

        userprofile = UserProfile.objects.get(pk=user.userprofile.id)
        eq_(userprofile.geo_region.name, region.name)
        eq_(userprofile.geo_region.mapbox_id, '24')
示例#23
0
    def test_extract_document(self):
        country = CountryFactory.create(name='Greece', code='gr')
        region = RegionFactory.create(name='attika', country=country)
        city = CityFactory.create(name='athens', region=region, country=country)
        user = UserFactory.create(userprofile={'geo_city': city,
                                               'geo_region': region,
                                               'allows_community_sites': False,
                                               'allows_mozilla_sites': False,
                                               'geo_country': country,
                                               'full_name': 'Nikos Koukos',
                                               'bio': 'This is my bio'})
        profile = user.userprofile
        group_1 = GroupFactory.create()
        group_2 = GroupFactory.create()
        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        LanguageFactory.create(code='fr', userprofile=profile)
        LanguageFactory.create(code='en', userprofile=profile)
        group_1.add_member(profile)
        group_2.add_member(profile)
        profile.skills.add(skill_1)
        profile.skills.add(skill_2)

        result = UserProfile.extract_document(user.userprofile.id)
        ok_(isinstance(result, dict))
        eq_(result['id'], profile.id)
        eq_(result['is_vouched'], profile.is_vouched)
        eq_(result['region'], region.name)
        eq_(result['city'], city.name)
        eq_(result['allows_community_sites'], profile.allows_community_sites)
        eq_(result['allows_mozilla_sites'], profile.allows_mozilla_sites)
        eq_(set(result['country']), set(['gr', 'Greece']))
        eq_(result['fullname'], profile.full_name.lower())
        eq_(result['name'], profile.full_name.lower())
        eq_(result['bio'], profile.bio)
        eq_(result['has_photo'], False)
        eq_(result['groups'], [group_1.name, group_2.name])
        eq_(result['skills'], [skill_1.name, skill_2.name])
        eq_(set(result['languages']),
            set([u'en', u'fr', u'english', u'french', u'français']))
 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={'geo_country': country,
                      'geo_region': region,
                      'geo_city': city})
     UserFactory.create(
         userprofile={'geo_country': country,
                      'geo_region': region,
                      'geo_city': city2})
     UserFactory.create()
     UserFactory.create(vouched=False)
     UserFactory.create(vouched=False, userprofile={'geo_country': country2})
     UserFactory.create(userprofile={'geo_country': country})
     UserFactory.create(userprofile={'geo_country': country, 'geo_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)