예제 #1
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)
예제 #2
0
    def test_location_region_required_if_city(self, mock_reverse_geocode):
        mock_reverse_geocode.return_value = (self.country, self.region, self.city)
        self.data.update({"savecity": True})
        self.data.update(_get_privacy_fields(MOZILLIANS))

        form = ProfileForm(data=self.data)
        ok_(not form.is_valid())
        ok_("saveregion" in form.errors)
예제 #3
0
    def test_location_city_region_optout(self, mock_reverse_geocode):
        mock_reverse_geocode.return_value = (self.country, self.region, self.city)
        self.data.update(_get_privacy_fields(MOZILLIANS))

        form = ProfileForm(data=self.data)
        eq_(form.is_valid(), True)
        eq_(form.instance.geo_country, self.country)
        eq_(form.instance.geo_region, None)
        eq_(form.instance.geo_city, None)
예제 #4
0
    def test_location_region_required_if_city(self, mock_reverse_geocode):
        mock_reverse_geocode.return_value = (self.country, self.region,
                                             self.city)
        self.data.update({'savecity': True})
        self.data.update(_get_privacy_fields(MOZILLIANS))

        form = ProfileForm(data=self.data)
        ok_(not form.is_valid())
        ok_('saveregion' in form.errors)
예제 #5
0
    def test_location_region_required_if_city(self, mock_reverse_geocode):
        mock_reverse_geocode.return_value = (self.country, self.region, self.city)
        self.data.update({'savecity': True})
        self.data.update(_get_privacy_fields(MOZILLIANS))

        form = ProfileForm(data=self.data)
        with self.assertRaises(ValidationError):
            ok_(not form.is_valid())
            form.clean()
예제 #6
0
    def test_location_city_region_optout(self, mock_reverse_geocode):
        mock_reverse_geocode.return_value = (self.country, self.region,
                                             self.city)
        self.data.update(_get_privacy_fields(MOZILLIANS))

        form = ProfileForm(data=self.data)
        eq_(form.is_valid(), True)
        eq_(form.instance.geo_country, self.country)
        eq_(form.instance.geo_region, None)
        eq_(form.instance.geo_city, None)
예제 #7
0
    def test_location_api_not_called_when_latlang_unchanged(self, mock_reverse_geocode):
        mock_reverse_geocode.return_value = (self.country, self.region, self.city)
        self.data["lng"] = self.user.userprofile.lng
        self.data["lat"] = self.user.userprofile.lat
        self.data.update(_get_privacy_fields(MOZILLIANS))
        initial = {"lat": self.user.userprofile.lat, "lng": self.user.userprofile.lng}

        form = ProfileForm(data=self.data, initial=initial)
        ok_(form.is_valid())
        ok_(not mock_reverse_geocode.called)
예제 #8
0
 def test_lat_lng_does_not_point_to_country(self):
     # If form includes lat/lng, must point to some country; fails if not
     user = UserFactory.create(email='*****@*****.**')
     data = model_to_dict(user.userprofile)
     # invalid data
     data['lat'] = data['lng'] = 0.0
     form = ProfileForm(data=data, instance=user.userprofile)
     with patch('mozillians.users.models.UserProfile.reverse_geocode'):
         # Pretend that geocoding doesn't come up with a country
         user.userprofile.geo_country = None
         ok_(not form.is_valid())
예제 #9
0
 def test_lat_lng_does_not_point_to_country(self):
     # If form includes lat/lng, must point to some country; fails if not
     user = UserFactory.create(email='*****@*****.**')
     data = model_to_dict(user.userprofile)
     # invalid data
     data['lat'] = data['lng'] = 0.0
     form = ProfileForm(data=data, instance=user.userprofile)
     with patch('mozillians.users.models.UserProfile.reverse_geocode'):
         # Pretend that geocoding doesn't come up with a country
         user.userprofile.geo_country = None
         ok_(not form.is_valid())
예제 #10
0
    def test_story_link(self):
        user = UserFactory.create()
        data = model_to_dict(user.userprofile)
        data['story_link'] = 'http://somelink.com'
        form = ProfileForm(data=data, instance=user.userprofile)
        ok_(form.is_valid(), msg=dict(form.errors))

        eq_(form.cleaned_data['story_link'], u'http://somelink.com/')

        data['story_link'] = 'Foobar'
        form = ProfileForm(data=data, instance=user.userprofile)
        ok_(not form.is_valid())
예제 #11
0
    def test_location_api_called_when_latlng_changed(self, mock_reverse_geocode):
        mock_reverse_geocode.return_value = (self.country, self.region, self.city)
        self.data['lat'] = 40
        self.data['lng'] = 20
        self.data.update(_get_privacy_fields(MOZILLIANS))
        initial = {
            'lat': self.user.userprofile.lat,
            'lng': self.user.userprofile.lng
        }

        form = ProfileForm(data=self.data, initial=initial)
        ok_(form.is_valid())
        ok_(mock_reverse_geocode.called)
