def test_large_donation_emails(self, ultsys_user_function,
                                   create_ultsys_user_function,
                                   update_ultsys_user_function,
                                   mock_caging_function):  # pylint: disable=unused-argument
        """Test large donation adds entry to GiftThankYouLetter table.

        :param ultsys_user_function: Argument for mocked function.
        :param ultsys_user_update_function: Argument for mocked function.
        :param ultsys_user_create_function: Argument for mocked function.
        :return:
        """
        with self.app.app_context():
            # Create agent ( Braintree ) for the online donation.

            agent_dict = get_agent_dict()
            agent_model = from_json(AgentSchema(), agent_dict, create=True)
            database.session.add(agent_model.data)

            # Flush to get the ID and set the database.
            database.session.flush()
            database.session.commit()

            # Call the function to be tested.
            payload = get_donate_dict({
                'user': get_new_donor_dict(),
                'recurring_subscription': False,
                'transaction': {
                    'gross_gift_amount': '110.00'
                }
            })
            post_donation(payload)

            gift_thank_you_letter = GiftThankYouLetterModel.query.filter_by(
                gift_id=1).one_or_none()
            self.assertEqual(gift_thank_you_letter.gift_id, 1)

            transaction = TransactionModel.query.filter_by(
                gift_id=1).one_or_none()
            self.assertIsNotNone(transaction)
            self.assertIsInstance(transaction.receipt_sent_in_utc, datetime)
Beispiel #2
0
    def test_donation_new_donor(self, ultsys_user_function,
                                create_ultsys_user_function,
                                update_ultsys_user_function,
                                mock_caging_function):  # pylint: disable=unused-argument
        """Test Braintree sale for a new donor.

        :param ultsys_user_function: Argument for mocked function.
        :param ultsys_user_update_function: Argument for mocked function.
        :param ultsys_user_create_function: Argument for mocked function.
        :return:
        """
        with self.app.app_context():
            # Create agent ( Braintree ) for the online donation.

            agent_dict = get_agent_dict()
            agent_model = from_json(AgentSchema(), agent_dict, create=True)
            database.session.add(agent_model.data)

            # Flush to get the ID and set the database.
            database.session.flush()
            database.session.commit()
            agent_id = agent_model.data.id

            # Call the function to be tested.
            payload = get_donate_dict({
                'user': get_new_donor_dict(),
                'recurring_subscription': False
            })
            result = post_donation(payload)

            self.assertEqual(result['job_id'], 'redis-queue-job-id')

            # The function should create one transaction, a gift, and a user.
            transaction = TransactionModel.query.filter_by(id=1).one_or_none()
            gift = GiftModel.query.filter_by(id=1).one_or_none()

            self.assertEqual(transaction.gift_id, gift.id)
            self.assertEqual(transaction.enacted_by_agent_id, agent_id)
            self.assertEqual(transaction.type,
                             self.parameters['transaction_type'])
            self.assertEqual(transaction.status,
                             self.parameters['transaction_status'])
            self.assertEqual(transaction.reference_number,
                             self.parameters['reference_number'])
            self.assertEqual(transaction.gross_gift_amount,
                             self.parameters['gross_gift_amount'])
            self.assertEqual(transaction.fee, self.parameters['fee'])

            self.assertEqual(str(gift.user_id), self.parameters['user_new_id'])
            self.assertEqual(gift.method_used_id, self.method_used_id)
            self.assertEqual(gift.given_to, self.parameters['given_to'])
