Пример #1
0
def post_draft_for_bright_mirror(
        request, test_session, discussion, moderator_user,
        bright_mirror):
    from assembl.models import Post, Idea, LangString, IdeaRelatedPostLink, PublicationStates
    from graphene.relay import Node
    idea_id = bright_mirror
    raw_id = int(Node.from_global_id(idea_id)[1])
    idea = Idea.get(raw_id)
    p = Post(
        discussion=discussion, creator=moderator_user,
        subject=LangString.create(u"Draft"),
        body=LangString.create(u"A simple draft fiction"),
        type='post', publication_state=PublicationStates.DRAFT,
        message_id="*****@*****.**",
        creation_date = datetime.utcnow() - timedelta(days=7))

    idc = IdeaRelatedPostLink(
        idea=idea,
        creator=moderator_user,
        content=p)

    test_session.add(p)
    test_session.add(idc)
    test_session.flush()

    def fin():
        print "finalizer post_draft_for_bright_mirror"
        test_session.delete(p)
        test_session.delete(idc)
        test_session.flush()

    request.addfinalizer(fin)
    return p
Пример #2
0
def post_related_to_sub_idea_1(
        request, test_session, discussion, admin_user, subidea_1):
    from assembl.models import Post, LangString, IdeaRelatedPostLink
    idea = subidea_1
    p = Post(
        discussion=discussion, creator=admin_user,
        subject=LangString.create(u"A post related to sub_idea_1 "),
        body=LangString.create(u"A post related to sub_idea_1"),
        type='post', message_id="*****@*****.**")

    idc = IdeaRelatedPostLink(
        idea=idea,
        creator=admin_user,
        content=p)

    test_session.add(p)
    test_session.add(idc)
    test_session.flush()

    def fin():
        print "finalizer root_post_en_under_positive_column_of_idea"
        test_session.delete(p)
        test_session.delete(idc)
        test_session.flush()

    request.addfinalizer(fin)
    return p
Пример #3
0
def subidea_1_1_1_1_2_2(request, discussion, subidea_1_1_1_1_2, test_session):
    """An Idea fixture with a idealink to subidea_1_1_1_1_2 fixture::

        root_idea
            |-> subidea_1
                |-> subidea_1_1
                    |-> subidea_1_1_1
                        |-> subidea_1_1_1_1
                            |-> subidea_1_1_1_1
                            |-> subidea_1_1_1_2
                                |-> subidea_1_1_1_1_2_1
                                |-> subidea_1_1_1_1_2_2"""

    from assembl.models import Idea, IdeaLink, LangString
    i = Idea(title=LangString.create(u"Federal programs are ineffective", 'en'),
             discussion=discussion,
             description=LangString.create("Some definition of an idea", 'en'))
    test_session.add(i)
    l_11112_111122 = IdeaLink(source=subidea_1_1_1_1_2, target=i)
    test_session.add(l_11112_111122)
    test_session.flush()

    def fin():
        print "finalizer subidea_1_1_1_1_2_2"
        test_session.delete(l_11112_111122)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)
    return i
Пример #4
0
def post_published_for_bright_mirror_participant(
        request, test_session, discussion, admin_user, participant1_user,
        bright_mirror):
    from assembl.models import Post, Idea, LangString, IdeaRelatedPostLink, PublicationStates
    from graphene.relay import Node
    idea_id = bright_mirror
    raw_id = int(Node.from_global_id(idea_id)[1])
    idea = Idea.get(raw_id)
    p = Post(
        discussion=discussion, creator=participant1_user,
        subject=LangString.create(u"Published by participant"),
        body=LangString.create(u"A simple published fiction by participant"),
        type='post', publication_state=PublicationStates.PUBLISHED,
        message_id="*****@*****.**",
        creation_date = datetime.utcnow())

    idc = IdeaRelatedPostLink(
        idea=idea,
        creator=admin_user,
        content=p)

    test_session.add(p)
    test_session.add(idc)
    test_session.flush()

    def fin():
        print "finalizer post_published_for_bright_mirror"
        test_session.delete(p)
        test_session.delete(idc)
        test_session.flush()

    request.addfinalizer(fin)
    return p
Пример #5
0
def subidea_1_1_1_1_1(request, discussion, subidea_1_1_1_1, test_session):
    """An Idea fixture with a idealink to subidea_1_1_1_1 fixture::

        root_idea
            |-> subidea_1
                |-> subidea_1_1
                    |-> subidea_1_1_1
                        |-> subidea_1_1_1_1
                            |-> subidea_1_1_1_1"""

    from assembl.models import Idea, IdeaLink, LangString
    i = Idea(title=LangString.create(u"Job loss", 'en'),
             discussion=discussion,
             description=LangString.create("Some definition of an idea", 'en'))
    test_session.add(i)
    l_1111_11111 = IdeaLink(source=subidea_1_1_1_1, target=i)
    test_session.add(l_1111_11111)
    test_session.flush()

    def fin():
        print "finalizer subidea_1_1_1_1_1_1"
        test_session.delete(l_1111_11111)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)
    return i
Пример #6
0
def idea_message_column_negative_on_subidea_1_1(request, test_adminuser_webrequest, subidea_1_1, test_session):
    from assembl.models import IdeaMessageColumn, LangString

    column = IdeaMessageColumn(idea=subidea_1_1,
                               message_classifier='negative',
                               name=LangString.create('Say my name', 'en'),
                               title=LangString.create('Add your point of view against the theme', 'en'),
                               color="red")

    test_session.add(column)
    synthesis = column.create_column_synthesis(
        subject=LangString.create('Be negative!', 'en'),
        body=LangString.create('This is a negative header', 'en'),
        creator_id=test_adminuser_webrequest.authenticated_userid
    )
    test_session.flush()

    def fin():
        test_session.delete(synthesis)
        test_session.delete(synthesis.idea_links_of_content[0])
        test_session.delete(column)
        test_session.flush()

    request.addfinalizer(fin)
    return column
