def test_campaign_model(self):
        """A test to ensure that campaigns are saved correctly to the database."""

        with self.app.app_context():
            campaign_dict = get_campaign_dict()

            campaign_model = from_json(CampaignSchema(),
                                       campaign_dict,
                                       create=True)
            database.session.add(campaign_model.data)
            database.session.commit()

            campaign_query = CampaignModel.query.filter_by(
                name=campaign_dict['name']).one()
            campaign_session = database.session.query( CampaignModel )\
                .filter_by( name=campaign_dict[ 'name' ] ).one()

            kwargs = {
                'self': self,
                'model_dict': campaign_dict,
                'model': CampaignModel,
                'model_data': campaign_model.data,
                'model_query': campaign_query,
                'model_session': campaign_session
            }
            ensure_query_session_aligned(kwargs)
    def test_campaign_amounts_model(self):
        """A test to ensure that campaign amounts are saved correctly to the database."""

        with self.app.app_context():
            # campaign_amounts_dict = get_campaign_amounts_dict()
            #
            # campaign_amounts_model = from_json( CampaignAmountsSchema(), campaign_amounts_dict, create=True )
            # database.session.add( campaign_amounts_model.data )
            # database.session.commit()

            campaign_amounts = get_campaign_amount_jsons()
            campaign_amount_dict = campaign_amounts[0]
            campaign_amount_model = from_json(CampaignAmountsSchema(),
                                              campaign_amount_dict,
                                              create=True)
            database.session.add(campaign_amount_model.data)
            database.session.commit()

            campaign_amount_query = CampaignAmountsModel.query\
                .filter_by( campaign_id=campaign_amount_dict[ 'campaign_id' ] ).one()
            campaign_amount_session = database.session.query( CampaignAmountsModel ) \
                .filter_by( campaign_id=campaign_amount_dict[ 'campaign_id' ] ).one()

            kwargs = {
                'self': self,
                'model_dict': campaign_amount_dict,
                'model': CampaignAmountsModel,
                'model_data': campaign_amount_model.data,
                'model_query': campaign_amount_query,
                'model_session': campaign_amount_session
            }
            ensure_query_session_aligned(kwargs)
    def test_queued_donor_model(self):
        """A test to ensure that caged donors are saved correctly to the database."""

        with self.app.app_context():
            queued_donor_dict = get_queued_donor_dict({
                'gift_id':
                1,
                'gift_searchable_id':
                uuid.uuid4(),
                'customer_id':
                'customer_id'
            })

            queued_donor_model = from_json(QueuedDonorSchema(),
                                           queued_donor_dict,
                                           create=True)
            database.session.add(queued_donor_model.data)
            database.session.commit()

            queued_donor_query = QueuedDonorModel.query \
                .filter_by( customer_id=queued_donor_dict[ 'customer_id' ] ).one()
            queued_donor_session = database.session.query( QueuedDonorModel ) \
                .filter_by( customer_id=queued_donor_dict[ 'customer_id' ] ).one()

            kwargs = {
                'self': self,
                'model_dict': queued_donor_dict,
                'model': QueuedDonorModel,
                'model_data': queued_donor_model.data,
                'model_query': queued_donor_query,
                'model_session': queued_donor_session
            }
            ensure_query_session_aligned(kwargs)
    def test_transaction_model(self):
        """A test to ensure that transactions are saved correctly to the database."""

        with self.app.app_context():
            transaction_dict = get_transaction_dict({'gift_id': 1})

            transaction_model = from_json(TransactionSchema(),
                                          transaction_dict,
                                          create=True)
            database.session.add(transaction_model.data)
            database.session.commit()

            transaction_query = TransactionModel.query.filter_by(
                gift_id=transaction_dict['gift_id']).one()
            transaction_session = database.session.query( TransactionModel )\
                .filter_by( gift_id=transaction_dict[ 'gift_id' ] )\
                .one()

            kwargs = {
                'self': self,
                'model_dict': transaction_dict,
                'model': TransactionModel,
                'model_data': transaction_model.data,
                'model_query': transaction_query,
                'model_session': transaction_session
            }
            ensure_query_session_aligned(kwargs)
    def test_gift_model(self):
        """A test to ensure that gifts are saved correctly to the database."""

        with self.app.app_context():

            gift_dict = get_gift_dict({
                'user_id': 1,
                'recurring_subscription_id': 'abcdefg'
            })

            gift_model = from_json(GiftSchema(), gift_dict, create=True)
            database.session.add(gift_model.data)
            database.session.commit()

            gift_query = GiftModel.query.filter_by(
                user_id=gift_dict['user_id']).one()
            gift_session = database.session.query(GiftModel).filter_by(
                user_id=gift_dict['user_id']).one()

            kwargs = {
                'self': self,
                'model_dict': gift_dict,
                'model': GiftModel,
                'model_data': gift_model.data,
                'model_query': gift_query,
                'model_session': gift_session
            }
            ensure_query_session_aligned(kwargs)
    def test_gift_thank_you_model(self):
        """A test to ensure that gifts are saved correctly to the database."""

        with self.app.app_context():

            gift_thank_you_dict = {'gift_id': 1}

            gift_thank_you_model = from_json(GiftThankYouLetterSchema(),
                                             gift_thank_you_dict,
                                             create=True)
            database.session.add(gift_thank_you_model.data)
            database.session.commit()

            gift_thank_you_query = GiftThankYouLetterModel.query\
                .filter_by( gift_id=gift_thank_you_dict[ 'gift_id' ] ).one()
            gift_thank_you_session = database.session.query( GiftThankYouLetterModel )\
                .filter_by( gift_id=gift_thank_you_dict[ 'gift_id' ] ).one()

            kwargs = {
                'self': self,
                'model_dict': gift_thank_you_dict,
                'model': GiftThankYouLetterModel,
                'model_data': gift_thank_you_model.data,
                'model_query': gift_thank_you_query,
                'model_session': gift_thank_you_session
            }
            ensure_query_session_aligned(kwargs)
    def test_agent_model(self):
        """A test to ensure that gifts are saved correctly to the database."""

        with self.app.app_context():

            agent_dict = get_agent_jsons()[AGENT_INDEX]

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

            agent_query = AgentModel.query\
                .filter_by( user_id=agent_dict[ 'user_id' ] ).one()
            agent_session = database.session.query( AgentModel )\
                .filter_by( user_id=agent_dict[ 'user_id' ] ).one()

            kwargs = {
                'self': self,
                'model_dict': agent_dict,
                'model': AgentModel,
                'model_data': agent_model.data,
                'model_query': agent_query,
                'model_session': agent_session
            }
            ensure_query_session_aligned(kwargs)