def test_get_rate_for_sms_and_email(notify_db, notify_db_session): letter_rate = LetterRate(start_date=datetime(2017, 12, 1), rate=Decimal(0.33), crown=True, sheet_count=1, post_class='second') dao_create_letter_rate(letter_rate) sms_rate = Rate(valid_from=datetime(2017, 12, 1), rate=Decimal(0.15), notification_type=SMS_TYPE) db.session.add(sms_rate) email_rate = Rate(valid_from=datetime(2017, 12, 1), rate=Decimal(0), notification_type=EMAIL_TYPE) db.session.add(email_rate) non_letter_rates = [(r.notification_type, r.valid_from, r.rate) for r in Rate.query.order_by(desc(Rate.valid_from)).all()] letter_rates = [(r.start_date, r.crown, r.sheet_count, r.rate) for r in LetterRate.query.order_by(desc(LetterRate.start_date)).all()] rate = get_rate(non_letter_rates, letter_rates, SMS_TYPE, datetime(2018, 1, 1)) assert rate == Decimal(0.15) rate = get_rate(non_letter_rates, letter_rates, EMAIL_TYPE, datetime(2018, 1, 1)) assert rate == Decimal(0)
def test_get_rate_for_letter_latest(notify_db, notify_db_session): letter_rate = LetterRate(start_date=datetime(2017, 12, 1), rate=Decimal(0.33), crown=True, sheet_count=1, post_class='second') dao_create_letter_rate(letter_rate) letter_rate = LetterRate(start_date=datetime(2016, 12, 1), end_date=datetime(2017, 12, 1), rate=Decimal(0.30), crown=True, sheet_count=1, post_class='second') dao_create_letter_rate(letter_rate) non_letter_rates = [ (r.notification_type, r.valid_from, r.rate) for r in Rate.query.order_by(desc(Rate.valid_from)).all() ] letter_rates = [ (r.start_date, r.crown, r.sheet_count, r.rate) for r in LetterRate.query.order_by(desc(LetterRate.start_date)).all() ] rate = get_rate(non_letter_rates, letter_rates, LETTER_TYPE, datetime(2018, 1, 1), True, 1) assert rate == Decimal(0.33)
def test_dao_create_letter_rate(notify_db_session): letter_rate = LetterRate(start_date=datetime(2017, 12, 1), rate=0.33, crown=True, sheet_count=1, post_class='second') dao_create_letter_rate(letter_rate) rates = LetterRate.query.all() assert len(rates) == 1
def test_get_letter_rates_for_daterange(notify_db_session): letter_rate = LetterRate(start_date=datetime(2017, 12, 1), rate=0.33, crown=True, sheet_count=1, post_class='second') dao_create_letter_rate(letter_rate) letter_rate = LetterRate(start_date=datetime(2016, 12, 1), end_date=datetime(2017, 12, 1), rate=0.30, crown=True, sheet_count=1, post_class='second') dao_create_letter_rate(letter_rate) results = get_letter_rates_for_daterange(date=datetime(2017, 12, 2), crown=True, sheet_count=1, post_class='second') assert len(results) == 1 assert results[0].rate == Decimal('0.33')