Пример #7
0
def post_body_locale_determined_by_import(
        request, test_session, discussion, admin_user, mailbox,
        undefined_locale, fr_locale, en_locale):
    from assembl.models import Email, LangString
    p = Email(
        discussion=discussion, creator=admin_user,
        subject=LangString.create(u"testa"),
        body=LangString.create(u"testa"),
        source=mailbox,
        body_mime_type="text/plain",
        sender="*****@*****.**",
        recipients="*****@*****.**",
        message_id="*****@*****.**",
        imported_blob="""Subject: testa
From: Mr. Administrator <*****@*****.**>
Content-Language: fr
Content-Type: text/plain; charset="iso-8859-1"

testa""")
    # must be done after the source is set
    p.source_post_id = "*****@*****.**"
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer post_subject_locale_determined_by_creator"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #8
0
def creativity_session_widget_new_idea(
        request, test_session, discussion, subidea_1,
        creativity_session_widget, participant1_user):
    """An Idea fixture with an bound ideaLink,
    GeneratedIdeaWidgetLink, and a IdeaProposalPost"""

    from assembl.models import (Idea, IdeaLink, GeneratedIdeaWidgetLink,
                                IdeaProposalPost, LangString)
    i = Idea(
        discussion=discussion,
        title=LangString.create(u"generated idea", 'en'))
    test_session.add(i)
    l_1_wi = IdeaLink(source=subidea_1, target=i)
    test_session.add(l_1_wi)
    l_w_wi = GeneratedIdeaWidgetLink(
        widget=creativity_session_widget,
        idea=i)
    ipp = IdeaProposalPost(
        proposes_idea=i, creator=participant1_user, discussion=discussion,
        message_id='*****@*****.**',
        subject=LangString.create(u"propose idea"),
        body=LangString.EMPTY(test_session))
    test_session.add(ipp)

    def fin():
        print "finalizer creativity_session_widget_new_idea"
        test_session.delete(ipp)
        test_session.delete(l_w_wi)
        test_session.delete(l_1_wi)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)

    return i
Пример #9
0
def timeline_vote_session(request, test_session, discussion):
    from assembl.models import DiscussionPhase, LangString

    phase = DiscussionPhase(
        discussion=discussion,
        identifier='voteSession',
        title=LangString.create(u"voteSession phase title fixture", "en"),
        description=LangString.create(u"voteSession phase description fixture", "en"),
        start=datetime(2014, 12, 31, 9, 0, 0),
        end=datetime(2015, 12, 31, 9, 0, 0),
        interface_v1=False,
        image_url=u'https://example.net/image.jpg'
    )


    # Create the phase
    test_session.add(phase)
    test_session.flush()

    def fin():
        print "finalizer timeline"
        test_session.delete(phase)
        test_session.flush()

    request.addfinalizer(fin)
    return phase
Пример #10
0
def root_post_en_under_positive_column_of_idea(
        request, test_session, discussion, admin_user,
        idea_message_column_positive):
    from assembl.models import Post, LangString, IdeaRelatedPostLink
    idea = idea_message_column_positive.idea
    p = Post(
        discussion=discussion, creator=admin_user,
        subject=LangString.create(u"A simple positive subject"),
        body=LangString.create(u"A simple positive body"),
        type='post', message_id="*****@*****.**",
        message_classifier=idea_message_column_positive.message_classifier)

    idc = IdeaRelatedPostLink(
        idea=idea,
        creator=admin_user,
        content=p)

    test_session.add(p)
    test_session.add(idc)
    test_session.flush()

    def fin():
        print "finalizer root_post_en_under_positive_column_of_idea"
        test_session.delete(p)
        test_session.delete(idc)
        test_session.flush()

    request.addfinalizer(fin)
    return p
Пример #11
0
def creativity_session_widget_post(
        request, test_session, discussion, participant1_user,
        creativity_session_widget, creativity_session_widget_new_idea):
    """A Post fixture with a bound to a creativity widget to a new idea and
    an idea content link"""

    from assembl.models import (Post, IdeaContentWidgetLink, LangString)
    p = Post(
        discussion=discussion, creator=participant1_user,
        subject=LangString.create(u"re: generated idea"),
        body=LangString.create(u"post body"),
        type="post", message_id="*****@*****.**")
    test_session.add(p)
    test_session.flush()
    icwl = IdeaContentWidgetLink(
        content=p, idea=creativity_session_widget_new_idea,
        creator=participant1_user)
    test_session.add(icwl)

    def fin():
        print "finalizer creativity_session_widget_post"
        test_session.delete(icwl)
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)

    return p
Пример #12
0
def subidea_1_1_1(request, discussion, subidea_1_1, test_session):
    """An Idea fixture with a idealink to subidea_1_1 fixture::

        root_idea
            |-> subidea_1
                |-> subidea_1_1
                    |-> subidea_1_1_1"""

    from assembl.models import Idea, IdeaLink, LangString
    title = LangString.create(u"Lower government revenue", 'en')
    title.add_value(u'Moins de revenus pour le gouvernement', 'fr')
    i = Idea(title=title,
             discussion=discussion,
             description=LangString.create("Some definition of an idea", 'en'))
    test_session.add(i)
    l_11_111 = IdeaLink(source=subidea_1_1, target=i)
    test_session.add(l_11_111)
    test_session.flush()

    def fin():
        print "finalizer subidea_1_1_1"
        test_session.delete(l_11_111)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)
    return i
Пример #13
0
def post_related_to_sub_idea_1_1_1(
        request, test_session, discussion, admin_user, subidea_1_1_1):
    from assembl.models import Post, LangString, IdeaRelatedPostLink
    idea = subidea_1_1_1
    p = Post(
        discussion=discussion, creator=admin_user,
        subject=LangString.create(u"A post subject related to sub_idea_1_1_1"),
        body=LangString.create(u"A post body related to sub_idea_1_1_1"),
        creation_date=datetime(2018, 2, 17, 9, 0, 0),  # in the thread phase date range (see phases fixture)
        type='post', message_id="*****@*****.**")

    idc = IdeaRelatedPostLink(
        idea=idea,
        creator=admin_user,
        content=p)

    test_session.add(p)
    test_session.add(idc)
    test_session.flush()

    def fin():
        print "finalizer post_related_to_sub_idea_1_1_1"
        test_session.delete(p)
        test_session.delete(idc)
        test_session.flush()

    request.addfinalizer(fin)
    return p
