示例#1
0
 def test_set_membership_skill_matches_alias(self):
     group_1 = SkillFactory.create(name='foo')
     group_2 = SkillFactory.create(name='lo')
     SkillAliasFactory.create(alias=group_2, name='bar')
     user = UserFactory.create()
     user.userprofile.set_membership(Skill, ['foo', 'bar'])
     eq_(set(user.userprofile.skills.all()), set([group_1, group_2]))
示例#2
0
    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 = UserProfile.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']))
示例#3
0
 def test_set_membership_skill_matches_alias(self):
     group_1 = SkillFactory.create(name="foo")
     group_2 = SkillFactory.create(name="lo")
     SkillAliasFactory.create(alias=group_2, name="bar")
     user = UserFactory.create()
     user.userprofile.set_membership(Skill, ["foo", "bar"])
     eq_(set(user.userprofile.skills.all()), set([group_1, group_2]))
示例#4
0
    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']))
示例#5
0
 def test_set_membership_skill_matches_alias(self):
     group_1 = SkillFactory.create(name='foo')
     group_2 = SkillFactory.create(name='lo')
     SkillAliasFactory.create(alias=group_2, name='bar')
     user = UserFactory.create()
     user.userprofile.set_membership(Skill, ['foo', 'bar'])
     eq_(set(user.userprofile.skills.all()), set([group_1, group_2]))
示例#6
0
    def test_search_skills(self):
        user = UserFactory.create()
        skill_1 = SkillFactory.create()
        SkillFactory.create()
        url = urlparams(reverse("groups:search_skills"), term=skill_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 skills are included in search")
        eq_(data[0], skill_1.name)
示例#7
0
    def test_index_skills(self):
        user = UserFactory.create()
        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        SkillFactory.create()
        skill_1.members.add(user.userprofile)
        skill_2.members.add(user.userprofile)

        with self.login(user) as client:
            response = client.get(self.url, follow=True)
        eq_(response.status_code, 200)
        self.assertTemplateUsed(response, "groups/index_skills.html")
        eq_(set(response.context["groups"].paginator.object_list), set([skill_1, skill_2]))
示例#8
0
    def test_search_skills(self):
        user = UserFactory.create()
        skill_1 = SkillFactory.create()
        SkillFactory.create()
        url = urlparams(reverse('groups:skills-autocomplete'), q=skill_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_(data['results'][0]['id'], skill_1.id)
示例#9
0
    def test_search_skills(self):
        client = Client()
        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        user_1 = UserFactory.create(userprofile={'is_vouched': True})
        user_1.userprofile.skills.add(skill_1)
        user_2 = UserFactory.create(userprofile={'is_vouched': True})
        user_2.userprofile.skills.add(skill_2)

        url = urlparams(self.mozilla_resource_url, skills=skill_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))
示例#10
0
    def test_search_skills(self):
        user = UserFactory.create(userprofile={'is_vouched': True})
        skill_1 = SkillFactory.create(auto_complete=True)
        SkillFactory.create()
        url = urlparams(reverse('groups:search_skills'), term=skill_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 skills are included in search')
        eq_(data[0], skill_1.name)
示例#11
0
    def test_index_skills(self):
        user = UserFactory.create(userprofile={'is_vouched': True})
        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        SkillFactory.create()
        skill_1.members.add(user.userprofile)
        skill_2.members.add(user.userprofile)

        with self.login(user) as client:
            response = client.get(self.url, follow=True)
        eq_(response.status_code, 200)
        self.assertTemplateUsed(response, 'groups/index_skills.html')
        eq_(set(response.context['groups'].paginator.object_list),
            set([skill_1, skill_2]))
示例#12
0
    def test_search_skills(self):
        user = UserFactory.create()
        skill_1 = SkillFactory.create()
        SkillFactory.create()
        url = urlparams(reverse('groups:skills-autocomplete'), q=skill_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['results']), 1, 'Non autocomplete skills are included in search')
        eq_(data['results'][0]['id'], skill_1.id)
示例#13
0
    def test_search_skills(self):
        client = Client()
        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        user_1 = UserFactory.create(userprofile={'is_vouched': True})
        user_1.userprofile.skills.add(skill_1)
        user_2 = UserFactory.create(userprofile={'is_vouched': True})
        user_2.userprofile.skills.add(skill_2)

        url = urlparams(self.mozilla_resource_url, skills=skill_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))
