示例#1
0
def test_view_language_team_new_member(client, language0, request_users,
                                       member, member2):
    user = request_users["user"]
    team = language_team.get(language0.__class__)(language0)
    admin_url = reverse('pootle-language-admin-team-new-members',
                        kwargs=dict(language_code=language0.code))
    client.login(username=user.username, password=request_users["password"])
    response = client.get(admin_url)
    if not user.is_superuser:
        assert response.status_code == 403
        if user.is_anonymous():
            return
        team.add_member(user, "admin")
        response = client.get(admin_url)
    assert json.loads(response.content)["items"] == []
    search_member = (member if user == member2 else member2)
    response = client.get("%s?q=%s" % (admin_url, search_member.username[:2]))
    result = json.loads(response.content)
    assert search_member.username in [r["username"] for r in result["items"]]
    team = language_team.get(language0.__class__)(language0)
    team.add_member(search_member, "member")
    response = client.get("%s?q=%s" % (admin_url, search_member.username[:2]))
    result = json.loads(response.content)
    assert (search_member.username
            not in [r["username"] for r in result["items"]])
    if user in team.admins:
        team.remove_member(user)

    from django.core.cache import cache
    from django.utils.encoding import iri_to_uri
    key = iri_to_uri('Permissions:%s' % user.username)
    key = iri_to_uri('Permissions:%s' % search_member.username)
    cache.delete(key)
示例#2
0
def tp_uploads(request, client):
    from pootle.core.delegate import language_team
    from pootle_language.models import Language
    from pootle_translationproject.models import TranslationProject
    from pootle_store.models import Store
    from django.contrib.auth import get_user_model

    submitter_name, uploader_name, errors = request.param
    uploader = get_user_model().objects.get(username=uploader_name)
    tp = TranslationProject.objects.all()[0]
    store = Store.objects.filter(parent=tp.directory)[0]
    kwargs = {
        "project_code": tp.project.code,
        "language_code": tp.language.code,
        "dir_path": "",
        "filename": store.name
    }
    password = TEST_USERS[submitter_name]['password']
    language_team.get(Language)(tp.language).add_member(uploader, "submitter")
    client.login(username=submitter_name, password=password)
    updated_units = [(unit.source_f, "%s UPDATED" % unit.target_f, False)
                     for unit in store.units]
    updated_store = create_store(store.pootle_path, "0", updated_units)
    uploaded_file = SimpleUploadedFile(store.name, str(updated_store),
                                       "text/x-gettext-translation")
    response = client.post(reverse("pootle-tp-store-browse", kwargs=kwargs), {
        'name': '',
        'file': uploaded_file,
        'user_id': uploader.id
    })

    return tp, response.wsgi_request, response, kwargs, errors
示例#3
0
文件: views.py 项目: cloph/pootle
def test_view_language_team_new_member(client, language0, request_users,
                                       member, member2):
    user = request_users["user"]
    team = language_team.get(language0.__class__)(language0)
    admin_url = reverse(
        'pootle-language-admin-team-new-members',
        kwargs=dict(language_code=language0.code))
    client.login(
        username=user.username,
        password=request_users["password"])
    if not user.is_superuser:
        response = client.post(admin_url)
        assert response.status_code == 403
    else:
        with pytest.raises(Http400):
            client.post(admin_url)

    response = client.post(admin_url, data=dict(q="DOES NOT EXIST"))
    if not user.is_superuser:
        if user.is_anonymous:
            assert response.status_code == 402
            return
        assert response.status_code == 403
        team.add_member(user, "admin")
        response = client.post(admin_url, data=dict(q="DOES NOT EXIST"))
    assert json.loads(response.content)["items"]["results"] == []
    search_member = (
        member
        if user == member2
        else member2)
    response = client.post(admin_url, data=dict(q=search_member.username[:2]))
    result = json.loads(response.content)
    assert search_member.username in [r["text"] for r in result["items"]["results"]]
    team = language_team.get(language0.__class__)(language0)
    team.add_member(search_member, "member")
    response = client.post(admin_url, data=dict(q=search_member.username[:2]))
    result = json.loads(response.content)
    assert (
        search_member.username
        not in [r["text"] for r in result["items"]["results"]])
    if user in team.admins:
        team.remove_member(user)

    from django.core.cache import cache
    from django.utils.encoding import iri_to_uri
    key = iri_to_uri('Permissions:%s' % user.username)
    key = iri_to_uri('Permissions:%s' % search_member.username)
    cache.delete(key)