Пример #14
0
 def fin():
     print "finalizer db_default_data"
     session = db_tables()
     clear_rows(get_config(), session)
     transaction.commit()
     from assembl.models import Locale, LangString
     Locale.reset_cache()
     LangString.reset_cache()
Пример #15
0
def create_idea(request):
    discussion_id = int(request.matchdict['discussion_id'])
    session = Discussion.default_db
    discussion = session.query(Discussion).get(int(discussion_id))
    user_id = request.authenticated_userid
    permissions = get_permissions(user_id, discussion.id)
    idea_data = json.loads(request.body)
    kwargs = {
        "discussion": discussion
    }

    for key, attr_name in langstring_fields.iteritems():
        if key in idea_data:
            ls_data = idea_data[key]
            if ls_data is None:
                continue
            assert isinstance(ls_data, dict)
            current = LangString.create_from_json(
                ls_data, user_id, permissions=permissions)
            kwargs[attr_name] = current

    new_idea = Idea(**kwargs)

    session.add(new_idea)

    if idea_data['parentId']:
        parent = Idea.get_instance(idea_data['parentId'])
    else:
        parent = discussion.root_idea
    session.add(IdeaLink(source=parent, target=new_idea, order=idea_data.get('order', 0.0)))

    session.flush()

    return {'ok': True, '@id': new_idea.uri()}
Пример #16
0
def sections(request, discussion_with_default_data, test_session):
    """Create default sections."""
    from assembl.models import Section, LangString
    from assembl.models.section import SectionTypesEnum
    discussion_id = discussion_with_default_data.id

    # default sections are created in the discussion_with_default_data fixture
    # via create_default_discussion_data

    sections = []
    # add a custom section
    custom_section = Section(
        discussion_id=discussion_id,
        title=LangString.create(u'GNU is not Unix', 'en'),
        url=u'http://www.gnu.org',
        section_type=SectionTypesEnum.CUSTOM.value,
        order=4.0
    )
    sections.append(custom_section)

    for section in sections:
        test_session.add(section)
    test_session.flush()

    def fin():
        print "finalizer sections"
        for section in sections:
            test_session.delete(section)
        test_session.flush()
    request.addfinalizer(fin)

    return sections
Пример #17
0
def save_synthesis(request):
    synthesis_id = request.matchdict['id']
    discussion_id = int(request.matchdict['discussion_id'])
    if synthesis_id == 'next_synthesis':
        discussion = Discussion.get_instance(discussion_id)
        synthesis = discussion.get_next_synthesis()
    else:
        synthesis = Synthesis.get_instance(synthesis_id)
    if not synthesis:
        raise HTTPBadRequest("Synthesis with id '%s' not found." %
                             synthesis_id)

    synthesis_data = json.loads(request.body)
    user_id = request.authenticated_userid
    permissions = get_permissions(user_id, discussion_id)

    for key in ('subject', 'introduction', 'conclusion'):
        if key in synthesis_data:
            ls_data = synthesis_data[key]
            if ls_data is None:
                continue
            assert isinstance(ls_data, dict)
            current = LangString.create_from_json(ls_data,
                                                  user_id,
                                                  permissions=permissions)
            setattr(synthesis, key, current)

    Synthesis.default_db.add(synthesis)
    Synthesis.default_db.flush()

    return {'ok': True, 'id': synthesis.uri()}
Пример #18
0
def save_synthesis(request):
    synthesis_id = request.matchdict['id']
    discussion_id = int(request.matchdict['discussion_id'])
    if synthesis_id == 'next_synthesis':
        discussion = Discussion.get_instance(discussion_id)
        synthesis = discussion.get_next_synthesis()
    else:
        synthesis = Synthesis.get_instance(synthesis_id)
    if not synthesis:
        raise HTTPBadRequest("Synthesis with id '%s' not found." % synthesis_id)

    synthesis_data = json.loads(request.body)
    user_id = request.authenticated_userid
    permissions = get_permissions(user_id, discussion_id)

    for key in ('subject', 'introduction', 'conclusion'):
        if key in synthesis_data:
            ls_data = synthesis_data[key]
            if ls_data is None:
                continue
            assert isinstance(ls_data, dict)
            current = LangString.create_from_json(
                ls_data, user_id, permissions=permissions)
            setattr(synthesis, key, current)

    Synthesis.default_db.add(synthesis)
    Synthesis.default_db.flush()

    return {'ok': True, 'id': synthesis.uri()}
Пример #19
0
def test_add_resource(admin_user, discussion, test_session):
    from assembl.models.resource import Resource
    from assembl.models import LangString

    resource = Resource(
        discussion_id=discussion.id,
        title=LangString.create(u"a resource"),
        text=LangString.create(u"Lorem ipsum dolor sit amet"),
        embed_code=u"<iframe ...>",
        order=3.0
    )

    assert resource.title.entries[0].value == u'a resource'
    assert resource.text.entries[0].value == u'Lorem ipsum dolor sit amet'
    assert resource.embed_code == u"<iframe ...>"
    assert resource.order == 3.0