示例#14
0
    def setUp(self):
        voucher = UserFactory.create()
        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)
        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)
示例#15
0
    def test_remove_empty_groups(self):
        user = UserFactory.create()
        group_1 = GroupFactory.create()
        GroupFactory.create()
        skill_1 = SkillFactory.create()
        SkillFactory.create()

        group_1.add_member(user.userprofile)
        skill_1.members.add(user.userprofile)

        tasks.remove_empty_groups()

        eq_(Group.objects.all().count(), 1)
        ok_(Group.objects.filter(id=group_1.id).exists())
        eq_(Skill.objects.all().count(), 1)
        ok_(Skill.objects.filter(id=skill_1.id).exists())
示例#16
0
    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)
示例#17
0
    def test_skill_member_count(self):
        skill = SkillFactory.create(name='foo')
        users = UserFactory.create_batch(3)
        for u in users:
            skill.add_member(u.userprofile)

        eq_(Skill.objects.get(name='foo').member_count, 3)
示例#18
0
    def test_search_skills(self):
        user = UserFactory.create(userprofile={'is_vouched': True})
        skill_1 = SkillFactory.create(auto_complete=True)
        SkillFactory.create()
        url = urlparams(reverse('groups:search_skills'), term=skill_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 skills are included in search')
        eq_(data[0], skill_1.name)
示例#19
0
 def setUp(self):
     self.skill = SkillFactory.create()
     # We must request the full path, with language, or the
     # LanguageMiddleware will convert the request to GET.
     self.url = reverse('groups:toggle_skill_subscription', prefix='/en-US/',
                        kwargs={'url': self.skill.url})
     self.user = UserFactory.create(userprofile={'is_vouched': True})
示例#20
0
    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)
示例#21
0
    def test_skill_member_count(self):
        skill = SkillFactory.create(name='foo')
        users = UserFactory.create_batch(3)
        for u in users:
            skill.add_member(u.userprofile)

        eq_(Skill.objects.get(name='foo').member_count, 3)
示例#22
0
 def test_add_member(self):
     skill = SkillFactory.create()
     user = UserFactory.create()
     ok_(user.userprofile not in skill.members.all())
     skill.add_member(userprofile=user.userprofile)
     ok_(user.userprofile in skill.members.all())
     ok_(skill.has_member(userprofile=user.userprofile))
示例#23
0
 def test_remove_member(self):
     skill = SkillFactory.create()
     user = UserFactory.create()
     skill.members.add(user.userprofile)
     skill.remove_member(userprofile=user.userprofile)
     ok_(not skill.has_member(userprofile=user.userprofile))
     ok_(user.userprofile not in skill.members.all())
示例#24
0
    def setUp(self):
        voucher = UserFactory.create()
        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)
        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)
示例#25
0
    def test_remove_empty_groups(self):
        user = UserFactory.create()
        group_1 = GroupFactory.create()
        GroupFactory.create()
        skill_1 = SkillFactory.create()
        SkillFactory.create()

        group_1.add_member(user.userprofile)
        skill_1.members.add(user.userprofile)

        tasks.remove_empty_groups()

        eq_(Group.objects.all().count(), 1)
        ok_(Group.objects.filter(id=group_1.id).exists())
        eq_(Skill.objects.all().count(), 1)
        ok_(Skill.objects.filter(id=skill_1.id).exists())
示例#26
0
 def setUp(self):
     self.skill = SkillFactory.create()
     # We must request the full path, with language, or the
     # LanguageMiddleware will convert the request to GET.
     self.url = reverse('groups:toggle_skill_subscription', prefix='/en-US/',
                        kwargs={'url': self.skill.url})
     self.user = UserFactory.create()
示例#27
0
 def setUp(self):
     self.skill = SkillFactory.create()
     # We must request the full path, with language, or the
     # LanguageMiddleware will convert the request to GET.
     with override_script_prefix('/en-US/'):
         self.url = reverse('groups:toggle_skill_subscription',
                            kwargs={'url': self.skill.url})
     self.user = UserFactory.create()
