def test_transform_tshirt(self): user = UserFactory.create(userprofile={'tshirt': 9}) data = UserProfileDetailedSerializer(user.userprofile).data tshirt = {'value': 9, 'english': 'Straight-cut Large', 'privacy': 'Privileged'} eq_(data['tshirt'], tshirt)
def test_transform_city(self): city = CityFactory.create(name='LA') user = UserFactory.create(userprofile={'geo_city': city}) data = UserProfileDetailedSerializer(user.userprofile).data city = {'value': 'LA', 'privacy': 'Mozillians'} eq_(data['city'], city)
def test_transform_bio(self): user = UserFactory.create(userprofile={'bio': '*foo*'}) data = UserProfileDetailedSerializer(user.userprofile).data bio = {'value': '*foo*', 'html': '<p><em>foo</em></p>', 'privacy': 'Mozillians'} eq_(data['bio'], bio)
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)
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)
def test_transform_city(self): city = CityFactory.create(name='LA') user = UserFactory.create(userprofile={'geo_city': city}) context = {'request': self.factory.get('/')} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) city = {'value': 'LA', 'privacy': 'Mozillians'} eq_(serializer.data['city'], city)
def test_get_country(self): country = CountryFactory.create(name='LA', code='IO') user = UserFactory.create(userprofile={'geo_country': country}) data = UserProfileDetailedSerializer(user.userprofile).data country = {'code': 'IO', 'value': 'LA', 'privacy': 'Mozillians'} eq_(data['country'], country)
def test_get_country(self): context = {'request': self.factory.get('/')} country = CountryFactory.create(name='LA', code='IO') user = UserFactory.create(userprofile={'geo_country': country}) serializer = UserProfileDetailedSerializer(user.userprofile, context=context) country = {'code': 'IO', 'value': 'LA', 'privacy': 'Mozillians'} eq_(serializer.data['country'], country)
def test_transform_tshirt(self): user = UserFactory.create(userprofile={'tshirt': 9}) user.userprofile._groups = Group.objects.none() context = {'request': self.factory.get('/')} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) tshirt = {'value': 9, 'english': 'Straight-cut Large', 'privacy': 'Privileged'} eq_(serializer.data['tshirt'], tshirt)
def test_transform_bio(self): user = UserFactory.create(userprofile={'bio': '*foo*'}) user.userprofile._groups = Group.objects.none() context = {'request': self.factory.get('/')} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) bio = {'value': '*foo*', 'html': '<p><em>foo</em></p>', 'privacy': 'Mozillians'} eq_(serializer.data['bio'], bio)
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)
def test_transform_city(self): city = CityFactory.create(name="LA") user = UserFactory.create(userprofile={"city": city}) user.userprofile._groups = Group.objects.none() context = {"request": self.factory.get("/")} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) city = {"value": "LA", "privacy": "Mozillians"} eq_(serializer.data["city"], city)
def test_transform_region(self): region = RegionFactory.create(name="LA") user = UserFactory.create(userprofile={"region": region}) user.userprofile._groups = Group.objects.none() context = {"request": self.factory.get("/")} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) region = {"value": "LA", "privacy": "Mozillians"} eq_(serializer.data["region"], region)
def test_transform_timezone(self): user = UserFactory.create(userprofile={'timezone': 'Europe/Athens'}) timezone_mock = Mock() timezone_mock.return_value = 99 user.userprofile.timezone_offset = timezone_mock data = UserProfileDetailedSerializer(user.userprofile).data timezone = {'value': 'Europe/Athens', 'utc_offset': 99, 'privacy': 'Mozillians'} eq_(data['timezone'], timezone)
def test_transform_bio(self): user = UserFactory.create(userprofile={"bio": "*foo*"}) user.userprofile._groups = Group.objects.none() context = {"request": self.factory.get("/")} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) bio = { "value": "*foo*", "html": "<p><em>foo</em></p>", "privacy": "Mozillians" } eq_(serializer.data["bio"], bio)
def test_transform_timezone(self): user = UserFactory.create(userprofile={'timezone': 'Europe/Athens'}) user.userprofile._groups = Group.objects.none() timezone_mock = Mock() timezone_mock.return_value = 99 user.userprofile.timezone_offset = timezone_mock context = {'request': self.factory.get('/')} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) timezone = {'value': 'Europe/Athens', 'utc_offset': 99, 'privacy': 'Mozillians'} eq_(serializer.data['timezone'], timezone)
def test_transform_tshirt(self): user = UserFactory.create(userprofile={"tshirt": 9}) user.userprofile._groups = Group.objects.none() context = {"request": self.factory.get("/")} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) tshirt = { "value": 9, "english": "Straight-cut Large", "privacy": "Private" } eq_(serializer.data["tshirt"], tshirt)
def test_alternate_emails_idp(self): user = UserFactory.create() IdpProfile.objects.create(profile=user.userprofile, auth0_user_id='ad|[email protected]', email='*****@*****.**', privacy=1) user.userprofile._groups = Group.objects.none() context = {'request': self.factory.get('/')} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) eq_(len(serializer.data['alternate_emails']), 1) eq_(serializer.data['alternate_emails'][0]['email'], '*****@*****.**') eq_(serializer.data['alternate_emails'][0]['privacy'], 'Private')
def test_alternate_emails_legacy(self): user = UserFactory.create() ExternalAccount.objects.create(type=ExternalAccount.TYPE_EMAIL, user=user.userprofile, identifier='*****@*****.**', privacy=3) user.userprofile._groups = Group.objects.none() context = {'request': self.factory.get('/')} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) eq_(len(serializer.data['alternate_emails']), 1) eq_(serializer.data['alternate_emails'][0]['email'], '*****@*****.**') eq_(serializer.data['alternate_emails'][0]['privacy'], 'Mozillians')
def test_alternate_emails_legacy(self): user = UserFactory.create() ExternalAccount.objects.create( type=ExternalAccount.TYPE_EMAIL, user=user.userprofile, identifier="*****@*****.**", privacy=3, ) user.userprofile._groups = Group.objects.none() context = {"request": self.factory.get("/")} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) eq_(len(serializer.data["alternate_emails"]), 1) eq_(serializer.data["alternate_emails"][0]["email"], "*****@*****.**") eq_(serializer.data["alternate_emails"][0]["privacy"], "Mozillians")
def test_alternate_emails_idp(self): user = UserFactory.create() IdpProfile.objects.create( profile=user.userprofile, auth0_user_id="ad|[email protected]", email="*****@*****.**", privacy=1, ) user.userprofile._groups = Group.objects.none() context = {"request": self.factory.get("/")} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) eq_(len(serializer.data["alternate_emails"]), 1) eq_(serializer.data["alternate_emails"][0]["email"], "*****@*****.**") eq_(serializer.data["alternate_emails"][0]["privacy"], "Private")
def test_transform_timezone(self): user = UserFactory.create(userprofile={"timezone": "Europe/Athens"}) user.userprofile._groups = Group.objects.none() timezone_mock = Mock() timezone_mock.return_value = 99 user.userprofile.timezone_offset = timezone_mock context = {"request": self.factory.get("/")} serializer = UserProfileDetailedSerializer(user.userprofile, context=context) timezone = { "value": "Europe/Athens", "utc_offset": 99, "privacy": "Mozillians" } eq_(serializer.data["timezone"], timezone)
def test_transform_photo(self): def _get_url(dimensions): return dimensions user = UserFactory.create(userprofile={'timezone': 'Europe/Athens'}) get_photo_url_mock = Mock() get_photo_url_mock.side_effect = _get_url user.userprofile.get_photo_url = get_photo_url_mock data = UserProfileDetailedSerializer(user.userprofile).data photo = {'value': '300x300', '150x150': '150x150', '300x300': '300x300', '500x500': '500x500', 'privacy': 'Mozillians'} eq_(data['photo'], photo)
def test_transform_photo(self): def _get_url(dimensions): return dimensions user = UserFactory.create(userprofile={'timezone': 'Europe/Athens'}) user.userprofile._groups = Group.objects.none() context = {'request': self.factory.get('/')} get_photo_url_mock = Mock() get_photo_url_mock.side_effect = _get_url user.userprofile.get_photo_url = get_photo_url_mock serializer = UserProfileDetailedSerializer(user.userprofile, context=context) photo = {'value': '300x300', '150x150': '150x150', '300x300': '300x300', '500x500': '500x500', 'privacy': 'Mozillians'} eq_(serializer.data['photo'], photo)
def test_transform_photo(self): def _get_url(dimensions): return dimensions user = UserFactory.create(userprofile={"timezone": "Europe/Athens"}) user.userprofile._groups = Group.objects.none() context = {"request": self.factory.get("/")} get_photo_url_mock = Mock() get_photo_url_mock.side_effect = _get_url user.userprofile.get_photo_url = get_photo_url_mock serializer = UserProfileDetailedSerializer(user.userprofile, context=context) photo = { "value": "300x300", "150x150": "150x150", "300x300": "300x300", "500x500": "500x500", "privacy": "Mozillians", } eq_(serializer.data["photo"], photo)