Пример #20
0
def vote_session(request, test_session, discussion, timeline_vote_session,
                 simple_file, admin_user):
    from assembl.graphql.utils import create_root_thematic
    from assembl.models import Thematic, VoteSession, VoteSessionAttachment, LangString
    vote_session = VoteSession(
        discussion=discussion,
        discussion_phase=timeline_vote_session,
        title=LangString.create(u"vote session fixture", "en"),
        sub_title=LangString.create(u"vote session sub title fixture", "en"),
        instructions_section_title=LangString.create(
            u"vote session instructions title fixture", "en"),
        instructions_section_content=LangString.create(
            u"vote session instructions fixture. Lorem ipsum dolor sit amet",
            "en"),
        propositions_section_title=LangString.create(
            u"vote session propositions section title fixture", "en"))
    attachment = VoteSessionAttachment(discussion=discussion,
                                       document=simple_file,
                                       vote_session=vote_session,
                                       title=u"vote session image fixture",
                                       creator=admin_user,
                                       attachmentPurpose='IMAGE')

    test_session.add(vote_session)
    test_session.add(attachment)
    test_session.flush()

    identifier = 'voteSession{}'.format(vote_session.id)
    root_thematic = create_root_thematic(discussion, identifier)
    test_session.flush()

    def fin():
        print "finalizer vote_session"
        # header_image may have been replaced by another one in a test
        # so be sure to remove attachments, not header_image
        with test_session.no_autoflush as db:
            for attachment in list(vote_session.attachments):
                if attachment.document != simple_file:
                    attachment.document.delete()
                attachment.delete()

            db.delete(root_thematic)
            db.delete(vote_session)
            db.flush()

    request.addfinalizer(fin)
    return vote_session
Пример #21
0
def test_add_discussion(test_session):
    d = Discussion(
        topic=u"Education", slug="education",
        subscribe_to_notifications_on_signup=False,
        creator=None,
        session=test_session)
    d.discussion_locales = ['en', 'fr', 'de']
    d.terms_and_conditions = LangString.create(
        u"Use the haptic JSON system, then you can quantify the cross-platform capacitor!", "en")
    d.legal_notice = LangString.create(
        u"Use the optical SCSI microchip, then you can generate the cross-platform pixel!", "en")
    test_session.flush()
    assert d.topic == u"Education"
    assert d.discussion_locales == ['en', 'fr', 'de']
    assert d.terms_and_conditions.entries[0].value == u"Use the haptic JSON system, then you can quantify the cross-platform capacitor!"  # noqa: E501
    assert d.legal_notice.entries[0].value == u"Use the optical SCSI microchip, then you can generate the cross-platform pixel!"  # noqa: E501
    test_session.delete(d)
Пример #22
0
def post_subject_locale_determined_by_body(
        request, test_session, discussion,
        undefined_locale, fr_locale, en_locale):
    from assembl.models import Content, LangString
    p = Content(
        discussion=discussion,
        subject=LangString.create(u"testa"),
        body=LangString.create(u"Contenu clairement en français"))
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer post_subject_locale_determined_by_body"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #23
0
def fully_ambiguous_post(
        request, test_session, discussion, participant1_user,
        undefined_locale, fr_locale, en_locale):
    from assembl.models import Content, LangString
    p = Content(
        discussion=discussion,
        subject=LangString.create(u"testa"),
        body=LangString.create(u"testa"))
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer fully_ambiguous_post"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #24
0
def extract_comment(request, extract_post_1_to_subidea_1_1, discussion, admin_user, test_session):
    from assembl.models import ExtractComment, LangString
    p = ExtractComment(
        discussion=discussion, creator=admin_user,
        subject=LangString.create(u"comment of extract title"),
        body=LangString.create(u"comment of extract body"),
        message_id="*****@*****.**",
        parent_extract_id=extract_post_1_to_subidea_1_1.id)
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer post_subject_locale_determined_by_creator"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #25
0
def fully_ambiguous_post(
        request, test_session, discussion, participant1_user,
        undefined_locale, fr_locale, en_locale):
    from assembl.models import Content, LangString
    p = Content(
        discussion=discussion,
        subject=LangString.create(u"testa"),
        body=LangString.create(u"testa"))
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer fully_ambiguous_post"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #26
0
def post_subject_locale_determined_by_body(
        request, test_session, discussion,
        undefined_locale, fr_locale, en_locale):
    from assembl.models import Content, LangString
    p = Content(
        discussion=discussion,
        subject=LangString.create(u"testa"),
        body=LangString.create(u"Contenu clairement en français"))
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer post_subject_locale_determined_by_body"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #27
0
def synthesis_post_1(request, participant1_user, discussion, test_session, synthesis_1):
    from assembl.models import SynthesisPost, LangString
    p = SynthesisPost(
        discussion=discussion, creator=participant1_user,
        subject=LangString.create(u"a synthesis post"),
        body=LangString.create(u"post body (unused, it's a synthesis...)"),
        message_id="*****@*****.**",
        creation_date=datetime(year=2000, month=1, day=3),
        publishes_synthesis = synthesis_1)
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer synthesis_post_1"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #28
0
def subidea_1_2(request, discussion, subidea_1, test_session):
    """A subidea fixture with idealink to subidea_1 fixture"""
    from assembl.models import Idea, IdeaLink, LangString
    i = Idea(title=LangString.create(u"Even lower taxes", 'en'),
             discussion=discussion,
             description=LangString.create("The definition of the subidea_1_2", 'en'))
    test_session.add(i)
    l_1_12 = IdeaLink(source=subidea_1, target=i)
    test_session.add(l_1_12)
    test_session.flush()

    def fin():
        print("finalizer subidea_1_2")
        test_session.delete(l_1_12)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)
    return i
Пример #29
0
def subidea_1_2(request, discussion, subidea_1, test_session):
    """A subidea fixture with idealink to subidea_1 fixture"""
    from assembl.models import Idea, IdeaLink, LangString
    i = Idea(title=LangString.create(u"Even lower taxes", 'en'),
             discussion=discussion,
             description=LangString.create("The definition of the subidea_1_2", 'en'))
    test_session.add(i)
    l_1_12 = IdeaLink(source=subidea_1, target=i)
    test_session.add(l_1_12)
    test_session.flush()

    def fin():
        print "finalizer subidea_1_2"
        test_session.delete(l_1_12)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)
    return i