示例#4
0
def test_view_language_team_admin_post(client, language0, request_users,
                                       member, member2):
    user = request_users["user"]
    team = language_team.get(language0.__class__)(language0)
    search_member = (member if user == member2 else member2)
    assert search_member not in team.members
    admin_url = reverse('pootle-language-admin-team',
                        kwargs=dict(language_code=language0.code))
    client.login(username=user.username, password=request_users["password"])
    response = client.post(admin_url,
                           data=dict(new_member=search_member.id,
                                     role="member"))
    if not user.is_superuser:
        assert search_member not in team.members
        if user.is_anonymous():
            assert response.status_code == 402
            return
        team.add_member(user, "admin")
        response = client.post(admin_url,
                               data=dict(new_member=search_member.id,
                                         role="member"))
    team.update_permissions()
    assert search_member in team.members
    assert response.status_code == 302
    response = client.post(admin_url, data=dict(rm_members=[search_member.id]))
    team.update_permissions()
    assert search_member not in team.members
    assert response.status_code == 302
示例#5
0
def test_display_language_suggestion(language0):
    team = language_team.get()(language0)
    suggestion = team.suggestions.first()
    display = SuggestionDisplay(suggestion)
    assert display.__suggestion__ is suggestion
    assert (
        display.project
        == ("<a href='%s'>%s</a>"
            % (suggestion.unit.store.translation_project.pootle_path,
               suggestion.unit.store.translation_project.project.code)))
    assert display.unit == display.__suggestion__.unit.source
    assert (
        display.unit_link
        == ("<a href='%s'>#%s</a>"
            % (suggestion.unit.get_translate_url(),
               suggestion.unit.id)))
    assert (
        str(display.unit_state)
        == STATES_MAP[suggestion.unit.state])
    assert (
        display.state
        == suggestion.state)

    with pytest.raises(AttributeError):
        display.DOES_NOT_EXIST
示例#6
0
文件: teams.py 项目: sjhale/pootle
def test_language_team_non_members(language0, member):
    team = language_team.get(Language)(language0)
    team.add_member(member, "member")
    User = get_user_model()
    assert (sorted(team.non_members.values_list("id", flat=True)) == sorted(
        User.objects.exclude(username=member.username).values_list("id",
                                                                   flat=True)))
示例#7
0
def test_view_language_team_admin(client, language0, request_users):
    user = request_users["user"]
    team = language_team.get(language0.__class__)(language0)
    admin_url = reverse('pootle-language-admin-team',
                        kwargs=dict(language_code=language0.code))
    client.login(username=user.username, password=request_users["password"])
    response = client.get(admin_url)
    if not user.is_superuser:
        assert response.status_code == 403
        if user.is_anonymous:
            return
        team.add_member(user, "admin")
        response = client.get(admin_url)
    assert isinstance(response.context["form"], LanguageTeamAdminForm)
    assert (list(response.context["tps"]) == list(
        language0.translationproject_set.exclude(project__disabled=True)))
    for k in response.context["stats"].keys():
        if k.endswith("_display"):
            del response.context["stats"][k]
    assert (sorted(response.context["stats"]) == sorted(
        language0.data_tool.get_stats(include_children=False, user=user)))
    assert (response.context["suggestions"] ==
            response.context["form"].language_team.suggestions.count())
    assert response.context["language"] == language0
    if user in team.admins:
        team.remove_member(user)
示例#8
0
文件: views.py 项目: cloph/pootle
def test_display_language_suggestion(language0):
    team = language_team.get()(language0)
    suggestion = team.suggestions.first()
    display = SuggestionDisplay(suggestion)
    assert display.__suggestion__ is suggestion
    assert (
        display.project
        == ("<a href='%s'>%s</a>"
            % (suggestion.unit.store.translation_project.pootle_path,
               suggestion.unit.store.translation_project.project.code)))
    assert display.unit == display.__suggestion__.unit.source
    assert (
        display.unit_link
        == ("<a href='%s'>#%s</a>"
            % (suggestion.unit.get_translate_url(),
               suggestion.unit.id)))
    assert (
        str(display.unit_state)
        == STATES_MAP[suggestion.unit.state])
    assert (
        display.state
        == suggestion.state)

    with pytest.raises(AttributeError):
        display.DOES_NOT_EXIST