예제 #12
0
 def test_lat_lng_does_point_to_country(self):
     # If form includes lat/lng, must point to some country; succeeds if so
     user = UserFactory.create(email='*****@*****.**')
     data = model_to_dict(user.userprofile)
     # Try again, with valid data
     data['lng'] = 35.918596
     data['lat'] = -79.083799
     country = CountryFactory.create()
     form = ProfileForm(data=data, instance=user.userprofile)
     with patch('mozillians.users.models.UserProfile.reverse_geocode'):
         # Pretend that geocoding does come up with a country
         user.userprofile.geo_country = country
         ok_(form.is_valid())
예제 #13
0
 def test_lat_lng_does_point_to_country(self):
     # If form includes lat/lng, must point to some country; succeeds if so
     user = UserFactory.create(email='*****@*****.**')
     data = model_to_dict(user.userprofile)
     # Try again, with valid data
     data['lng'] = 35.918596
     data['lat'] = -79.083799
     country = CountryFactory.create()
     form = ProfileForm(data=data, instance=user.userprofile)
     with patch('mozillians.users.models.UserProfile.reverse_geocode'):
         # Pretend that geocoding does come up with a country
         user.userprofile.geo_country = country
         ok_(form.is_valid())
예제 #14
0
    def test_location_api_not_called_when_latlang_unchanged(
            self, mock_reverse_geocode):
        mock_reverse_geocode.return_value = (self.country, self.region,
                                             self.city)
        self.data['lng'] = self.user.userprofile.lng
        self.data['lat'] = self.user.userprofile.lat
        self.data.update(_get_privacy_fields(MOZILLIANS))
        initial = {
            'lat': self.user.userprofile.lat,
            'lng': self.user.userprofile.lng
        }

        form = ProfileForm(data=self.data, initial=initial)
        ok_(form.is_valid())
        ok_(not mock_reverse_geocode.called)
예제 #15
0
    def test_location_data_required(self):
        user = UserFactory.create(email='*****@*****.**')
        data = {'full_name': user.userprofile.full_name,
                'email': user.email,
                'username': user.username,
                '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(), False)
        ok_(form.errors.get('lat'))
        ok_(form.errors.get('lng'))
예제 #16
0
    def test_location_data_required(self):
        user = UserFactory.create(email='*****@*****.**')
        data = {
            'full_name': user.userprofile.full_name,
            'email': user.email,
            'username': user.username,
            '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(), False)
        ok_(form.errors.get('lat'))
        ok_(form.errors.get('lng'))
예제 #17
0
    def test_location_data_required(self):
        user = UserFactory.create(email="*****@*****.**")
        data = {
            "full_name": user.userprofile.full_name,
            "email": user.email,
            "username": user.username,
            "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(), False)
        ok_(form.errors.get("lat"))
        ok_(form.errors.get("lng"))
예제 #18
0
    def test_story_link(self):
        user = UserFactory.create()
        data = model_to_dict(user.userprofile)
        data['story_link'] = 'http://somelink.com'
        form = ProfileForm(data=data, instance=user.userprofile)
        ok_(form.is_valid(), msg=dict(form.errors))

        eq_(form.cleaned_data['story_link'], u'http://somelink.com/')

        data['story_link'] = 'Foobar'
        form = ProfileForm(data=data, instance=user.userprofile)
        ok_(not form.is_valid())
예제 #19
0
    def test_skill_name_validation(self):
        # skill names can contain A-Za-z0-9 +.:-
        user = UserFactory.create(email='*****@*****.**')
        data = model_to_dict(user.userprofile)

        # valid names
        data['skills'] = 'lO ngN,am3+.:-'
        form = ProfileForm(data=data, instance=user.userprofile)
        ok_(form.is_valid(), msg=dict(form.errors))

        # Save the form
        form.save()
        # We should end up with two skills - note the names are lower-cased
        ok_(Skill.objects.filter(name='lo ngn').exists())
        ok_(Skill.objects.filter(name='am3+.:-').exists())

        # an invalid name - ';' is not a valid character
        data['skills'] = 'lOngName+.:-;'
        form = ProfileForm(data=data, instance=user.userprofile)
        ok_(not form.is_valid())
        ok_('skills' in form.errors)
예제 #20
0
    def test_skill_name_validation(self):
        # skill names can contain A-Za-z0-9 +.:-
        user = UserFactory.create(email='*****@*****.**')
        data = model_to_dict(user.userprofile)

        # valid names
        data['skills'] = 'lO ngN,am3+.:-'
        form = ProfileForm(data=data, instance=user.userprofile)
        ok_(form.is_valid(), msg=dict(form.errors))

        # Save the form
        form.save()
        # We should end up with two skills - note the names are lower-cased
        ok_(Skill.objects.filter(name='lo ngn').exists())
        ok_(Skill.objects.filter(name='am3+.:-').exists())

        # an invalid name - ';' is not a valid character
        data['skills'] = 'lOngName+.:-;'
        form = ProfileForm(data=data, instance=user.userprofile)
        ok_(not form.is_valid())
        ok_('skills' in form.errors)