Пример #30
0
def post_body_locale_determined_by_creator(
        request, test_session, discussion, admin_user,
        user_language_preference_fr_cookie):
    from assembl.models import Post, LangString
    p = Post(
        discussion=discussion, creator=admin_user,
        subject=LangString.create(u"testa"),
        body=LangString.create(u"testa"),
        message_id="*****@*****.**")
    test_session.add(p)
    test_session.flush()

    def fin():
        print("finalizer post_subject_locale_determined_by_creator")
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #31
0
def idea_with_en_fr(request, discussion, en_locale,
                    fr_locale, test_session):
    """A top idea with english and french"""
    from assembl.models import Idea, LangString, LangStringEntry

    title = LangString.create(u'Title in english', 'en')
    title.add_entry(LangStringEntry(
                    locale=fr_locale,
                    value=u'Titre en français',
                    locale_confirmed=True))

    synthesis_title = LangString.create(u'What you need to know', 'en')
    synthesis_title.add_entry(LangStringEntry(
                              locale=fr_locale,
                              value=u'A retnir',
                              locale_confirmed=True))

    description = LangString.create(u'Idea description', 'en')
    description.add_entry(LangStringEntry(
                          locale=fr_locale,
                          value=u'Un Description',
                          locale_confirmed=True))

    idea = Idea(title=title,
                discussion=discussion,
                description=description,
                synthesis_title=synthesis_title)

    test_session.add(title)
    test_session.add(synthesis_title)
    test_session.add(description)
    test_session.add(idea)
    test_session.flush()

    def fin():
        print("finalizer idea_with_en_fr")
        test_session.delete(idea)
        test_session.delete(title)
        test_session.delete(synthesis_title)
        test_session.delete(description)
        test_session.flush()

    request.addfinalizer(fin)
    return idea
Пример #32
0
def idea_with_en_fr(request, discussion, en_locale,
                    fr_locale, test_session):
    """A top idea with english and french"""
    from assembl.models import Idea, LangString, LangStringEntry

    title = LangString.create(u'Title in english', 'en')
    title.add_entry(LangStringEntry(
                    locale=fr_locale,
                    value=u'Titre en français',
                    locale_confirmed=True))

    synthesis_title = LangString.create(u'What you need to know', 'en')
    synthesis_title.add_entry(LangStringEntry(
                              locale=fr_locale,
                              value=u'A retnir',
                              locale_confirmed=True))

    description = LangString.create(u'Idea description', 'en')
    description.add_entry(LangStringEntry(
                          locale=fr_locale,
                          value=u'Un Description',
                          locale_confirmed=True))

    idea = Idea(title=title,
                discussion=discussion,
                description=description,
                synthesis_title=synthesis_title)

    test_session.add(title)
    test_session.add(synthesis_title)
    test_session.add(description)
    test_session.add(idea)
    test_session.flush()

    def fin():
        print "finalizer idea_with_en_fr"
        test_session.delete(idea)
        test_session.delete(title)
        test_session.delete(synthesis_title)
        test_session.delete(description)
        test_session.flush()

    request.addfinalizer(fin)
    return idea
Пример #33
0
def post_body_locale_determined_by_creator(
        request, test_session, discussion, admin_user,
        user_language_preference_fr_cookie,
        undefined_locale, fr_locale, en_locale):
    from assembl.models import Post, LangString
    p = Post(
        discussion=discussion, creator=admin_user,
        subject=LangString.create(u"testa"),
        body=LangString.create(u"testa"),
        message_id="*****@*****.**")
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer post_subject_locale_determined_by_creator"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #34
0
def fix_posts_subjects(db, logger):
    from assembl.models import AssemblPost, Idea, LangString
    count = 0
    with transaction.manager:
        for idea in db.query(Idea).filter(Idea.message_view_override == 'messageColumns'):
            for post in idea.get_related_posts_query():
                locale = post.body.first_original().locale.code
                new_post_subject = LangString.create(u'', locale)
                if idea.title:
                    closest_subject_entry = idea.title.closest_entry(locale)
                    if closest_subject_entry:
                        new_post_subject = LangString.create(closest_subject_entry.value, locale)

                logger.info(u'Old subject: %s', post.subject)
                logger.info(u'New subject: %s', new_post_subject)
                post.subject = new_post_subject
                count += 1

    return count
Пример #35
0
def annnouncement_for_subidea_1_1(request, discussion, en_locale,
                        fr_locale, admin_user, subidea_1_1,
                        test_session):
    from assembl.models import LangString, LangStringEntry, IdeaAnnouncement
    title = LangString.create(u'Announce title in English', 'en')
    title.add_entry(LangStringEntry(
                    locale=fr_locale,
                    value=u"Titre d'announce en français",
                    locale_confirmed=True))

    body = LangString.create(u'Announce body in English', 'en')
    body.add_entry(LangStringEntry(
                   locale=fr_locale,
                   value=u"Corps d'announce en français",
                   locale_confirmed=True))
    quote = LangString.create(u'A quote in English', 'en')
    quote.add_entry(LangStringEntry(
                    locale=fr_locale,
                    value=u"Une quote en français",
                    locale_confirmed=True))
    announce = IdeaAnnouncement(creator=admin_user,
                                last_updated_by=admin_user,
                                title=title,
                                body=body,
                                discussion=discussion,
                                idea=subidea_1_1,
                                quote=quote)

    test_session.add(title)
    test_session.add(body)
    test_session.add(announce)
    test_session.flush()

    def fin():
        print("finalizer announcement_en_fr")
        test_session.delete(title)
        test_session.delete(body)
        test_session.delete(announce)
        test_session.flush()

    request.addfinalizer(fin)
    return announce
