Exemple #1
0
def test_definition(mocker):
    from fossir.modules.events.agreements import util
    mocker.patch.object(util,
                        'get_agreement_definitions',
                        return_value={'foobar': 'test'})
    assert Agreement(type='foobar').definition == 'test'
    assert Agreement(type='barfoo').definition is None
Exemple #2
0
def test_reject(reason, on_behalf, expected_state):
    ip = '127.0.0.1'
    agreement = Agreement()
    agreement.reject(from_ip=ip, reason=reason, on_behalf=on_behalf)
    assert agreement.state == expected_state
    assert agreement.signed_from_ip == ip
    assert agreement.reason == reason
    assert agreement.signed_dt == now_utc()
    agreement.definition.handle_rejected.assert_called_with(agreement)
Exemple #3
0
def test_reset():
    agreement = Agreement()
    agreement.reset()
    assert agreement.state == AgreementState.pending
    assert agreement.attachment is None
    assert agreement.attachment_filename is None
    assert agreement.data is None
    assert agreement.reason is None
    assert agreement.signed_dt is None
    assert agreement.signed_from_ip is None
Exemple #4
0
 def _create_agreement(state):
     agreement = Agreement(uuid=str(uuid4()),
                           event=dummy_event,
                           type='dummy',
                           person_email=dummy_person.email,
                           person_name=dummy_person.name,
                           state=state,
                           identifier=dummy_person.identifier)
     db.session.add(agreement)
     db.session.flush()
     return agreement
 def _process_args(self):
     RHAgreementManagerDetails._process_args(self)
     if 'id' in request.view_args:
         self.agreement = Agreement.get_one(request.view_args['id'])
         if self.event != self.agreement.event:
             raise NotFound
         if not self.agreement.pending:
             raise NoReportError(_("The agreement is already signed"))
     else:
         self.agreement = None
         identifier = request.args['identifier']
         try:
             self.person = self.definition.get_people(self.event)[identifier]
         except KeyError:
             raise NotFound
Exemple #6
0
def test_create_from_data(dummy_event, dummy_person, dummy_user,
                          person_with_user):
    type_ = 'dummy'
    dummy_person.user = dummy_user if person_with_user else None
    agreement = Agreement.create_from_data(event=dummy_event,
                                           type_=type_,
                                           person=dummy_person)
    assert agreement.event == dummy_event
    assert agreement.type == type_
    assert agreement.state == AgreementState.pending
    assert agreement.uuid
    assert agreement.identifier == dummy_person.identifier
    assert agreement.person_email == dummy_person.email
    assert agreement.person_name == dummy_person.name
    assert agreement.user == dummy_person.user
    assert agreement.data == dummy_person.data
 def _process(self):
     agreement = self.agreement
     form = AgreementAnswerSubmissionForm()
     if form.validate_on_submit():
         if agreement is None:
             agreement = Agreement.create_from_data(event=self.event, type_=self.definition.name,
                                                    person=self.person)
             db.session.add(agreement)
             db.session.flush()
         if form.answer.data:
             agreement.accept(from_ip=request.remote_addr, on_behalf=True)
             agreement.attachment_filename = form.document.data.filename
             agreement.attachment = form.document.data.read()
         else:
             agreement.reject(from_ip=request.remote_addr, on_behalf=True)
         flash(_("Agreement answered on behalf of {0}".format(agreement.person_name)), 'success')
         return jsonify(success=True)
     return WPJinjaMixin.render_template('events/agreements/dialogs/agreement_submit_answer_form.html', form=form,
                                         event=self.event, agreement=agreement)
def send_new_agreements(event, name, people, email_body, cc_addresses,
                        from_address):
    """Creates and send agreements for a list of people on a given event.

    :param event: The `Event` associated with the agreement
    :param name: The agreement type matcing a :class:`AgreementDefinition` name
    :param people: The list of people for whom agreements will be created
    :param email_body: The body of the email
    :param cc_addresses: Email addresses to send CCs to
    :param from_address: Email address of the sender
    """
    agreements = []
    for person in people.itervalues():
        agreement = Agreement.create_from_data(event=event,
                                               type_=name,
                                               person=person)
        db.session.add(agreement)
        agreements.append(agreement)
    db.session.flush()
    for agreement in agreements:
        notify_agreement_new(agreement, email_body, cc_addresses, from_address)
    return agreements
Exemple #9
0
def test_rejected(dummy_agreement, state, expected):
    dummy_agreement.state = state
    assert dummy_agreement.rejected == expected
    assert Agreement.find_one(rejected=expected) == dummy_agreement
Exemple #10
0
def test_render():
    agreement = Agreement()
    agreement.render(None)
    agreement.definition.render_form.assert_called_with(agreement, None)
 def _process_args(self):
     RHAgreementManagerDetails._process_args(self)
     self.agreement = Agreement.get_one(request.view_args['id'])
Exemple #12
0
def test_belongs_to():
    agreement = Agreement(identifier='foo')
    assert agreement.belongs_to(MagicMock(identifier='foo'))
    assert not agreement.belongs_to(MagicMock(identifier='bar'))
Exemple #13
0
def _merge_users(target, source, **kwargs):
    Agreement.find(user_id=source.id).update({Agreement.user_id: target.id})
Exemple #14
0
def test_locator():
    id_ = 1337
    event_id = 9000
    agreement = Agreement(id=id_, event_id=event_id)
    assert agreement.locator == {'id': id_, 'confId': event_id}
Exemple #15
0
def test_is_orphan(dummy_event):
    agreement = Agreement(event=dummy_event)
    agreement.is_orphan()
    agreement.definition.is_agreement_orphan(agreement.event, agreement)
Exemple #16
0
def test_is_orphan_no_definition(monkeypatch):
    monkeypatch.setattr(Agreement, 'definition', property(lambda s: None))
    agreement = Agreement()
    with pytest.raises(ServiceUnavailable):
        agreement.is_orphan()
Exemple #17
0
def test_accepted(dummy_agreement, state, expected):
    dummy_agreement.state = state
    assert dummy_agreement.accepted == expected
    assert Agreement.find_one(accepted=expected) == dummy_agreement
Exemple #18
0
def test_pending(dummy_agreement, state, expected):
    dummy_agreement.state = state
    filter_ = Agreement.pending if expected else ~Agreement.pending
    assert dummy_agreement.pending == expected
    assert Agreement.find_one(filter_) == dummy_agreement
    assert not Agreement.find_first(~filter_)
 def _process_args(self):
     RHDisplayEventBase._process_args(self)
     self.agreement = Agreement.get_one(request.view_args['id'])
     if self.agreement.is_orphan():
         raise NotFound('The agreement is not active anymore')
Exemple #20
0
def test_signed_on_behalf(dummy_agreement, state, expected):
    dummy_agreement.state = state
    assert dummy_agreement.signed_on_behalf == expected
    assert Agreement.find_one(signed_on_behalf=expected) == dummy_agreement