def test_create_withuser(self):
        """Test access request creation with user."""
        from zenodo_accessrequests.models import AccessRequest, \
            RequestStatus
        from zenodo_accessrequests.signals import \
            request_created, request_confirmed

        with request_created.connected_to(self.get_receiver('created')):
            with request_confirmed.connected_to(
                 self.get_receiver('confirmed')):
                r = AccessRequest.create(
                    recid=1,
                    receiver=self.receiver,
                    sender_full_name="Another Name",
                    sender_email="*****@*****.**",
                    sender=self.sender,
                    justification="Bla bla bla",
                )

                self.assertEqual(r.status, RequestStatus.PENDING)
                self.assertEqual(r.sender_user_id, self.sender.get_id())
                self.assertIsNotNone(r.created)
                self.assertIsNotNone(r.modified)
                self.assertEqual(r.message, u'')
                self.assertEqual(r.sender_full_name, u'Another Name')
                self.assertEqual(r.sender_email, u'*****@*****.**')

                self.assertIsNone(self.called['created'])
                self.assertIsNotNone(self.called['confirmed'])
def test_create_nouser(app, db, users, record_example):
    """Test access request creation without user."""
    mock_request_created = Mock()
    mock_request_confirmed = Mock()
    pid_value, record = record_example

    with app.test_request_context():
        with request_created.connected_to(mock_request_created):
            with request_confirmed.connected_to(mock_request_confirmed):
                datastore = current_app.extensions['security'].datastore
                receiver = datastore.get_user(users['receiver']['id'])

                r = AccessRequest.create(
                    recid=pid_value,
                    receiver=receiver,
                    sender_full_name="John Smith",
                    sender_email="*****@*****.**",
                    justification="Bla bla bla",
                )

                assert r.status == RequestStatus.EMAIL_VALIDATION
                assert r.sender_user_id is None
                assert r.created is not None
                assert r.modified is not None
                assert r.message == u''

                assert mock_request_created.called
                assert not mock_request_confirmed.called
    def test_create_nouser(self):
        """Test access request creation without user."""
        from zenodo_accessrequests.models import AccessRequest, \
            RequestStatus
        from zenodo_accessrequests.signals import \
            request_created, request_confirmed

        with request_created.connected_to(self.get_receiver('created')):
            with request_confirmed.connected_to(
                 self.get_receiver('confirmed')):

                r = AccessRequest.create(
                    recid=1,
                    receiver=self.receiver,
                    sender_full_name="John Smith",
                    sender_email="*****@*****.**",
                    justification="Bla bla bla",
                )

                self.assertEqual(r.status, RequestStatus.EMAIL_VALIDATION)
                self.assertIsNone(r.sender_user_id)
                self.assertIsNotNone(r.created)
                self.assertIsNotNone(r.modified)
                self.assertEqual(r.message, u'')

                self.assertIsNotNone(self.called['created'])
                self.assertIsNone(self.called['confirmed'])
def test_create_withuser(app, db, users, record_example):
    """Test access request creation with user."""
    mock_request_created = Mock()
    mock_request_confirmed = Mock()
    pid_value, record = record_example

    with app.test_request_context():
        with request_created.connected_to(mock_request_created):
            with request_confirmed.connected_to(mock_request_confirmed):
                datastore = current_app.extensions['security'].datastore
                receiver = datastore.get_user(users['receiver']['id'])
                sender = datastore.get_user(users['sender']['id'])

                r = AccessRequest.create(
                    recid=pid_value,
                    receiver=receiver,
                    sender_full_name="Another Name",
                    sender_email="*****@*****.**",
                    sender=sender,
                    justification="Bla bla bla",
                )

                assert r.status == RequestStatus.PENDING
                assert r.sender_user_id == sender.id
                assert r.created is not None
                assert r.modified is not None
                assert r.message == u''
                assert r.sender_full_name == u'Another Name'
                assert r.sender_email == u'*****@*****.**'

                assert not mock_request_created.called
                assert mock_request_confirmed.called
Exemple #5
0
def test_create_withuser(app, db, users, record_example):
    """Test access request creation with user."""
    mock_request_created = Mock()
    mock_request_confirmed = Mock()
    pid_value, record = record_example

    with app.test_request_context():
        with request_created.connected_to(mock_request_created):
            with request_confirmed.connected_to(mock_request_confirmed):
                datastore = current_app.extensions['security'].datastore
                receiver = datastore.get_user(users['receiver']['id'])
                sender = datastore.get_user(users['sender']['id'])

                r = AccessRequest.create(
                    recid=pid_value,
                    receiver=receiver,
                    sender_full_name="Another Name",
                    sender_email="*****@*****.**",
                    sender=sender,
                    justification="Bla bla bla",
                )

                assert r.status == RequestStatus.PENDING
                assert r.sender_user_id == sender.id
                assert r.created is not None
                assert r.modified is not None
                assert r.message == u''
                assert r.sender_full_name == u'Another Name'
                assert r.sender_email == u'*****@*****.**'

                assert not mock_request_created.called
                assert mock_request_confirmed.called
