def test_extract_document(self): user = UserFactory.create(userprofile={'allows_community_sites': False, 'allows_mozilla_sites': False, '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 = UserProfileMappingType.extract_document(profile.id) ok_(isinstance(result, dict)) eq_(result['id'], profile.id) eq_(result['is_vouched'], profile.is_vouched) eq_(result['region'], 'attika') eq_(result['city'], 'athens') 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_search_no_public_with_unvouched(self, PrivacyAwareSMock): result = UserProfileMappingType.search("foo", include_non_vouched=True) ok_(isinstance(result, Mock)) PrivacyAwareSMock.assert_any_call(UserProfileMappingType) PrivacyAwareSMock().indexes.assert_any_call("index") ok_(call().indexes().boost().query().order_by().filter(is_vouched=True) not in PrivacyAwareSMock.mock_calls) ok_(call().privacy_level(PUBLIC) not in PrivacyAwareSMock.mock_calls)
def test_search_no_public_only_vouched(self, PrivacyAwareSMock): result = UserProfileMappingType.search('foo') ok_(isinstance(result, Mock)) PrivacyAwareSMock.assert_any_call(UserProfileMappingType) PrivacyAwareSMock().indexes.assert_any_call('index') (PrivacyAwareSMock().indexes().boost() .query().order_by().filter.assert_any_call(is_vouched=True)) ok_(call().privacy_level(PUBLIC) not in PrivacyAwareSMock.mock_calls)
def test_search_no_public_with_unvouched(self, PrivacyAwareSMock): result = UserProfileMappingType.search('foo', include_non_vouched=True) ok_(isinstance(result, Mock)) PrivacyAwareSMock.assert_any_call(UserProfileMappingType) PrivacyAwareSMock().indexes.assert_any_call('index') ok_(call().indexes().boost().query().order_by().filter( is_vouched=True) not in PrivacyAwareSMock.mock_calls) ok_(call().privacy_level(PUBLIC) not in PrivacyAwareSMock.mock_calls)
def test_search_public_only_vouched(self, PrivacyAwareSMock): result = UserProfileMappingType.search('foo', public=True) ok_(isinstance(result, Mock)) PrivacyAwareSMock.assert_any_call(UserProfileMappingType) PrivacyAwareSMock().privacy_level.assert_any_call(PUBLIC) (PrivacyAwareSMock().privacy_level().indexes.assert_any_call( 'public_index')) (PrivacyAwareSMock().privacy_level().indexes().boost().query(). order_by().filter.assert_any_call(is_vouched=True))
def test_search_public_only_vouched(self, PrivacyAwareSMock): result = UserProfileMappingType.search("foo", public=True) ok_(isinstance(result, Mock)) PrivacyAwareSMock.assert_any_call(UserProfileMappingType) PrivacyAwareSMock().privacy_level.assert_any_call(PUBLIC) (PrivacyAwareSMock().privacy_level().indexes.assert_any_call("public_index")) ( PrivacyAwareSMock() .privacy_level() .indexes() .boost() .query() .order_by() .filter.assert_any_call(is_vouched=True) )
def test_extract_document(self): user = UserFactory.create( userprofile={ "allows_community_sites": False, "allows_mozilla_sites": False, "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 = UserProfileMappingType.extract_document(profile.id) ok_(isinstance(result, dict)) eq_(result["id"], profile.id) eq_(result["is_vouched"], profile.is_vouched) eq_(result["region"], "attika") eq_(result["city"], "athens") 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_get_index(self): ok_(UserProfileMappingType.get_index(public_index=False), 'bar')
def test_get_index_public(self): ok_(UserProfileMappingType.get_index(public_index=True), 'foo')
def test_get_mapping(self): ok_(UserProfileMappingType.get_mapping())