示例#9
0
文件: views.py 项目: cloph/pootle
def test_view_admin_language_team_suggestion(client, language0, request_users):
    user = request_users["user"]
    team = language_team.get(language0.__class__)(language0)
    admin_url = reverse(
        'pootle-language-admin-suggestions',
        kwargs=dict(language_code=language0.code))
    client.login(
        username=user.username,
        password=request_users["password"])
    response = client.get(admin_url)
    if not user.is_superuser:
        assert response.status_code == 403
        if user.is_anonymous:
            return
        team.add_member(user, "admin")
        response = client.get(admin_url)
    assert response.context["language"] == language0
    assert response.context["page"] == "admin-suggestions"
    formtable = response.context["formtable"]
    assert isinstance(formtable, SuggestionFormtable)
    assert isinstance(formtable.form, LanguageSuggestionAdminForm)
    assert formtable.form.user == response.wsgi_request.user
    assert formtable.form.language == language0
    assert formtable.form.data == dict(
        page_no=1,
        results_per_page=10)
    assert (
        [x[0] for x in formtable.form.fields["suggestions"].choices]
        == [item.id
            for item in
            formtable.form.batch().object_list])
    assert isinstance(
        formtable.form.fields["suggestions"].choices[0][1],
        SuggestionDisplay)
示例#10
0
def test_view_admin_language_team_suggestion(client, language0, request_users):
    user = request_users["user"]
    team = language_team.get(language0.__class__)(language0)
    admin_url = reverse('pootle-language-admin-suggestions',
                        kwargs=dict(language_code=language0.code))
    client.login(username=user.username, password=request_users["password"])
    response = client.get(admin_url)
    if not user.is_superuser:
        assert response.status_code == 403
        if user.is_anonymous():
            return
        team.add_member(user, "admin")
        response = client.get(admin_url)
    assert response.context["language"] == language0
    assert response.context["page"] == "admin-suggestions"
    formtable = response.context["formtable"]
    assert isinstance(formtable, SuggestionFormtable)
    assert isinstance(formtable.form, LanguageSuggestionAdminForm)
    assert formtable.form.user == response.wsgi_request.user
    assert formtable.form.language == language0
    assert formtable.form.data == dict(page_no=1, results_per_page=10)
    assert ([x[0] for x in formtable.form.fields["suggestions"].choices
             ] == [item.id for item in formtable.form.batch().object_list])
    assert isinstance(formtable.form.fields["suggestions"].choices[0][1],
                      SuggestionDisplay)
示例#11
0
文件: teams.py 项目: ta2-1/pootle
def test_language_team_non_members(language0, member):
    team = language_team.get(Language)(language0)
    team.add_member(member, "member")
    User = get_user_model()
    assert (
        sorted(team.non_members.values_list("id", flat=True))
        == sorted(
            User.objects.exclude(
                username=member.username).values_list("id", flat=True)))
示例#12
0
文件: teams.py 项目: sjhale/pootle
def test_language_team_suggestions(language0):
    team = language_team.get(Language)(language0)
    suggestions = Suggestion.objects.filter(
        state=SuggestionStates.PENDING,
        unit__state__gt=OBSOLETE,
        unit__store__translation_project__language=language0)
    assert (list(team.suggestions) == list(
        suggestions.order_by("-creation_time")))
    # there should be some suggestions in the env
    assert team.suggestions
    assert (team.users_with_suggestions == set(
        team.suggestions.values_list("user__username", "user__full_name")))