Exemple #6
0
def test_create_nouser(app, db, users, record_example):
    """Test access request creation without user."""
    mock_request_created = Mock()
    mock_request_confirmed = Mock()
    pid_value, record = record_example

    with app.test_request_context():
        with request_created.connected_to(mock_request_created):
            with request_confirmed.connected_to(mock_request_confirmed):
                datastore = current_app.extensions['security'].datastore
                receiver = datastore.get_user(users['receiver']['id'])

                r = AccessRequest.create(
                    recid=pid_value,
                    receiver=receiver,
                    sender_full_name="John Smith",
                    sender_email="*****@*****.**",
                    justification="Bla bla bla",
                )

                assert r.status == RequestStatus.EMAIL_VALIDATION
                assert r.sender_user_id is None
                assert r.created is not None
                assert r.modified is not None
                assert r.message == u''

                assert mock_request_created.called
                assert not mock_request_confirmed.called
    def test_create_withuser(self):
        """Test access request creation with user."""
        from zenodo_accessrequests.models import AccessRequest, \
            RequestStatus
        from zenodo_accessrequests.signals import \
            request_created, request_confirmed

        with request_created.connected_to(self.get_receiver('created')):
            with request_confirmed.connected_to(
                    self.get_receiver('confirmed')):
                r = AccessRequest.create(
                    recid=1,
                    receiver=self.receiver,
                    sender_full_name="Another Name",
                    sender_email="*****@*****.**",
                    sender=self.sender,
                    justification="Bla bla bla",
                )

                self.assertEqual(r.status, RequestStatus.PENDING)
                self.assertEqual(r.sender_user_id, self.sender.get_id())
                self.assertIsNotNone(r.created)
                self.assertIsNotNone(r.modified)
                self.assertEqual(r.message, u'')
                self.assertEqual(r.sender_full_name, u'Another Name')
                self.assertEqual(r.sender_email, u'*****@*****.**')

                self.assertIsNone(self.called['created'])
                self.assertIsNotNone(self.called['confirmed'])
    def test_create_nouser(self):
        """Test access request creation without user."""
        from zenodo_accessrequests.models import AccessRequest, \
            RequestStatus
        from zenodo_accessrequests.signals import \
            request_created, request_confirmed

        with request_created.connected_to(self.get_receiver('created')):
            with request_confirmed.connected_to(
                    self.get_receiver('confirmed')):

                r = AccessRequest.create(
                    recid=1,
                    receiver=self.receiver,
                    sender_full_name="John Smith",
                    sender_email="*****@*****.**",
                    justification="Bla bla bla",
                )

                self.assertEqual(r.status, RequestStatus.EMAIL_VALIDATION)
                self.assertIsNone(r.sender_user_id)
                self.assertIsNotNone(r.created)
                self.assertIsNotNone(r.modified)
                self.assertEqual(r.message, u'')

                self.assertIsNotNone(self.called['created'])
                self.assertIsNone(self.called['confirmed'])
    def test_confirm_email(self):
        """Test confirm email signal and state."""
        from zenodo_accessrequests.models import RequestStatus

        from zenodo.modules.accessrequests.signals import \
            request_confirmed

        with request_confirmed.connected_to(self.get_receiver('confirmed')):
            r = self.get_request(confirmed=False)
            r.confirm_email()
            self.assertEqual(r.status, RequestStatus.PENDING)
            self.assertEqual(r, self.called['confirmed']['args'][0])
def test_confirm_email(app, db, users, record_example,
                       access_request_not_confirmed):
    """Test confirm email signal and state."""
    mock_request_confirmed = Mock()
    pid_value, record = record_example

    with app.test_request_context():
        with request_confirmed.connected_to(mock_request_confirmed):

            r = AccessRequest.query.filter_by(
                id=access_request_not_confirmed).first()
            r.confirm_email()
            assert r.status == RequestStatus.PENDING
            assert mock_request_confirmed.call_args[0][0] == r
Exemple #11
0
def test_confirm_email(app, db, users, record_example,
                       access_request_not_confirmed):
    """Test confirm email signal and state."""
    mock_request_confirmed = Mock()
    pid_value, record = record_example

    with app.test_request_context():
        with request_confirmed.connected_to(mock_request_confirmed):

            r = AccessRequest.query.filter_by(
                id=access_request_not_confirmed).first()
            r.confirm_email()
            assert r.status == RequestStatus.PENDING
            assert mock_request_confirmed.call_args[0][0] == r
    def test_confirm_email(self):
        """Test confirm email signal and state."""
        from zenodo_accessrequests.models import RequestStatus

        from zenodo.modules.accessrequests.signals import \
            request_confirmed

        with request_confirmed.connected_to(self.get_receiver('confirmed')):
            r = self.get_request(confirmed=False)
            r.confirm_email()
            self.assertEqual(r.status, RequestStatus.PENDING)
            self.assertEqual(
                r,
                self.called['confirmed']['args'][0]
            )