Exemple #1
0
def session_with_requests(session, fake_new_account_request):
    session.add(StoredNewAccountRequest.from_request(fake_new_account_request, 'reason'))
    session.add(StoredNewAccountRequest.from_request(
        fake_new_account_request._replace(user_name='other'),
        'reason',
    ))
    session.commit()
    assert len(session.query(StoredNewAccountRequest).all()) == 2
    return session
Exemple #2
0
def session_with_requests(session, fake_new_account_request):
    session.add(StoredNewAccountRequest.from_request(fake_new_account_request, 'reason'))
    session.add(StoredNewAccountRequest.from_request(
        fake_new_account_request._replace(user_name='other'),
        'reason',
    ))
    session.commit()
    assert len(session.query(StoredNewAccountRequest).all()) == 2
    return session
Exemple #3
0
def test_get_pending_requests(session_with_requests, tasks, fake_new_account_request):
    request = fake_new_account_request
    pending_requests = tasks.get_pending_requests()
    assert set(request.to_request() for request in pending_requests) == {
        StoredNewAccountRequest.from_request(request, 'reason').to_request(),
        StoredNewAccountRequest.from_request(
            request._replace(user_name='other'),
            'reason',
        ).to_request(),
    }
Exemple #4
0
def test_get_pending_requests(session_with_requests, tasks, fake_new_account_request):
    request = fake_new_account_request
    pending_requests = tasks.get_pending_requests()
    assert {request.to_request() for request in pending_requests} == {
        StoredNewAccountRequest.from_request(request, 'reason').to_request(),
        StoredNewAccountRequest.from_request(
            request._replace(user_name='other'),
            'reason',
        ).to_request(),
    }
Exemple #5
0
 def test_has_pending(self, session, fake_new_account_request, attrs):
     fake_new_account_request = fake_new_account_request._replace(**attrs)
     session.add(
         StoredNewAccountRequest.from_request(fake_new_account_request,
                                              'reason'))
     session.commit()
     assert user_has_request_pending(session, fake_new_account_request)
Exemple #6
0
 def test_not_has_pending_zero_group(self, session, fake_new_account_request):
     """callink_oid=0 can create infinite accounts."""
     fake_new_account_request = fake_new_account_request._replace(
         is_group=True,
         callink_oid=0,
         calnet_uid=None,
     )
     session.add(StoredNewAccountRequest.from_request(fake_new_account_request, 'reason'))
     session.commit()
     assert not user_has_request_pending(session, fake_new_account_request)
Exemple #7
0
 def test_not_has_pending_zero_group(self, session, fake_new_account_request):
     """callink_oid=0 can create infinite accounts."""
     fake_new_account_request = fake_new_account_request._replace(
         is_group=True,
         callink_oid=0,
         calnet_uid=None,
     )
     session.add(StoredNewAccountRequest.from_request(fake_new_account_request, 'reason'))
     session.commit()
     assert not user_has_request_pending(session, fake_new_account_request)
Exemple #8
0
def test_approve_request(celery_app, fake_new_account_request, session_with_requests, tasks):
    tasks.approve_request(fake_new_account_request.user_name)
    assert len(session_with_requests.query(StoredNewAccountRequest).all()) == 1

    # we want to make sure we go through the same conversion process:
    # live -> stored -> live -> dict
    request = StoredNewAccountRequest.from_request(fake_new_account_request, 'reason').to_request()
    tasks.create_account.delay.assert_called_once_with(request)
    assert celery_app._sent_messages == [
        {'type': 'ocflib.account_approved', 'request': request.to_dict()}
    ]
Exemple #9
0
def test_approve_request(celery_app, fake_new_account_request, session_with_requests, tasks):
    tasks.approve_request(fake_new_account_request.user_name)
    assert len(session_with_requests.query(StoredNewAccountRequest).all()) == 1

    # we want to make sure we go through the same conversion process:
    # live -> stored -> live -> dict
    request = StoredNewAccountRequest.from_request(fake_new_account_request, 'reason').to_request()
    tasks.create_account.delay.assert_called_once_with(request)
    assert celery_app._sent_messages == [
        {'type': 'ocflib.account_approved', 'request': request.to_dict()}
    ]
Exemple #10
0
def test_reject_request(send_rejected_mail, celery_app, fake_new_account_request, session_with_requests, tasks):
    tasks.reject_request(fake_new_account_request.user_name)
    assert len(session_with_requests.query(StoredNewAccountRequest).all()) == 1

    # we want to make sure we go through the same conversion process:
    # live -> stored -> live -> dict
    request = StoredNewAccountRequest.from_request(fake_new_account_request, 'reason').to_request()
    assert celery_app._sent_messages == [
        {'type': 'ocflib.account_rejected', 'request': request.to_dict()}
    ]

    # TODO: assert real reason
    send_rejected_mail.assert_called_once_with(request, mock.ANY)
Exemple #11
0
def test_reject_request(send_rejected_mail, celery_app, fake_new_account_request, session_with_requests, tasks):
    tasks.reject_request(fake_new_account_request.user_name)
    assert len(session_with_requests.query(StoredNewAccountRequest).all()) == 1

    # we want to make sure we go through the same conversion process:
    # live -> stored -> live -> dict
    request = StoredNewAccountRequest.from_request(fake_new_account_request, 'reason').to_request()
    assert celery_app._sent_messages == [
        {'type': 'ocflib.account_rejected', 'request': request.to_dict()}
    ]

    # TODO: assert real reason
    send_rejected_mail.assert_called_once_with(request, mock.ANY)
Exemple #12
0
 def test_str(self, fake_new_account_request):
     assert (str(
         StoredNewAccountRequest.from_request(fake_new_account_request,
                                              'reason')) ==
             'someuser (individual: "Some User"), because: reason')
Exemple #13
0
 def test_pending(self, session, fake_new_account_request):
     session.add(
         StoredNewAccountRequest.from_request(fake_new_account_request,
                                              'reason'))
     session.commit()
     assert username_pending(session, fake_new_account_request)
Exemple #14
0
 def test_has_pending(self, session, fake_new_account_request, attrs):
     fake_new_account_request = fake_new_account_request._replace(**attrs)
     session.add(StoredNewAccountRequest.from_request(fake_new_account_request, 'reason'))
     session.commit()
     assert user_has_request_pending(session, fake_new_account_request)
Exemple #15
0
 def test_str(self, fake_new_account_request):
     assert (
         str(StoredNewAccountRequest.from_request(fake_new_account_request, 'reason')) ==
         'someuser (individual: "Some User"), because: reason'
     )
Exemple #16
0
 def test_pending(self, session, fake_new_account_request):
     session.add(StoredNewAccountRequest.from_request(fake_new_account_request, 'reason'))
     session.commit()
     assert username_pending(session, fake_new_account_request)