Пример #36
0
def annnouncement_for_subidea_1_1(request, discussion, en_locale, 
                        fr_locale, admin_user, subidea_1_1,
                        test_session):
    from assembl.models import LangString, LangStringEntry, IdeaAnnouncement
    title = LangString.create(u'Announce title in English', 'en')
    title.add_entry(LangStringEntry(
                    locale=fr_locale,
                    value=u"Titre d'announce en français",
                    locale_confirmed=True))

    body = LangString.create(u'Announce body in English', 'en')
    body.add_entry(LangStringEntry(
                   locale=fr_locale,
                   value=u"Corps d'announce en français",
                   locale_confirmed=True))
    quote = LangString.create(u'A quote in English', 'en')
    quote.add_entry(LangStringEntry(
                    locale=fr_locale,
                    value=u"Une quote en français",
                    locale_confirmed=True))
    announce = IdeaAnnouncement(creator=admin_user,
                                last_updated_by=admin_user,
                                title=title,
                                body=body,
                                discussion=discussion,
                                idea=subidea_1_1,
                                quote=quote)

    test_session.add(title)
    test_session.add(body)
    test_session.add(announce)
    test_session.flush()

    def fin():
        print "finalizer announcement_en_fr"
        test_session.delete(title)
        test_session.delete(body)
        test_session.delete(announce)
        test_session.flush()

    request.addfinalizer(fin)
    return announce
Пример #37
0
def resource(request, discussion, test_session):
    from assembl.models import Resource, LangString
    resource = Resource(discussion=discussion,
                        title=LangString.create(u"a resource", "en"),
                        text=LangString.create(u"Lorem ipsum dolor sit amet",
                                               "en"),
                        embed_code=u"<iframe ...>",
                        order=2.0)

    test_session.add(resource)
    test_session.flush()

    def fin():
        print("finalizer resource")
        test_session.delete(resource)
        test_session.flush()

    request.addfinalizer(fin)

    return resource
Пример #38
0
def root_post_1(request, participant1_user, discussion, test_session):
    """
    From participant1_user
    """
    from assembl.models import Post, LangString
    p = Post(
        discussion=discussion, creator=participant1_user,
        subject=LangString.create(u"a root post"),
        body=LangString.create(u"post body"), moderator=None,
        creation_date=datetime(year=2000, month=1, day=1),
        type="post", message_id="*****@*****.**")
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer root_post_1"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #39
0
def root_post_1(request, participant1_user, discussion, test_session):
    """
    From participant1_user
    """
    from assembl.models import Post, LangString
    p = Post(
        discussion=discussion, creator=participant1_user,
        subject=LangString.create(u"a root post"),
        body=LangString.create(u"post body"), moderator=None,
        creation_date=datetime(year=2000, month=1, day=1),
        type="post", message_id="*****@*****.**")
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer root_post_1"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #40
0
def test_get_ideas(discussion, test_app, test_session, test_webrequest):
    url = get_url(discussion, 'ideas')
    res = test_app.get(url)
    assert res.status_code == 200

    ideas = json.loads(res.body)
    num_ideas = len(ideas)

    idea = Idea(synthesis_title=LangString.create('This is a long test', 'en'),
                title=LangString.create('This is a test', 'en'),
                discussion=discussion)
    test_session.add(idea)
    test_session.flush()
    test_session.commit()
    url = get_url(discussion, 'ideas')
    res = test_app.get(url)
    assert res.status_code == 200

    ideas = json.loads(res.body)
    assert len(ideas) == num_ideas + 1
Пример #41
0
def subidea_1(request, discussion, root_idea, test_session, ):
    """An Idea fixture with a idealink to root idea fixture -
    root_idea
        |-> subidea_1"""

    from assembl.models import Idea, IdeaLink, LangString
    i = Idea(title=LangString.create(u"Favor economic growth", 'en'),
             discussion=discussion,
             description=LangString.create("Some definition of an idea", 'en'))
    test_session.add(i)
    l_r_1 = IdeaLink(source=root_idea, target=i)
    test_session.add(l_r_1)
    test_session.flush()

    def fin():
        print("finalizer subidea_1")
        test_session.delete(l_r_1)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)
    return i
Пример #42
0
def fix_posts_subjects(db, logger):
    from assembl.models import AssemblPost, Idea, LangString
    count = 0
    with transaction.manager:
        for idea in db.query(Idea).filter(
                Idea.message_view_override == 'messageColumns'):
            for post in idea.get_related_posts_query():
                locale = post.body.first_original().locale.code
                new_post_subject = LangString.create(u'', locale)
                if idea.title:
                    closest_subject_entry = idea.title.closest_entry(locale)
                    if closest_subject_entry:
                        new_post_subject = LangString.create(
                            closest_subject_entry.value, locale)

                logger.info(u'Old subject: %s', post.subject)
                logger.info(u'New subject: %s', new_post_subject)
                post.subject = new_post_subject
                count += 1

    return count
Пример #43
0
def synthesis_post_1(request, participant1_user, discussion, test_session,
                     synthesis_1):
    """A Syntehsis Post fixture"""

    from assembl.models import SynthesisPost, LangString
    p = SynthesisPost(
        discussion=discussion, creator=participant1_user,
        subject=LangString.create(u"a synthesis post"),
        body=LangString.create(u"post body (unused, it's a synthesis...)"),
        message_id="*****@*****.**",
        creation_date=datetime(year=2000, month=1, day=3),
        publishes_synthesis=synthesis_1)
    test_session.add(p)
    test_session.flush()

    def fin():
        print "finalizer synthesis_post_1"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #44
0
def subidea_1_2(request, discussion, subidea_1, test_session):
    """An Idea fixture with a idealink to subidea_1 fixture -
    root_idea
        |-> subidea_1
            |-> subidea_1_2"""

    from assembl.models import Idea, IdeaLink, LangString
    i = Idea(title=LangString.create(u"Increased reseource consumption", 'en'),
             discussion=discussion,
             description=LangString.create("Some definition of an idea", 'en'))
    test_session.add(i)
    l_1_12 = IdeaLink(source=subidea_1, target=i)
    test_session.add(l_1_12)
    test_session.flush()

    def fin():
        print("finalizer subidea_1_2")
        test_session.delete(l_1_12)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)
    return i
Пример #45
0
def reply_post_3(request, participant2_user, discussion,
                 root_post_1, test_session):
    """
    From participant2_user, in reply to reply_post_2
    """
    from assembl.models import Post, LangString
    p = Post(
        discussion=discussion, creator=participant2_user,
        subject=LangString.create(u"re2: root post"),
        body=LangString.create(u"post body"),
        type="post", message_id="*****@*****.**")
    test_session.add(p)
    test_session.flush()
    p.set_parent(root_post_1)
    test_session.flush()

    def fin():
        print "finalizer reply_post_3"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #46