示例#13
0
def test_view_admin_language_suggestion_post(client, language0, request_users,
                                             mailoutbox):
    user = request_users["user"]
    team = language_team.get(language0.__class__)(language0)
    admin_url = reverse('pootle-language-admin-suggestions',
                        kwargs=dict(language_code=language0.code))
    client.login(username=user.username, password=request_users["password"])
    suggestion = team.suggestions.first()
    data = dict(actions="accept", suggestions=[suggestion.id])
    response = client.post(admin_url, data=data)
    if not user.is_superuser:
        if user.is_anonymous:
            assert response.status_code == 402
            return
        assert response.status_code == 403
        team.add_member(user, "admin")
        response = client.post(admin_url, data=data)
    assert response.status_code == 302
    suggestion.refresh_from_db()
    assert suggestion.state.name == "accepted"
    assert len(mailoutbox) == 0

    # reject
    suggestion = team.suggestions.first()
    data = dict(actions="reject", suggestions=[suggestion.id])
    response = client.post(admin_url, data=data)
    assert response.status_code == 302
    suggestion.refresh_from_db()
    assert suggestion.state.name == "rejected"
    assert len(mailoutbox) == 0

    # reject with comment
    suggestion = team.suggestions.first()
    data = dict(actions="accept",
                comment="ta very much!",
                suggestions=[suggestion.id])
    response = client.post(admin_url, data=data)
    assert response.status_code == 302
    suggestion.refresh_from_db()
    assert suggestion.state.name == "accepted"
    assert len(mailoutbox) == 1

    # reject with comment
    suggestion = team.suggestions.first()
    data = dict(actions="reject",
                comment="no way!",
                suggestions=[suggestion.id])
    response = client.post(admin_url, data=data)
    assert response.status_code == 302
    suggestion.refresh_from_db()
    assert suggestion.state.name == "rejected"
    assert len(mailoutbox) == 2
示例#14
0
文件: views.py 项目: arky/pootle
def tp_uploads(request, client):
    from pootle.core.delegate import language_team
    from pootle_language.models import Language
    from pootle_translationproject.models import TranslationProject
    from pootle_store.models import Store
    from django.contrib.auth import get_user_model

    submitter_name, uploader_name, errors = request.param
    uploader = get_user_model().objects.get(username=uploader_name)
    tp = TranslationProject.objects.all()[0]
    store = Store.objects.filter(parent=tp.directory)[0]
    kwargs = {
        "project_code": tp.project.code,
        "language_code": tp.language.code,
        "dir_path": "",
        "filename": store.name}
    password = TEST_USERS[submitter_name]['password']
    language_team.get(Language)(tp.language).add_member(uploader, "submitter")
    client.login(username=submitter_name, password=password)
    updated_units = [
        (unit.source_f, "%s UPDATED" % unit.target_f, False)
        for unit in store.units
    ]
    updated_store = create_store(store.pootle_path, "0", updated_units)
    uploaded_file = SimpleUploadedFile(
        store.name,
        str(updated_store),
        "text/x-gettext-translation"
    )
    response = client.post(
        reverse("pootle-tp-store-browse", kwargs=kwargs),
        {
            'name': '',
            'file': uploaded_file,
            'user_id': uploader.id
        }
    )

    return tp, response.wsgi_request, response, kwargs, errors
示例#15
0
文件: teams.py 项目: yiyibooks/pootle
def test_language_team_suggestions(language0):
    team = language_team.get(Language)(language0)
    suggestions = (Suggestion.objects.filter(
        state__name="pending",
        unit__state__gt=OBSOLETE,
        unit__store__translation_project__language=language0).exclude(
            unit__store__translation_project__project__disabled=True).exclude(
                unit__store__obsolete=True))
    assert (list(team.suggestions) == list(
        suggestions.order_by("-creation_time", "-pk")))
    # there should be some suggestions in the env
    assert team.suggestions
    assert (team.users_with_suggestions == set(
        team.suggestions.values_list("user__username", "user__full_name")))
示例#16
0
def test_language_team_suggestions(language0):
    team = language_team.get(Language)(language0)
    suggestions = Suggestion.objects.filter(
        state=SuggestionStates.PENDING,
        unit__state__gt=OBSOLETE,
        unit__store__translation_project__language=language0)
    assert (
        list(team.suggestions)
        == list(suggestions.order_by("-creation_time", "-pk")))
    # there should be some suggestions in the env
    assert team.suggestions
    assert (
        team.users_with_suggestions
        == set(
            team.suggestions.values_list(
                "user__username",
                "user__full_name")))
