def test_templatetag_profile_scores(member, rf, nobody, settings): user_profile = profile.get(member.__class__)(member) request = rf.get("") request.user = nobody rendered = render_as_template( "{% load profile_tags %}{% profile_score request profile %}", dict(profile=user_profile, request=request)) assert "Total score:" in rendered score = str(int(round(member.score))) assert score in rendered assert (quote_plus("My current score at %s is %s" % (settings.POOTLE_TITLE, score)) not in rendered) request.user = member rendered = render_as_template( "{% load profile_tags %}{% profile_score request profile %}", dict(profile=user_profile, request=request)) assert "Total score:" in rendered assert score in rendered assert (quote_plus("My current score at %s is %s" % (settings.POOTLE_TITLE, score)) in rendered) nobody_profile = profile.get(nobody.__class__)(nobody) rendered = render_as_template( "{% load profile_tags %}{% profile_score request profile %}", dict(profile=nobody_profile, request=request)) assert "0" in rendered assert (quote_plus("My current score at") not in rendered)
def test_templatetag_profile_user(member, rf, nobody, system, request_users): request_user = request_users["user"] member.email = "*****@*****.**" user_profile = profile.get(member.__class__)(member) request = rf.get("") request.user = request_user rendered = render_as_template( "{% load profile_tags %}{% profile_user request profile %}", dict(profile=user_profile, request=request)) assert member.display_name in rendered if request_user.is_superuser: assert member.email in rendered else: assert member.email not in rendered if request_user == member: assert "Show others who you are" in rendered assert "js-user-profile-edit" in rendered else: assert "Show others who you are" not in rendered assert "js-user-profile-edit" not in rendered member.bio = "my life story" member.website = "http://foobar.baz" rendered = render_as_template( "{% load profile_tags %}{% profile_user request profile %}", dict(profile=user_profile, request=request)) assert "my life story" in rendered if request_user == member: assert "Show others who you are" not in rendered assert "js-user-profile-edit" in rendered assert "You can set or change your avatar" in rendered else: assert "Show others who you are" not in rendered assert "js-user-profile-edit" not in rendered assert "You can set or change your avatar" not in rendered nobody_profile = profile.get(nobody.__class__)(nobody) rendered = render_as_template( "{% load profile_tags %}{% profile_user request profile %}", dict(profile=nobody_profile, request=request)) assert "Show others who you are" not in rendered assert "js-user-profile-edit" not in rendered assert "Some translations are provided by anonymous volunteers" in rendered assert "You can set or change your avatar" not in rendered system_profile = profile.get(system.__class__)(system) rendered = render_as_template( "{% load profile_tags %}{% profile_user request profile %}", dict(profile=system_profile, request=request)) assert "Show others who you are" not in rendered assert "js-user-profile-edit" not in rendered assert "Some translations are imported from external files. " in rendered assert "You can set or change your avatar" not in rendered
def test_templatetag_profile_teams(rf, admin, member, language0, request_users): request_user = request_users["user"] lang_team = language_team.get() user_profile = profile.get(member.__class__)(member) request = rf.get("") request.user = request_user rendered = render_as_template( "{% load profile_tags %}{% profile_teams request profile %}", dict(profile=user_profile, request=request)) assert (("%s is not a member of any language teams" % member.display_name) in rendered) lang_team(language0).add_member(member, "member") user_profile = profile.get(member.__class__)(member) rendered = render_as_template( "{% load profile_tags %}{% profile_teams request profile %}", dict(profile=user_profile, request=request)) assert language0.name in rendered lang_link = reverse("pootle-language-browse", kwargs=dict(language_code=language0.code)) assert lang_link in rendered assert ("/%s/" % lang_link) not in rendered assert "Admin" not in rendered assert "Site administrator" not in rendered lang_team(language0).add_member(member, "admin") user_profile = profile.get(member.__class__)(member) rendered = render_as_template( "{% load profile_tags %}{% profile_teams request profile %}", dict(profile=user_profile, request=request)) assert language0.name in rendered assert lang_link in rendered if request_user.is_anonymous: assert "Admin" not in rendered else: assert "Admin" in rendered admin_profile = profile.get(admin.__class__)(admin) rendered = render_as_template( "{% load profile_tags %}{% profile_teams request profile %}", dict(profile=admin_profile, request=request)) if request_user.is_anonymous: assert "Site administrator" not in rendered else: assert "Site administrator" in rendered
def test_templatetag_profile_ranking(member, rf, nobody): user_profile = profile.get(member.__class__)(member) request = rf.get("") request.user = nobody top_lang = user_profile.scores.top_language rendered = render_as_template( "{% load profile_tags %}{% profile_ranking request profile %}", dict(profile=user_profile, request=request)) assert (("#%s contributor in %s in the last 30 days" % (top_lang[0], top_lang[1].name)) in rendered) assert (quote_plus("I am #%s contributor in %s in the last 30 days" % (top_lang[0], top_lang[1].name)) not in rendered) request.user = member rendered = render_as_template( "{% load profile_tags %}{% profile_ranking request profile %}", dict(profile=user_profile, request=request)) assert (quote_plus("I am #%s contributor in %s in the last 30 days" % (top_lang[0], top_lang[1].name)) in rendered) nobody_profile = profile.get(nobody.__class__)(nobody) rendered = render_as_template( "{% load profile_tags %}{% profile_ranking request profile %}", dict(profile=nobody_profile, request=request)) assert "contributor in" not in rendered
def test_templatetag_profile_activity(member, rf, nobody, system, request_users): request_user = request_users["user"] user_profile = profile.get(member.__class__)(member) request = rf.get("") request.user = request_user rendered = render_as_template( "{% load profile_tags %}{% profile_activity profile %}", dict(profile=user_profile)) last_event = member.last_event() assert last_event.message in rendered assert "user-last-activity" in rendered nobody_profile = profile.get(nobody.__class__)(nobody) rendered = render_as_template( "{% load profile_tags %}{% profile_activity profile %}", dict(profile=nobody_profile)) assert "user-last-activity" not in rendered system_profile = profile.get(system.__class__)(system) rendered = render_as_template( "{% load profile_tags %}{% profile_activity profile %}", dict(profile=system_profile)) assert "user-last-activity" not in rendered
def test_profile_user(member): user_profile = profile.get(member.__class__)(member) assert isinstance(user_profile, UserProfile) assert user_profile.user == member user_membership = user_profile.membership assert isinstance(user_membership, UserMembership) assert user_membership.user == member user_scores = user_profile.scores assert isinstance(user_scores, UserScores) assert user_scores.context == member assert user_profile.display_name == member.display_name avatar = render_as_template( "{% load common_tags %}{% avatar username email_hash 20 %}", context=dict( username=member.username, email_hash=member.email_hash)) assert user_profile.avatar == avatar user_log = user_profile.log assert isinstance(user_log, UserLog) all_events = list(user_profile.get_events()) assert all( (ev.user == member or ev.value.user == member) for ev in all_events) # default is to get events from last 30 days thirty_days_ago = timezone.now() - timedelta(days=30) assert all( (ev.timestamp > thirty_days_ago) for ev in all_events) events = list(user_profile.get_events(n=2)) assert all( (ev.user == member or ev.value.user == member) for ev in events) assert len(events) == 2 sorted_events = sorted(ComparableLogEvent(ev) for ev in all_events) # last 2 events in the sorted events matches "events" assert sorted_events[-1].timestamp == events[0].timestamp assert sorted_events[-2].timestamp == events[1].timestamp latest_events = list(user_profile.get_events(start=sorted_events[1].timestamp)) event = latest_events[0] no_microseconds = (event.timestamp == event.timestamp.replace(microsecond=0)) if not no_microseconds: assert len(latest_events) == len(all_events) - 1 assert all( (ev.timestamp >= sorted_events[1].timestamp) for ev in latest_events)
def test_templatetag_profile_social(member): user_profile = profile.get(member.__class__)(member) rendered = render_as_template( "{% load profile_tags %}{% profile_social profile %}", dict(profile=user_profile)) assert not rendered.strip() member.website = "http://foobar.baz" rendered = render_as_template( "{% load profile_tags %}{% profile_social profile %}", dict(profile=user_profile)) assert "My Website" in rendered assert "http://foobar.baz" in rendered member.twitter = "foomember" rendered = render_as_template( "{% load profile_tags %}{% profile_social profile %}", dict(profile=user_profile)) assert "@foomember" in rendered assert "https://twitter.com/foomember" in rendered member.linkedin = "https://linked.in/in/foomember" rendered = render_as_template( "{% load profile_tags %}{% profile_social profile %}", dict(profile=user_profile)) assert "My LinkedIn Profile" in rendered assert member.linkedin in rendered
def get_context_data(self, **kwargs): context = super(UserDetailView, self).get_context_data(**kwargs) context["profile"] = profile.get(self.object.__class__)(self.object) return context