0
def subidea_2(request, discussion, root_idea, test_session):
    """A subidea fixture with a idealink to root idea fixture::

        root_idea
            |-> subidea_1"""

    from assembl.models import Idea, IdeaLink, LangString
    i = Idea(title=LangString.create(u"An idea for another phase", 'en'),
             discussion=discussion,
             description=LangString.create("Some definition of an idea", 'en'))
    test_session.add(i)
    l_r_2 = IdeaLink(source=root_idea, target=i)
    test_session.add(l_r_2)
    test_session.flush()

    def fin():
        print("finalizer subidea_2")
        test_session.delete(l_r_2)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)
    return i
Пример #47
0
def reply_post_3(request, participant2_user, discussion,
                 root_post_1, test_session):
    """
    From participant2_user, in reply to reply_post_2
    """
    from assembl.models import Post, LangString
    p = Post(
        discussion=discussion, creator=participant2_user,
        subject=LangString.create(u"re2: root post"),
        body=LangString.create(u"post body"),
        type="post", message_id="*****@*****.**")
    test_session.add(p)
    test_session.flush()
    p.set_parent(root_post_1)
    test_session.flush()

    def fin():
        print "finalizer reply_post_3"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #48
0
def timeline_phase2_interface_v1(request, test_app, test_session, discussion,
                                 subidea_1, subidea_2):
    from assembl.models import DiscussionPhase, LangString
    phase1 = DiscussionPhase(identifier='survey',
                             discussion=discussion,
                             title=LangString.create('phase 1', 'en'),
                             description=LangString.create(
                                 'A first exploratory phase', 'en'),
                             root_idea=subidea_1,
                             start=datetime(2014, 12, 31, 9),
                             end=datetime(2015, 12, 31, 9),
                             interface_v1=True)
    test_session.add(phase1)
    phase2 = DiscussionPhase(identifier='thread',
                             discussion=discussion,
                             title=LangString.create('phase 2', 'en'),
                             description=LangString.create(
                                 'A second divergent phase', 'en'),
                             root_idea=subidea_2,
                             start=datetime(2015, 12, 31, 9, 1),
                             end=datetime(2049, 12, 31, 9),
                             previous_event=phase1,
                             order=2.0,
                             interface_v1=True)
    test_session.add(phase2)
    test_session.flush()

    def fin():
        print "finalizer timeline"
        phase2.previous_event = None
        phase2.previous_event_id = None
        phase2.delete()
        phase1.delete()

        test_session.flush()

    request.addfinalizer(fin)
    return phase2
Пример #49
0
def reply_post_1(request, participant2_user, discussion,
                 root_post_1, test_session):
    """
    From participant2_user, in reply to root_post_1
    """
    from assembl.models import Post, LangString
    p = Post(
        discussion=discussion, creator=participant2_user,
        subject=LangString.create(u"re1: root post"),
        body=LangString.create(u"post body"),
        creation_date=datetime(year=2000, month=1, day=4),
        type="post", message_id="*****@*****.**")
    test_session.add(p)
    test_session.flush()
    p.set_parent(root_post_1)
    test_session.flush()

    def fin():
        print("finalizer reply_post_1")
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #50
0
def test_add_section(admin_user, discussion, test_session):
    from assembl.models.section import Section, SectionTypesEnum
    from assembl.models import LangString

    section = Section(discussion_id=discussion.id,
                      title=LangString.create(u"My homepage section"),
                      url=u'http://www.example.com',
                      section_type=SectionTypesEnum.HOMEPAGE.value,
                      order=0.0)

    assert section.title.entries[0].value == u'My homepage section'
    assert section.url == u'http://www.example.com'
    assert section.order == 0.0
    assert section.section_type == SectionTypesEnum.HOMEPAGE.value
Пример #51
0
def reply_deleted_post_4(request, participant2_user, discussion,
                         reply_post_1, test_session):
    """
    From participant2_user, in reply to reply_post_1
    """
    from assembl.models import Post, LangString, PublicationStates
    p = Post(
        discussion=discussion, creator=participant2_user,
        subject=LangString.create(u"re2: root post"),
        body=LangString.create(u"post body"),
        publication_state=PublicationStates.DELETED_BY_ADMIN,
        type="post", message_id="*****@*****.**")
    test_session.add(p)
    test_session.flush()
    p.set_parent(reply_post_1)
    test_session.flush()

    def fin():
        print "finalizer reply_deleted_post_4"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #52
0
def subidea_1_2_1(request, discussion, subidea_1_2, test_session):
    """An Idea fixture with a idealink to subidea_1 fixture -
    root_idea
        |-> subidea_1
            |-> subidea_1_2
                |-> subidea_1_2_1"""

    from assembl.models import Idea, IdeaLink, LangString
    i = Idea(title=LangString.create(u"Bad for the environment", 'en'),
             discussion=discussion,
             description=LangString.create("Some definition of an idea", 'en'))
    test_session.add(i)
    l_12_121 = IdeaLink(source=subidea_1_2, target=i)
    test_session.add(l_12_121)
    test_session.flush()

    def fin():
        print("finalizer subidea_1_2_1")
        test_session.delete(l_12_121)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)
    return i