示例#17
0
def test_membership_user(member, member2, language0, language1):
    lang_team = language_team.get()
    user_member = membership.get(member.__class__)(member)
    assert isinstance(user_member, UserMembership)
    assert user_member.user == member
    assert user_member.teams == []
    assert user_member.teams_and_roles == {}

    lang_team(language0).add_member(member, "admin")
    user_member = membership.get(member.__class__)(member)
    assert user_member.teams == [language0.code]
    assert user_member.teams_and_permissions == {
        language0.code: set(['administrate', 'review', 'suggest', 'translate'])}
    user_member.teams_and_roles[language0.code]["role"] == "Admin"
    user_member.teams_and_roles[language0.code]["name"] == language0.name

    lang_team(language1).add_member(member, "submitter")
    user_member = membership.get(member.__class__)(member)
    assert sorted(user_member.teams) == [language0.code, language1.code]
    assert user_member.teams_and_permissions == {
        language0.code: set(['administrate', 'review', 'suggest', 'translate']),
        language1.code: set(['suggest', 'translate'])}
    user_member.teams_and_roles[language0.code]["role"] == "Admin"
    user_member.teams_and_roles[language0.code]["name"] == language0.name
    user_member.teams_and_roles[language1.code]["role"] == "Translater"
    user_member.teams_and_roles[language1.code]["name"] == language1.name

    lang_team(language0).add_member(member2, "reviewer")
    user_member = membership.get(member2.__class__)(member2)
    assert user_member.teams == [language0.code]
    assert user_member.teams_and_permissions == {
        language0.code: set(['review', 'suggest', 'translate'])}
    user_member.teams_and_roles[language0.code]["role"] == "Reviewer"
    user_member.teams_and_roles[language0.code]["name"] == language0.name

    lang_team(language1).add_member(member2, "member")
    user_member = membership.get(member2.__class__)(member2)
    assert sorted(user_member.teams) == [language0.code, language1.code]
    assert user_member.teams_and_permissions == {
        language0.code: set(['review', 'suggest', 'translate']),
        language1.code: set(['suggest'])}
    user_member.teams_and_roles[language0.code]["role"] == "Reviewer"
    user_member.teams_and_roles[language0.code]["name"] == language0.name
    user_member.teams_and_roles[language1.code]["role"] == ""
    user_member.teams_and_roles[language1.code]["name"] == language1.name
示例#18
0
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
示例#19
0
文件: teams.py 项目: arky/pootle
def test_language_team_suggestions(language0):
    team = language_team.get(Language)(language0)
    suggestions = (
        Suggestion.objects.filter(
            state__name="pending",
            unit__state__gt=OBSOLETE,
            unit__store__translation_project__language=language0
        ).exclude(
            unit__store__translation_project__project__disabled=True
        ).exclude(unit__store__obsolete=True))
    assert (
        list(team.suggestions)
        == list(suggestions.order_by("-creation_time", "-pk")))
    # there should be some suggestions in the env
    assert team.suggestions
    assert (
        team.users_with_suggestions
        == set(
            team.suggestions.values_list(
                "user__username",
                "user__full_name")))
示例#20
0
def test_view_language_team_admin(client, language0, request_users):
    user = request_users["user"]
    team = language_team.get(language0.__class__)(language0)
    admin_url = reverse(
        'pootle-language-admin-team',
        kwargs=dict(language_code=language0.code))
    client.login(
        username=user.username,
        password=request_users["password"])
    response = client.get(admin_url)
    if not user.is_superuser:
        assert response.status_code == 403
        if user.is_anonymous:
            return
        team.add_member(user, "admin")
        response = client.get(admin_url)
    assert isinstance(
        response.context["form"], LanguageTeamAdminForm)
    assert (
        list(response.context["tps"])
        == list(
            language0.translationproject_set.exclude(
                project__disabled=True)))
    for k in response.context["stats"].keys():
        if k.endswith("_display"):
            del response.context["stats"][k]
    assert (
        list(response.context["stats"])
        == list(
            language0.data_tool.get_stats(
                include_children=False,
                user=user)))
    assert (
        list(response.context["suggestions"])
        == list(
            response.context["form"].language_team.suggestions))
    assert response.context["language"] == language0
    if user in team.admins:
        team.remove_member(user)