Beispiel #3
0
    def test_donation_donor_update(self, ultsys_user_function,
                                   create_ultsys_user_function,
                                   update_ultsys_user_function,
                                   mock_caging_function):  # pylint: disable=unused-argument
        """Test Braintree sale where there is an update to Braintree customer address.

        :param ultsys_user_function: Argument for mocked function.
        :param ultsys_user_update_function: Argument for mocked function.
        :param ultsys_user_create_function: Argument for mocked function.
        :return:
        """
        with self.app.app_context():
            # Create agent ( Braintree ) for the online donation.
            agent_dict = get_agent_dict()
            agent_model = from_json(AgentSchema(), agent_dict, create=True)
            database.session.add(agent_model.data)
            database.session.commit()

            # Call function to be tested with new billing information.
            # See customer_details in TRANSACTION_SUCCESSFUL.
            new_info = {
                'user': {
                    'id': 5,
                    'user_address': {
                        'user_address': '126 Jackson Street',
                        'user_zipcode': '48336'
                    }
                }
            }

            payload = get_donate_dict(new_info)
            result = post_donation(payload)

            self.assertEqual(result['job_id'], 'redis-queue-job-id')

            # The function should NOT update the user.
            user = UltsysUserModel.query.filter_by(ID=5).one_or_none()
            self.assertNotEqual(
                user.email, new_info['user']['user_address']['user_address'])
            self.assertNotEqual(
                user.zip,
                int(new_info['user']['user_address']['user_zipcode']))
    def test_admin_new_donor(self, ultsys_user_function,
                             create_ultsys_user_function,
                             update_ultsys_user_function,
                             mock_caging_function):  # pylint: disable=unused-argument
        """Test the administrative donation of a donor who is a new user."""

        with self.app.app_context():

            # Create the sourced by agent.
            agent_dict = get_agent_dict(
                {'name': 'Unspecified NumbersUSA Staff'})
            agent_model = from_json(AgentSchema(), agent_dict, create=True)
            database.session.add(agent_model.data)
            database.session.flush()
            database.session.commit()

            agent_dict = get_agent_dict({'name': 'Fidelity Bank'})
            bank_agent_model = from_json(AgentSchema(),
                                         agent_dict,
                                         create=True)
            database.session.add(bank_agent_model.data)
            database.session.flush()
            database.session.commit()

            # Create the agent who will be referenced in the payload.
            agent_user_id = '3255162'
            agent_dict = get_agent_dict({
                'name': 'Aaron Peters',
                'user_id': agent_user_id,
                'type': 'Staff Member'
            })
            user_agent_model = from_json(AgentSchema(),
                                         agent_dict,
                                         create=True)
            database.session.add(user_agent_model.data)
            database.session.flush()
            database.session.commit()

            # Call the function to be tested.
            # Administrative donations need to provide information not required by an online donation.
            payload = get_donate_dict({
                'gift': {
                    'method_used': self.parameters['method_used'],
                },
                'transaction': {
                    'date_of_method_used':
                    self.parameters['date_of_method_used']
                },
                'user': get_new_donor_dict(),
                'recurring_subscription': False
            })
            payload['sourced_from_agent_user_id'] = agent_user_id

            payload['transaction']['reference_number'] = self.parameters[
                'reference_number']
            payload['transaction']['type'] = self.parameters[
                'transaction_type']

            self.assertEqual(
                post_donation(payload)['job_id'], 'redis-queue-job-id')

            # The function should create one transaction, a gift, and a user.
            transactions = TransactionModel.query.all()
            gift = GiftModel.query.filter_by(id=1).one_or_none()

            self.assertEqual(transactions[0].gift_id, gift.id)
            self.assertEqual(transactions[0].enacted_by_agent_id, 3)
            self.assertEqual(transactions[0].type,
                             self.parameters['transaction_type'])
            self.assertEqual(transactions[0].status,
                             self.parameters['transaction_status'])
            self.assertEqual(transactions[0].reference_number,
                             self.parameters['reference_number'])
            self.assertEqual(transactions[0].gross_gift_amount,
                             self.parameters['gross_gift_amount'])

            self.assertEqual(transactions[1].gift_id, gift.id)
            self.assertEqual(transactions[1].enacted_by_agent_id, 2)
            self.assertEqual(transactions[1].type,
                             self.parameters['second_transaction_type'])
            self.assertEqual(transactions[1].status,
                             self.parameters['transaction_status'])
            self.assertEqual(transactions[1].reference_number,
                             self.parameters['bank_deposit_number'])
            self.assertEqual(transactions[1].gross_gift_amount,
                             self.parameters['gross_gift_amount'])

            # Find the newly created Ultsys ID.
            ultsys_user = UltsysUserModel.query.filter_by(
                email=self.parameters['new_user_email']).one_or_none()

            self.assertEqual(gift.user_id, ultsys_user.ID)
            self.assertEqual(gift.method_used_id, self.method_used_id)
            self.assertEqual(gift.given_to, self.parameters['given_to'])
    def test_admin_caged_donor(self, ultsys_user_function,
                               mock_caging_function):  # pylint: disable=unused-argument
        """Test the administrative donation of a donor who has been previously caged."""

        with self.app.app_context():
            agent_dict = get_agent_dict(
                {'name': 'Unspecified NumbersUSA Staff'})
            agent_model = from_json(AgentSchema(), agent_dict, create=True)
            database.session.add(agent_model.data)
            database.session.flush()
            database.session.commit()

            agent_dict = get_agent_dict({'name': 'Fidelity Bank'})
            bank_agent_model = from_json(AgentSchema(),
                                         agent_dict,
                                         create=True)
            database.session.add(bank_agent_model.data)
            database.session.flush()
            database.session.commit()

            # Create the agent who will be referenced in the payload.
            agent_user_id = '3255162'
            agent_dict = get_agent_dict({
                'name': 'Aaron Peters',
                'user_id': agent_user_id,
                'type': 'Staff Member'
            })
            user_agent_model = from_json(AgentSchema(),
                                         agent_dict,
                                         create=True)
            database.session.add(user_agent_model.data)
            database.session.flush()
            database.session.commit()

            # Create a caged donor, which will be caged again.
            caged_donor_dict = get_caged_donor_dict({
                'gift_searchable_id':
                uuid.uuid4(),
                'customer_id':
                self.parameters['customer_id']
            })
            caged_donor_model = from_json(CagedDonorSchema(),
                                          caged_donor_dict,
                                          create=True)
            database.session.add(caged_donor_model.data)
            database.session.flush()
            database.session.commit()

            # Call function to tests.
            payload = get_donate_dict({
                'gift': {
                    'method_used': self.parameters['method_used'],
                    'date_of_method_used':
                    self.parameters['date_of_method_used']
                },
                'user': {
                    'user_address': {
                        'user_first_name':
                        caged_donor_model.data.user_first_name,
                        'user_last_name':
                        caged_donor_model.data.user_last_name,
                        'user_address': caged_donor_model.data.user_address
                    }
                }
            })
            payload['sourced_from_agent_user_id'] = agent_user_id
            payload['transaction']['reference_number'] = self.parameters[
                'reference_number']
            payload['transaction']['type'] = self.parameters[
                'transaction_type']

            self.assertEqual(
                post_donation(payload)['job_id'], 'redis-queue-job-id')

            # The function should create one transaction, a gift, and a user.
            transactions = TransactionModel.query.all()
            gift = GiftModel.query.filter_by(id=1).one_or_none()

            self.assertEqual(transactions[0].gift_id, gift.id)
            self.assertEqual(transactions[0].enacted_by_agent_id, 3)
            self.assertEqual(transactions[0].type,
                             self.parameters['transaction_type'])
            self.assertEqual(transactions[0].status,
                             self.parameters['transaction_status'])
            self.assertEqual(transactions[0].reference_number,
                             self.parameters['reference_number'])
            self.assertEqual(transactions[0].gross_gift_amount,
                             self.parameters['gross_gift_amount'])

            self.assertEqual(transactions[1].gift_id, gift.id)
            self.assertEqual(transactions[1].enacted_by_agent_id, 2)
            self.assertEqual(transactions[1].type,
                             self.parameters['second_transaction_type'])
            self.assertEqual(transactions[1].status,
                             self.parameters['transaction_status'])
            self.assertEqual(transactions[1].reference_number,
                             self.parameters['bank_deposit_number'])
            self.assertEqual(transactions[1].gross_gift_amount,
                             self.parameters['gross_gift_amount'])

            caged_donor = CagedDonorModel.query.filter_by(id=2).one()

            self.assertEqual(caged_donor.gift_searchable_id,
                             gift.searchable_id)
            self.assertEqual(caged_donor.user_first_name,
                             caged_donor_dict['user_first_name'])
            self.assertEqual(caged_donor.user_last_name,
                             caged_donor_dict['user_last_name'])
