def test_set_membership_language_matches_alias(self): group_1 = LanguageFactory.create(name='foo') group_2 = LanguageFactory.create(name='lo') LanguageAliasFactory.create(alias=group_2, name='bar') user = UserFactory.create() user.userprofile.set_membership(Language, ['foo','bar']) eq_(set(user.userprofile.languages.all()), set([group_1, group_2]))
def test_search_languages(self): user = UserFactory.create(userprofile={"is_vouched": True}) language_1 = LanguageFactory.create(auto_complete=True) LanguageFactory.create() url = urlparams(reverse("groups:search_languages"), term=language_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 languages are included in search") eq_(data[0], language_1.name)
def test_search_languages(self): client = Client() language_1 = LanguageFactory.create() language_2 = LanguageFactory.create() user_1 = UserFactory.create(userprofile={'is_vouched': True}) user_1.userprofile.languages.add(language_1) user_2 = UserFactory.create(userprofile={'is_vouched': True}) user_2.userprofile.languages.add(language_2) url = urlparams(self.mozilla_resource_url, languages=language_1.name) response = client.get(url, follow=True) data = json.loads(response.content) eq_(len(data['objects']), 1) eq_(data['objects'][0]['id'], unicode(user_1.userprofile.id))
def test_search_languages(self): user = UserFactory.create(userprofile={'is_vouched': True}) language_1 = LanguageFactory.create() LanguageFactory.create() url = urlparams(reverse('groups:search_languages'), term=language_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 languages are included in search') eq_(data[0], language_1.name)
def test_search_multiple_languages(self): client = Client() language_1 = LanguageFactory.create() language_2 = LanguageFactory.create() user_1 = UserFactory.create(userprofile={"is_vouched": True}) user_1.userprofile.languages.add(language_1) user_2 = UserFactory.create(userprofile={"is_vouched": True}) user_2.userprofile.languages.add(language_2) url = urlparams(self.mozilla_resource_url, languages=",".join([language_1.name, language_2.name])) response = client.get(url, follow=True) data = json.loads(response.content) eq_(len(data["objects"]), 2) eq_(data["objects"][0]["id"], unicode(user_1.userprofile.id)) eq_(data["objects"][1]["id"], unicode(user_2.userprofile.id))
def setUp(self): voucher = UserFactory.create(userprofile={'is_vouched': True}) self.user = UserFactory.create( userprofile={'is_vouched': True, 'vouched_by': voucher.userprofile}) group = GroupFactory.create() self.user.userprofile.groups.add(group) skill = SkillFactory.create() self.user.userprofile.skills.add(skill) language = LanguageFactory.create() self.user.userprofile.languages.add(language) 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)
def setUp(self): voucher = UserFactory.create(userprofile={'is_vouched': True}) self.user = UserFactory.create(userprofile={ 'is_vouched': True, 'vouched_by': voucher.userprofile }) group = GroupFactory.create() self.user.userprofile.groups.add(group) skill = SkillFactory.create() self.user.userprofile.skills.add(skill) language = LanguageFactory.create() self.user.userprofile.languages.add(language) 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)
def setUp(self): voucher = UserFactory.create(userprofile={'is_vouched': True}) self.user = UserFactory.create( userprofile={'is_vouched': True, 'vouched_by': voucher.userprofile}) group = GroupFactory.create() group.add_member(self.user.userprofile) skill = SkillFactory.create() self.user.userprofile.skills.add(skill) language = LanguageFactory.create() self.user.userprofile.languages.add(language) 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)
def test_search_languages(self): user = UserFactory.create(userprofile={'is_vouched': True}) language_1 = LanguageFactory.create(auto_complete=True) LanguageFactory.create() url = urlparams(reverse('groups:search_languages'), term=language_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 languages are included in search') eq_(data[0], language_1.name)
def test_extract_document(self): group_1 = GroupFactory.create() group_2 = GroupFactory.create() skill_1 = SkillFactory.create() skill_2 = SkillFactory.create() language_1 = LanguageFactory.create() language_2 = LanguageFactory.create() user = UserFactory.create( userprofile={ 'website': 'bestplaceonthenet.com', 'city': 'athens', 'region': 'attika', 'allows_community_sites': False, 'allows_mozilla_sites': False, 'country': 'gr', 'full_name': 'Nikos Koukos', 'bio': 'This is my bio' }) profile = user.userprofile profile.groups.add(group_1) profile.groups.add(group_2) profile.skills.add(skill_1) profile.skills.add(skill_2) profile.languages.add(language_1) profile.languages.add(language_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['website'], profile.website) eq_(result['region'], profile.region) eq_(result['city'], profile.city) eq_(result['allows_community_sites'], profile.allows_community_sites) eq_(result['allows_mozilla_sites'], profile.allows_mozilla_sites) eq_(result['country'], ['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_(result['languages'], [language_1.name, language_2.name])
def test_extract_document(self): group_1 = GroupFactory.create() group_2 = GroupFactory.create() skill_1 = SkillFactory.create() skill_2 = SkillFactory.create() language_1 = LanguageFactory.create() language_2 = LanguageFactory.create() user = UserFactory.create(userprofile={'website': 'bestplaceonthenet.com', 'city': 'athens', 'region': 'attika', 'allows_community_sites': False, 'allows_mozilla_sites': False, 'country': 'gr', 'full_name': 'Nikos Koukos', 'bio': 'This is my bio'}) profile = user.userprofile profile.groups.add(group_1) profile.groups.add(group_2) profile.skills.add(skill_1) profile.skills.add(skill_2) profile.languages.add(language_1) profile.languages.add(language_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['website'], profile.website) eq_(result['region'], profile.region) eq_(result['city'], profile.city) eq_(result['allows_community_sites'], profile.allows_community_sites) eq_(result['allows_mozilla_sites'], profile.allows_mozilla_sites) eq_(result['country'], ['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_(result['languages'], [language_1.name, language_2.name])
def test_list_languages(self): unvouched_user = UserFactory.create() user = UserFactory.create(userprofile={'is_vouched': True}) language = LanguageFactory.create() language.members.add(unvouched_user.userprofile) language.members.add(user.userprofile) client = Client() response = client.get(self.resource_url, follow=True) data = json.loads(response.content) eq_(data['meta']['total_count'], 1) eq_(data['objects'][0]['name'], language.name) eq_(data['objects'][0]['number_of_members'], 1, 'List includes unvouched users') eq_(int(data['objects'][0]['id']), language.id)
def setUp(self): voucher = UserFactory.create(userprofile={"is_vouched": True}) self.user = UserFactory.create(userprofile={"is_vouched": True, "vouched_by": voucher.userprofile}) group = GroupFactory.create() self.user.userprofile.groups.add(group) skill = SkillFactory.create() self.user.userprofile.skills.add(skill) language = LanguageFactory.create() self.user.userprofile.languages.add(language) 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 )