示例#21
0
文件: views.py 项目: cloph/pootle
def test_view_language_team_admin_post(client, language0, request_users,
                                       member, member2):
    user = request_users["user"]
    team = language_team.get(language0.__class__)(language0)
    search_member = (
        member
        if user == member2
        else member2)
    assert search_member not in team.members
    admin_url = reverse(
        'pootle-language-admin-team',
        kwargs=dict(language_code=language0.code))
    client.login(
        username=user.username,
        password=request_users["password"])
    response = client.post(
        admin_url,
        data=dict(new_member=search_member.id, role="member"))
    if not user.is_superuser:
        assert search_member not in team.members
        if user.is_anonymous:
            assert response.status_code == 402
            return
        team.add_member(user, "admin")
        response = client.post(
            admin_url,
            data=dict(new_member=search_member.id, role="member"))
    team.update_permissions()
    assert search_member in team.members
    assert response.status_code == 302
    response = client.post(
        admin_url,
        data=dict(rm_members=[search_member.id]))
    team.update_permissions()
    assert search_member not in team.members
    assert response.status_code == 302
示例#22
0
 def language_team(self):
     return language_team.get(self.language.__class__)(self.language)
示例#23
0
文件: forms.py 项目: claudep/pootle
 def language_team(self):
     return language_team.get(self.language.__class__)(self.language)
示例#24
0
文件: views.py 项目: cloph/pootle
def test_view_admin_language_suggestion_post(client, language0, request_users,
                                             mailoutbox):
    user = request_users["user"]
    team = language_team.get(language0.__class__)(language0)
    admin_url = reverse(
        'pootle-language-admin-suggestions',
        kwargs=dict(language_code=language0.code))
    client.login(
        username=user.username,
        password=request_users["password"])
    suggestion = team.suggestions.first()
    data = dict(
        actions="accept",
        suggestions=[suggestion.id])
    response = client.post(admin_url, data=data)
    if not user.is_superuser:
        if user.is_anonymous:
            assert response.status_code == 402
            return
        assert response.status_code == 403
        team.add_member(user, "admin")
        response = client.post(admin_url, data=data)
    assert response.status_code == 302
    suggestion.refresh_from_db()
    assert suggestion.state.name == "accepted"
    assert len(mailoutbox) == 0

    # reject
    suggestion = team.suggestions.first()
    data = dict(
        actions="reject",
        suggestions=[suggestion.id])
    response = client.post(admin_url, data=data)
    assert response.status_code == 302
    suggestion.refresh_from_db()
    assert suggestion.state.name == "rejected"
    assert len(mailoutbox) == 0

    # reject with comment
    suggestion = team.suggestions.first()
    data = dict(
        actions="accept",
        comment="ta very much!",
        suggestions=[suggestion.id])
    response = client.post(admin_url, data=data)
    assert response.status_code == 302
    suggestion.refresh_from_db()
    assert suggestion.state.name == "accepted"
    assert len(mailoutbox) == 1

    # reject with comment
    suggestion = team.suggestions.first()
    data = dict(
        actions="reject",
        comment="no way!",
        suggestions=[suggestion.id])
    response = client.post(admin_url, data=data)
    assert response.status_code == 302
    suggestion.refresh_from_db()
    assert suggestion.state.name == "rejected"
    assert len(mailoutbox) == 2
示例#25
0
文件: views.py 项目: ainslied/pootle
def handle_upload_form(request, tp):
    """Process the upload form."""
    valid_extensions = tp.project.filetype_tool.valid_extensions
    if "po" not in valid_extensions:
        return {}
    language = tp.language
    team = language_team.get(tp.language.__class__)(language)

    uploader_list = [(request.user.id, request.user.display_name), ]
    if check_permission('administrate', request):
        User = get_user_model()
        uploader_list = [
            (user.id, user.display_name)
            for user
            in (team.submitters | team.reviewers | team.admins | team.superusers)]

    if request.method == "POST" and "file" in request.FILES:
        upload_form = UploadForm(
            request.POST,
            request.FILES,
            uploader_list=uploader_list
        )

        if upload_form.is_valid():
            uploader_id = upload_form.cleaned_data["user_id"]
            django_file = request.FILES["file"]
            uploader = request.user
            if uploader_id and uploader_id != uploader.id:
                User = get_user_model()
                uploader = User.objects.get(
                    id=upload_form.cleaned_data["user_id"]
                )

            try:
                if is_zipfile(django_file):
                    with ZipFile(django_file, "r") as zf:
                        for path in zf.namelist():
                            if path.endswith("/"):
                                # is a directory
                                continue
                            ext = os.path.splitext(path)[1].strip(".")
                            if ext not in valid_extensions:
                                continue
                            with zf.open(path, "r") as f:
                                import_file(f, user=uploader)
                else:
                    # is_zipfile consumes the file buffer
                    django_file.seek(0)
                    import_file(django_file, user=uploader)
            except Exception as e:
                upload_form.add_error("file", e)
                return {
                    "upload_form": upload_form,
                }
        else:
            return {
                "upload_form": upload_form,
            }

    # Always return a blank upload form unless the upload form is not valid.
    return {
        "upload_form": UploadForm(
            uploader_list=uploader_list,
            initial=dict(user_id=request.user.id)
        ),
    }