示例#28
0
    def test_show_leave_group_button_value_skill(self):
        skill = SkillFactory.create()
        user = UserFactory.create(userprofile={"is_vouched": True})
        url = reverse("groups:show_skill", kwargs={"url": skill.url})

        with self.login(user) as client:
            response = client.get(url, follow=True)
        eq_(response.status_code, 200)
        eq_(response.context["hide_leave_group_button"], False)
示例#29
0
    def test_show_leave_group_button_value_skill(self):
        skill = SkillFactory.create()
        user = UserFactory.create(userprofile={'is_vouched': True})
        url = reverse('groups:show_skill', kwargs={'url': skill.url})

        with self.login(user) as client:
            response = client.get(url, follow=True)
        eq_(response.status_code, 200)
        eq_(response.context['hide_leave_group_button'], False)
示例#30
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"]))
示例#31
0
    def test_show_leave_button_value_skill(self):
        skill = SkillFactory.create()
        user = UserFactory.create(userprofile={'is_vouched': True})
        skill.members.add(user.userprofile)
        url = reverse('groups:show_skill', kwargs={'url': skill.url})

        with self.login(user) as client:
            response = client.get(url, follow=True)
        eq_(response.status_code, 200)
        eq_(response.context['show_leave_button'], True)
示例#32
0
    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])
示例#33
0
    def test_show_leave_button_value_skill(self):
        skill = SkillFactory.create()
        user = UserFactory.create()
        skill.members.add(user.userprofile)
        url = reverse('groups:show_skill', kwargs={'url': skill.url})

        with self.login(user) as client:
            response = client.get(url, follow=True)
        eq_(response.status_code, 200)
        eq_(response.context['show_leave_button'], True)
        ok_(not response.context['is_pending'])
示例#34
0
    def test_show_leave_button_value_skill(self):
        skill = SkillFactory.create()
        user = UserFactory.create()
        skill.members.add(user.userprofile)
        url = reverse("groups:show_skill", kwargs={"url": skill.url})

        with self.login(user) as client:
            response = client.get(url, follow=True)
        eq_(response.status_code, 200)
        eq_(response.context["show_leave_button"], True)
        ok_(not response.context["is_pending"])
示例#35
0
 def test_search_combined_skills_country(self):
     country = CountryFactory.create(code="fr")
     user_1 = UserFactory.create(userprofile={"geo_country": country})
     UserFactory.create(userprofile={"geo_country": country})
     skill = SkillFactory.create()
     user_1.userprofile.skills.add(skill)
     client = Client()
     url = urlparams(self.mozilla_resource_url, skills=skill.name, country=country.code)
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data["objects"]), 1)
     eq_(data["objects"][0]["id"], user_1.userprofile.id)
示例#36
0
    def test_show_common_skills(self):
        """Show most common skills first."""
        user_1 = UserFactory.create()
        user_2 = UserFactory.create()
        user_3 = UserFactory.create()
        user_4 = UserFactory.create()

        group = GroupFactory.create()
        group.add_member(user_1.userprofile)
        group.add_member(user_2.userprofile)
        group.add_member(user_3.userprofile)
        group.add_member(user_4.userprofile)

        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        skill_3 = SkillFactory.create()
        skill_4 = SkillFactory.create()
        skill_3.members.add(user_1.userprofile)
        skill_3.members.add(user_2.userprofile)
        skill_3.members.add(user_3.userprofile)
        skill_3.members.add(user_4.userprofile)
        skill_2.members.add(user_2.userprofile)
        skill_2.members.add(user_3.userprofile)
        skill_2.members.add(user_4.userprofile)
        skill_4.members.add(user_3.userprofile)
        skill_4.members.add(user_4.userprofile)
        skill_1.members.add(user_1.userprofile)
        users = UserFactory.create_batch(5)
        for user in users:
            skill_4.members.add(user.userprofile)

        url = reverse('groups:show_group', kwargs={'url': group.url})
        with self.login(user_1) as client:
            response = client.get(url, follow=True)
        eq_(response.status_code, 200)
        skills = response.context['skills']
        eq_(skills[0], skill_3)
        eq_(skills[1], skill_2)
        eq_(skills[2], skill_4)
        ok_(skill_1 not in skills)
示例#37
0
    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])