Пример #53
0
def reply_post_1(request, participant2_user, discussion,
                 root_post_1, test_session):
    """
    From participant2_user, in reply to root_post_1
    """
    from assembl.models import Post, LangString
    p = Post(
        discussion=discussion, creator=participant2_user,
        subject=LangString.create(u"re1: root post"),
        body=LangString.create(u"post body with some text so we can test harvesting features. I'm writing a very topical comment with an unrelated source, hoping it would make people angry and make them write answers. I have read in '17O Solid-State NMR Spectroscopy of Functional Oxides for Energy Conversion' thesis by Halat, D. M. (2018) that variable-temperature spectra indicate the onset of oxide-ion motion involving the interstitials at 130 °C, which is linked to an orthorhombic−tetragonal phase transition. For the V-doped phases, an oxide-ion conduction mechanism is observed that involves oxygen exchange between the Bi-O sublattice and rapidly rotating VO4 tetrahedral units. The more poorly conducting P-doped phase exhibits only vacancy conduction with no evidence of sublattice exchange, a result ascribed to the differing propensities of the dopants to undergo variable oxygen coordination. So I think it would be a very bad idea to allow hot beverages in coworking spaces. But it looks like people don't really care about scientific evidence around here."),
        creation_date=datetime(year=2000, month=1, day=4),
        type="post", message_id="*****@*****.**")
    test_session.add(p)
    test_session.flush()
    p.set_parent(root_post_1)
    test_session.flush()

    def fin():
        print "finalizer reply_post_1"
        test_session.delete(p)
        test_session.flush()
    request.addfinalizer(fin)
    return p
Пример #54
0
def resource_with_image_and_doc(request, discussion, moderator_user,
                                simple_file, simple_file2, test_session):
    from assembl.models import Resource, LangString
    from assembl.models.attachment import ResourceAttachment
    resource = Resource(discussion=discussion,
                        title=LangString.create(u"another resource", "en"),
                        text=LangString.create(u"Lorem ipsum dolor sit amet",
                                               "en"),
                        embed_code=u"",
                        order=1.0)
    resource_image = ResourceAttachment(discussion=discussion,
                                        document=simple_file,
                                        resource=resource,
                                        title=u"Resource image",
                                        creator=moderator_user,
                                        attachmentPurpose='IMAGE')

    resource_doc = ResourceAttachment(discussion=discussion,
                                      document=simple_file2,
                                      resource=resource,
                                      title=u"Resource document",
                                      creator=moderator_user,
                                      attachmentPurpose='DOCUMENT')

    test_session.add(resource)
    test_session.flush()

    def fin():
        print("finalizer resource with image and doc")
        test_session.delete(resource_doc)
        test_session.delete(resource_image)
        test_session.delete(resource)
        test_session.flush()

    request.addfinalizer(fin)

    return resource
Пример #55
0
def subidea_1_1_1_1(request, discussion, subidea_1_1_1, test_session):
    """An Idea fixture with a idealink to subidea_1_1_1 fixture -
    root_idea
        |-> subidea_1
            |-> subidea_1_1
                |-> subidea_1_1_1
                    |->subidea_1_1_1_1"""

    from assembl.models import Idea, IdeaLink, LangString
    i = Idea(title=LangString.create(u"Austerity yields contraction", 'en'),
             discussion=discussion,
             description=LangString.create("Some definition of an idea", 'en'))
    test_session.add(i)
    l_111_1111 = IdeaLink(source=subidea_1_1_1, target=i)
    test_session.add(l_111_1111)
    test_session.flush()

    def fin():
        print "finalizer subidea_1_1_1_1"
        test_session.delete(l_111_1111)
        test_session.delete(i)
        test_session.flush()
    request.addfinalizer(fin)
    return i
Пример #56
0
def participant_published_post_with_parent_post_for_bright_mirror(
        request, test_session, discussion, admin_user, participant1_user,
        bright_mirror, post_published_for_bright_mirror):
    from assembl.models import Post, Idea, LangString, IdeaRelatedPostLink, PublicationStates
    from graphene.relay import Node
    idea_id = bright_mirror
    raw_id = int(Node.from_global_id(idea_id)[1])
    idea = Idea.get(raw_id)
    parent_post_id = post_published_for_bright_mirror.id
    post = Post(
        discussion=discussion, creator=participant1_user,
        subject=LangString.create(u"Published by participant"),
        body=LangString.create(u"A simple published fiction by participant"),
        type='post', publication_state=PublicationStates.PUBLISHED,
        message_id="*****@*****.**",
        creation_date=datetime.utcnow(),
        parent_id=parent_post_id
        )

    idc = IdeaRelatedPostLink(
        idea=idea,
        creator=admin_user,
        content=post)

    test_session.add(post)
    test_session.add(idc)
    test_session.flush()

    def fin():
        print "finalizer participant_published_post_with_parent_post_for_bright_mirror"
        test_session.delete(post)
        test_session.delete(idc)
        test_session.flush()

    request.addfinalizer(fin)
    return post
Пример #57
0
def text_field(request, test_session, discussion):
    from assembl.models import LangString, TextField
    saobj = TextField(discussion=discussion,
                      order=1.0,
                      title=LangString.create('My text field', 'en'),
                      required=True)
    test_session.add(saobj)
    test_session.flush()

    def fin():
        print("Finalizer text_field")
        test_session.delete(saobj)
        test_session.flush()

    request.addfinalizer(fin)
    return saobj
Пример #58
0
def create_proposal_en_fr_x(request, session, discussion, creator_id,
                            idea_id, num):
    from assembl.models import (
        PropositionPost,
        IdeaRelatedPostLink,
        Locale,
        LangString,
        LangStringEntry)

    en_locale = Locale.get_or_create('en')
    fr_locale = Locale.get_or_create('fr')
    mt_locale = Locale.create_mt_locale(en_locale, fr_locale, db=session)

    body = LangString.create(u"English Proposition %d" % num, 'en')
    body.add_entry(LangStringEntry(
                   locale=mt_locale,
                   value=u'French Proposition %d' % num,
                   locale_confirmed=True))

    post = PropositionPost(
        discussion=discussion,
        creator_id=creator_id,
        subject=None,
        body=body,
        body_mime_type=u'text/html',
        message_id="*****@*****.**" % num
    )

    icl = IdeaRelatedPostLink(
        idea_id=idea_id,
        content=post,
        discussion=discussion,
        creator_id=creator_id
    )

    session.add(post)
    session.add(icl)
    session.flush()

    def fin():
        session.delete(icl)
        session.delete(post)
        session.delete(mt_locale)
        session.flush()

    request.addfinalizer(fin)
    return post