示例#26
0
文件: teams.py 项目: sjhale/pootle
def test_language_team_members(language0, member):
    team = language_team.get(Language)(language0)
    assert (list(team.members) == list(team.submitters) == list(team.reviewers)
            == list(team.admins) == [])
    team.add_member(member, "member")
    assert list(team.members) == [member]
    assert (list(team.submitters) == list(team.reviewers) == list(team.admins)
            == [])
    assert (member.permissionset_set.filter(
        directory=language0.directory).filter(
            positive_permissions__codename="suggest").count() == 1)
    assert (member.permissionset_set.filter(
        directory=language0.directory).exclude(
            positive_permissions__codename="suggest").count() == 0)
    team.add_member(member, "submitter")
    assert list(team.submitters) == [member]
    assert (list(team.members) == list(team.reviewers) == list(team.admins) ==
            [])
    assert (member.permissionset_set.filter(
        directory=language0.directory).filter(
            positive_permissions__codename__in=["suggest", "translate"
                                                ]).count() == 2)
    assert (member.permissionset_set.filter(
        directory=language0.directory).exclude(
            positive_permissions__codename__in=["suggest", "translate"
                                                ]).count() == 0)
    team.add_member(member, "reviewer")
    assert list(team.reviewers) == [member]
    assert (list(team.members) == list(team.submitters) == list(team.admins) ==
            [])
    assert (member.permissionset_set.filter(
        directory=language0.directory).filter(
            positive_permissions__codename__in=[
                "suggest", "review", "translate"
            ]).count() == 3)
    assert (member.permissionset_set.filter(
        directory=language0.directory).exclude(
            positive_permissions__codename__in=[
                "suggest", "review", "translate"
            ]).count() == 0)
    team.add_member(member, "admin")
    assert list(team.admins) == [member]
    assert (list(team.members) == list(team.submitters) == list(team.reviewers)
            == [])
    assert (member.permissionset_set.filter(
        directory=language0.directory).filter(
            positive_permissions__codename__in=[
                "suggest", "review", "administrate", "translate"
            ]).count() == 4)
    assert (member.permissionset_set.filter(
        directory=language0.directory).exclude(
            positive_permissions__codename__in=[
                "suggest", "review", "administrate", "translate"
            ]).count() == 0)
    team.remove_member(member)
    assert (list(team.members) == list(team.submitters) == list(team.reviewers)
            == list(team.admins) == [])
    assert (member.permissionset_set.filter(
        directory=language0.directory).filter(
            positive_permissions__codename__in=[
                "suggest", "review", "administrate", "translate"
            ]).count() == 0)
示例#27
0
文件: teams.py 项目: sjhale/pootle
def test_language_team_getter(language0):
    team = language_team.get(Language)(language0)
    assert isinstance(team, LanguageTeam)
示例#28
0
文件: teams.py 项目: ta2-1/pootle
def test_language_team_getter(language0):
    team = language_team.get(Language)(language0)
    assert isinstance(team, LanguageTeam)