Beispiel #6
0
    def test_donation_caged_donor(self, ultsys_user_function,
                                  mock_caging_function):  # pylint: disable=unused-argument
        """Test Braintree sale for a donor that has already been caged.

        :param ultsys_user_function: Argument for mocked function.
        :return:
        """
        with self.app.app_context():
            # Create agent ( Braintree ) for the online donation.
            agent_dict = get_agent_dict()
            agent_model = from_json(AgentSchema(), agent_dict, create=True)
            database.session.add(agent_model.data)

            # Flush to get agent ID and set database.
            database.session.flush()
            agent_id = agent_model.data.id

            # Create a caged donor, which will be caged again.
            caged_donor_dict = get_caged_donor_dict({
                'gift_searchable_id':
                uuid.uuid4(),
                'customer_id':
                self.parameters['customer_id']
            })

            caged_donor_model = from_json(CagedDonorSchema(), caged_donor_dict)
            database.session.add(caged_donor_model.data)

            database.session.commit()

            # Call function to tests.
            payload = get_donate_dict({
                'user': {
                    'user_address': {
                        'user_first_name': 'Alice',
                        'user_email_address': '*****@*****.**'
                    },
                    'billing_address': {}
                },
                'recurring_subscription': False
            })

            result = post_donation(payload)

            self.assertEqual(result['job_id'], 'redis-queue-job-id')

            # The function should create one transaction, a gift, and an additional caged donor.
            # Additional caged donor is the same as first, but attached to a separate gift.
            transaction = TransactionModel.query.filter_by(id=1).one_or_none()
            gift = GiftModel.query.filter_by(id=1).one_or_none()
            caged_donor = CagedDonorModel.query.filter_by(id=2).one_or_none()

            self.assertEqual(transaction.gift_id, gift.id)
            self.assertEqual(transaction.enacted_by_agent_id, agent_id)
            self.assertEqual(transaction.type,
                             self.parameters['transaction_type'])
            self.assertEqual(transaction.status,
                             self.parameters['transaction_status'])
            self.assertEqual(transaction.reference_number,
                             self.parameters['reference_number'])
            self.assertEqual(transaction.gross_gift_amount,
                             self.parameters['gross_gift_amount'])
            self.assertEqual(transaction.fee, self.parameters['fee'])

            self.assertEqual(gift.user_id, -1)
            self.assertEqual(gift.method_used_id, self.method_used_id)
            self.assertEqual(gift.given_to, self.parameters['given_to'])

            self.assertEqual(caged_donor.gift_searchable_id,
                             gift.searchable_id)
            self.assertEqual(caged_donor.customer_id,
                             self.parameters['customer_id'])
            self.assertEqual(caged_donor.user_first_name,
                             caged_donor_dict['user_first_name'])
            self.assertEqual(caged_donor.user_last_name,
                             caged_donor_dict['user_last_name'])