示例#38
0
    def test_show_common_skills(self):
        """Show most common skills first."""
        user_1 = UserFactory.create()
        user_2 = UserFactory.create()
        user_3 = UserFactory.create()
        user_4 = UserFactory.create()

        group = GroupFactory.create()
        group.add_member(user_1.userprofile)
        group.add_member(user_2.userprofile)
        group.add_member(user_3.userprofile)
        group.add_member(user_4.userprofile)

        skill_1 = SkillFactory.create()
        skill_2 = SkillFactory.create()
        skill_3 = SkillFactory.create()
        skill_4 = SkillFactory.create()
        skill_3.members.add(user_1.userprofile)
        skill_3.members.add(user_2.userprofile)
        skill_3.members.add(user_3.userprofile)
        skill_3.members.add(user_4.userprofile)
        skill_2.members.add(user_2.userprofile)
        skill_2.members.add(user_3.userprofile)
        skill_2.members.add(user_4.userprofile)
        skill_4.members.add(user_3.userprofile)
        skill_4.members.add(user_4.userprofile)
        skill_1.members.add(user_1.userprofile)
        users = UserFactory.create_batch(5)
        for user in users:
            skill_4.members.add(user.userprofile)

        url = reverse('groups:show_group', kwargs={'url': group.url})
        with self.login(user_1) as client:
            response = client.get(url, follow=True)
        eq_(response.status_code, 200)
        skills = response.context['skills']
        eq_(skills[0], skill_3)
        eq_(skills[1], skill_2)
        eq_(skills[2], skill_4)
        ok_(skill_1 not in skills)
示例#39
0
 def test_search_combined_skills_country(self):
     country = 'fr'
     user_1 = UserFactory.create(userprofile={'country': country})
     UserFactory.create(userprofile={'country': country})
     skill = SkillFactory.create()
     user_1.userprofile.skills.add(skill)
     client = Client()
     url = urlparams(self.mozilla_resource_url,
                     skills=skill.name, country=country)
     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))
示例#40
0
 def test_search_combined_skills_country(self):
     country = CountryFactory.create(code='fr')
     user_1 = UserFactory.create(userprofile={'geo_country': country})
     UserFactory.create(userprofile={'geo_country': country})
     skill = SkillFactory.create()
     user_1.userprofile.skills.add(skill)
     client = Client()
     url = urlparams(self.mozilla_resource_url,
                     skills=skill.name, country=country.code)
     response = client.get(url, follow=True)
     data = json.loads(response.content)
     eq_(len(data['objects']), 1)
     eq_(data['objects'][0]['id'], user_1.userprofile.id)
示例#41
0
    def test_list_skills(self):
        unvouched_user = UserFactory.create(vouched=False)
        user = UserFactory.create()
        skill = SkillFactory.create()
        skill.members.add(unvouched_user.userprofile)
        skill.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"], skill.name)
        eq_(data["objects"][0]["number_of_members"], 1, "List includes unvouched users")
        eq_(int(data["objects"][0]["id"]), skill.id)
示例#42
0
    def test_list_skills(self):
        unvouched_user = UserFactory.create(vouched=False)
        user = UserFactory.create()
        skill = SkillFactory.create()
        skill.members.add(unvouched_user.userprofile)
        skill.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'], skill.name)
        eq_(data['objects'][0]['number_of_members'], 1,
            'List includes unvouched users')
        eq_(int(data['objects'][0]['id']), skill.id)
示例#43
0
    def test_list_skills(self):
        unvouched_user = UserFactory.create()
        user = UserFactory.create(userprofile={'is_vouched': True})
        skill = SkillFactory.create()
        skill.members.add(unvouched_user.userprofile)
        skill.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'], skill.name)
        eq_(data['objects'][0]['number_of_members'], 1,
            'List includes unvouched users')
        eq_(int(data['objects'][0]['id']), skill.id)
示例#44
0
    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
        )
示例#45
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
        )
示例#46
0
 def test_has_member(self):
     skill = SkillFactory.create()
     user = UserFactory.create()
     ok_(not skill.has_member(userprofile=user.userprofile))
     skill.members.add(user.userprofile)
     ok_(skill.has_member(userprofile=user.userprofile))
示例#47
0
 def test_skill_get_absolute_url(self):
     skill = SkillFactory.create(url='bar')
     ok_(skill.get_absolute_url())