示例#29
0
文件: teams.py 项目: ta2-1/pootle
def test_language_team_members(language0, member):
    team = language_team.get(Language)(language0)
    assert (
        list(team.members)
        == list(team.submitters)
        == list(team.reviewers)
        == list(team.admins)
        == [])
    team.add_member(member, "member")
    assert list(team.members) == [member]
    assert (
        list(team.submitters)
        == list(team.reviewers)
        == list(team.admins)
        == [])
    assert (
        member.permissionset_set
              .filter(directory=language0.directory)
              .filter(positive_permissions__codename="suggest")
              .count()
        == 1)
    assert (
        member.permissionset_set
              .filter(directory=language0.directory)
              .exclude(positive_permissions__codename="suggest")
              .count()
        == 0)
    team.add_member(member, "submitter")
    assert list(team.submitters) == [member]
    assert (
        list(team.members)
        == list(team.reviewers)
        == list(team.admins)
        == [])
    assert (
        member.permissionset_set
              .filter(directory=language0.directory)
              .filter(positive_permissions__codename__in=["suggest",
                                                          "translate"])
              .count()
        == 2)
    assert (
        member.permissionset_set
              .filter(directory=language0.directory)
              .exclude(positive_permissions__codename__in=["suggest",
                                                           "translate"])
              .count()
        == 0)
    team.add_member(member, "reviewer")
    assert list(team.reviewers) == [member]
    assert (
        list(team.members)
        == list(team.submitters)
        == list(team.admins)
        == [])
    assert (
        member.permissionset_set
              .filter(directory=language0.directory)
              .filter(positive_permissions__codename__in=["suggest",
                                                          "review",
                                                          "translate"])
              .count()
        == 3)
    assert (
        member.permissionset_set
              .filter(directory=language0.directory)
              .exclude(positive_permissions__codename__in=["suggest",
                                                           "review",
                                                           "translate"])
              .count()
        == 0)
    team.add_member(member, "admin")
    assert list(team.admins) == [member]
    assert (
        list(team.members)
        == list(team.submitters)
        == list(team.reviewers)
        == [])
    assert (
        member.permissionset_set
              .filter(directory=language0.directory)
              .filter(positive_permissions__codename__in=["suggest",
                                                          "review",
                                                          "administrate",
                                                          "translate"])
              .count()
        == 4)
    assert (
        member.permissionset_set
              .filter(directory=language0.directory)
              .exclude(positive_permissions__codename__in=["suggest",
                                                           "review",
                                                           "administrate",
                                                           "translate"])
              .count()
        == 0)
    team.remove_member(member)
    assert (
        list(team.members)
        == list(team.submitters)
        == list(team.reviewers)
        == list(team.admins)
        == [])
    assert (
        member.permissionset_set
              .filter(directory=language0.directory)
              .filter(positive_permissions__codename__in=["suggest",
                                                          "review",
                                                          "administrate",
                                                          "translate"])
              .count()
        == 0)
示例#30
0
def handle_upload_form(request, tp):
    """Process the upload form."""
    valid_extensions = tp.project.filetype_tool.valid_extensions
    if "po" not in valid_extensions:
        return {}
    language = tp.language
    team = language_team.get(tp.language.__class__)(language)

    uploader_list = [
        (request.user.id, request.user.display_name),
    ]
    if check_permission('administrate', request):
        User = get_user_model()
        uploader_list = [(user.id, user.display_name)
                         for user in (team.submitters | team.reviewers
                                      | team.admins | team.superusers)]

    if request.method == "POST" and "file" in request.FILES:
        upload_form = UploadForm(request.POST,
                                 request.FILES,
                                 uploader_list=uploader_list)

        if upload_form.is_valid():
            uploader_id = upload_form.cleaned_data["user_id"]
            django_file = request.FILES["file"]
            uploader = request.user
            if uploader_id and uploader_id != uploader.id:
                User = get_user_model()
                uploader = User.objects.get(
                    id=upload_form.cleaned_data["user_id"])

            try:
                if is_zipfile(django_file):
                    with ZipFile(django_file, "r") as zf:
                        for path in zf.namelist():
                            if path.endswith("/"):
                                # is a directory
                                continue
                            ext = os.path.splitext(path)[1].strip(".")
                            if ext not in valid_extensions:
                                continue
                            with zf.open(path, "r") as f:
                                import_file(f, user=uploader)
                else:
                    # is_zipfile consumes the file buffer
                    django_file.seek(0)
                    import_file(django_file, user=uploader)
            except Exception as e:
                upload_form.add_error("file", e)
                return {
                    "upload_form": upload_form,
                }
        else:
            return {
                "upload_form": upload_form,
            }

    # Always return a blank upload form unless the upload form is not valid.
    return {
        "upload_form":
        UploadForm(uploader_list=uploader_list,
                   initial=dict(user_id=request.user.id)),
    }