def test_dni_uniqueness(self): s = Factory.create('student') s.is_valid() self.assertTrue(s.is_valid()) s2 = Factory.build('student', {'dni': s.dni}) self.assertFalse(s2.is_valid()) self.assertIn('dni', s2.errors)
def test_adds_family_members(self): s1 = Factory.create('student', {'name': 'Alumno1'}) s2 = Factory.create('student', {'name': 'Alumno2'}) s3 = Factory.create('student', {'name': 'Alumno3'}) s1.add_family_member(s2) self.assertEqual(s1.family, s1.id) self.assertEqual(s1.family, s2.family) s2.add_family_member(s3) self.assertEqual(s1.family, s3.family)
def test_incoming_returns_only_incoming_movements(self): mv1 = Factory.create('movement', {'direction': 'in'}) mv2 = Factory.create('movement', {'direction': 'out'}) mv3 = Factory.create('movement', {'direction': 'out'}) mv4 = Factory.create('movement', {'direction': 'in'}) outgoing = movement.Movement.outgoing() self.assertNotIn(mv1,outgoing) self.assertIn(mv2,outgoing) self.assertIn(mv3,outgoing) self.assertNotIn(mv4,outgoing)
def test_cannot_be_deleted_if_has_memberships(self): s = Factory.create('student') self.assertIs(s.can_delete(), True) m = Factory.create('membership', {'student': s}) self.assertIsNot(s.can_delete(), True) s = Factory.create('student') self.assertIs(s.can_delete(), True) p = Factory.create('payment', {'user': s}) self.assertIsNot(s.can_delete(), True)
def test_it_returns_zero_if_day_less_than_after_day(self): false_today = datetime.datetime.strptime('2015-01-10','%Y-%m-%d') installment.Installment._today = Mock(return_value=false_today) ins = Factory.create('installment', {'membership': self.membership, 'month': 0, 'year': 2015}) self.assertEqual(ins.get_recharge(after_day = 10, recharge_value = '50'),0) false_today = datetime.datetime.strptime('2015-02-15','%Y-%m-%d') installment.Installment._today = Mock(return_value=false_today) ins = Factory.create('installment', {'membership': self.membership, 'month': 5, 'year': 2015}) self.assertEqual(ins.get_recharge(after_day = 10, recharge_value = '50'),0)
def test_removes_family_members(self): s1 = Factory.create('student', {'name': 'AlumnoUno'}) s2 = Factory.create('student', {'name': 'AlumnoDos'}) s3 = Factory.create('student', {'name': 'AlumnoTres'}) s1.add_family_member(s2) s1.add_family_member(s3) self.assertIn(s2, s1.family_members()) self.assertIn(s3, s1.family_members()) s1.remove_family_member(s2) self.assertNotIn(s2, s1.family_members()) self.assertIn(s3, s1.family_members()) s3.remove_family_member(s1) self.assertNotIn(s2, s1.family_members()) self.assertNotIn(s3, s1.family_members()) self.assertIs(s1.family, None)
def test_it_returns_the_recharge_value_if_day_greater_than_after_day(self): false_today = datetime.datetime.strptime('2015-01-11','%Y-%m-%d') installment.Installment._today = Mock(return_value=false_today) ins = Factory.create('installment', {'membership': self.membership, 'month': 0, 'year': 2015, 'amount': 250}) self.assertEqual(ins.get_recharge(after_day = 10, recharge_value = '50'),50) self.assertEqual(ins.get_recharge(after_day = 10, recharge_value = '10%'),25) false_today = datetime.datetime.strptime('2015-01-06','%Y-%m-%d') installment.Installment._today = Mock(return_value=false_today) ins = Factory.create('installment', {'membership': self.membership, 'month': 11, 'year': 2014, 'amount': 250}) self.assertEqual(ins.get_recharge(after_day = 10, recharge_value = '50'),50) self.assertEqual(ins.get_recharge(after_day = 10, recharge_value = '10%'),25)
def test_deletes_teachers_associations(self): t = Factory.create('teacher') self.klass.add_teacher(t) self.klass.save() self.assertEqual(self._count_teachers_for_klass(self.klass.id), 1) self.klass.delete() self.assertEqual(self._count_teachers_for_klass(self.klass.id), 0)
def test_it_can_filter_by_klass(self): false_today = datetime.datetime.strptime('2015-01-11','%Y-%m-%d') installment.Installment._today = Mock(return_value=false_today) self.klass2 = Factory.create('klass', {'name': 'Arabe'}) self.membership2 = Factory.create('membership', {'student': self.student, 'klass_or_package': self.klass2}) ins1 = Factory.create('installment', {'membership': self.membership, 'month': 0, 'year': 2015}) ins2 = Factory.create('installment', {'membership': self.membership2, 'month': 0, 'year': 2015}) overdues = installment.Installment.overdues(10) self.assertIn(ins1, overdues) self.assertIn(ins2, overdues) overdues = installment.Installment.overdues(10,klass=self.klass) self.assertIn(ins1, overdues) self.assertNotIn(ins2, overdues)
def test_incoming_and_outgoing_can_filter_by_date(self): today = datetime.date.today() yesterday = today - datetime.timedelta(days=1) tomorrow = today + datetime.timedelta(days=1) mv1 = Factory.create('movement', {'direction': 'in', 'date': today}) mv2 = Factory.create('movement', {'direction': 'out', 'date': today}) mv3 = Factory.create('movement', {'direction': 'out', 'date': yesterday}) mv4 = Factory.create('movement', {'direction': 'in', 'date': tomorrow}) mv5 = Factory.create('movement', {'direction': 'in', 'date': yesterday}) mv6 = Factory.create('movement', {'direction': 'out', 'date': today}) mv7 = Factory.create('movement', {'direction': 'out', 'date': tomorrow}) outgoing = movement.Movement.outgoing(yesterday) for mv in [mv3]: self.assertIn(mv,outgoing) for mv in [mv1,mv2,mv4,mv5,mv6,mv7]: self.assertNotIn(mv,outgoing) outgoing = movement.Movement.outgoing(today) for mv in [mv2,mv6]: self.assertIn(mv,outgoing) for mv in [mv1,mv3,mv4,mv5,mv7]: self.assertNotIn(mv,outgoing) outgoing = movement.Movement.outgoing(tomorrow) for mv in [mv7]: self.assertIn(mv, outgoing) for mv in [mv1,mv2,mv3,mv4,mv5,mv6]: self.assertNotIn(mv,outgoing) outgoing = movement.Movement.outgoing(yesterday,today) for mv in [mv2,mv3,mv6]: self.assertIn(mv,outgoing) for mv in [mv1,mv4,mv5,mv7]: self.assertNotIn(mv, outgoing) outgoing = movement.Movement.outgoing(yesterday,tomorrow) for mv in [mv2,mv3,mv6,mv7]: self.assertIn(mv, outgoing) for mv in [mv1,mv4,mv5]: self.assertNotIn(mv, outgoing) outgoing = movement.Movement.outgoing(today,tomorrow) for mv in [mv2,mv6,mv7]: self.assertIn(mv, outgoing) for mv in [mv1,mv3,mv4,mv5]: self.assertNotIn(mv, outgoing) incoming = movement.Movement.incoming(yesterday) for mv in [mv5]: self.assertIn(mv, incoming) for mv in [mv1,mv2,mv3,mv4,mv6,mv7]: self.assertNotIn(mv, incoming) incoming = movement.Movement.incoming(today) for mv in [mv1]: self.assertIn(mv, incoming) for mv in [mv2,mv3,mv4,mv5,mv6,mv7]: self.assertNotIn(mv,incoming) incoming = movement.Movement.incoming(tomorrow) for mv in [mv4]: self.assertIn(mv,incoming) for mv in [mv1,mv2,mv3,mv5,mv6,mv7]: self.assertNotIn(mv,incoming) incoming = movement.Movement.incoming(yesterday,today) for mv in [mv1,mv5]: self.assertIn(mv,incoming) for mv in [mv2,mv3,mv4,mv6,mv7]: self.assertNotIn(mv,incoming) incoming = movement.Movement.incoming(yesterday,tomorrow) for mv in [mv1,mv4,mv5]: self.assertIn(mv, incoming) for mv in [mv2,mv3,mv6,mv7]: self.assertNotIn(mv, incoming) incoming = movement.Movement.incoming(today,tomorrow) for mv in [mv1,mv4]: self.assertIn(mv, incoming) for mv in [mv2,mv3,mv5,mv6,mv7]: self.assertNotIn(mv,incoming)
def setUp(self): self.app = create_app() self.db = db self.app.config['TESTING'] = True self.app_ctx = self.app.app_context() self.app_ctx.push() db.session.close() db.drop_all() db.create_all() self.factory = Factory() self.client = self.app.test_client()
def setUp(self): self.app = create_app() self.db = db self.app.config['TESTING'] = True self.app.config['SERVER_NAME'] = 'localhost' limiter.enabled = False self.app_ctx = self.app.app_context() self.app_ctx.push() db.session.close() db.drop_all() db.create_all() self.factory = Factory() self.client = self.app.test_client()
def test_it_returns_overdue_installments(self): false_today = datetime.datetime.strptime('2015-01-10','%Y-%m-%d') installment.Installment._today = Mock(return_value=false_today) ins1 = Factory.create('installment', {'membership': self.membership, 'month': 0, 'year': 2015}) ins2 = Factory.create('installment', {'membership': self.membership, 'month': 2, 'year': 2015}) overdues = installment.Installment.overdues(10) self.assertNotIn(ins1, overdues) self.assertNotIn(ins2, overdues) false_today = datetime.datetime.strptime('2015-01-11','%Y-%m-%d') installment.Installment._today = Mock(return_value=false_today) overdues = installment.Installment.overdues(10) self.assertIn(ins1, overdues) self.assertNotIn(ins2, overdues) overdues = installment.Installment.overdues(12) self.assertNotIn(ins1, overdues) self.assertNotIn(ins2, overdues) false_today = datetime.datetime.strptime('2015-03-10','%Y-%m-%d') installment.Installment._today = Mock(return_value=false_today) overdues = installment.Installment.overdues(12) self.assertIn(ins1, overdues) self.assertNotIn(ins2, overdues) overdues = installment.Installment.overdues(10) self.assertIn(ins1, overdues) self.assertNotIn(ins2, overdues) overdues = installment.Installment.overdues(9) self.assertIn(ins1, overdues) self.assertIn(ins2, overdues)
def test_incoming_and_outgoing_can_filter_by_date(self): today = datetime.date.today() yesterday = today - datetime.timedelta(days=1) tomorrow = today + datetime.timedelta(days=1) p1 = Factory.create('payment', {'done': 0, 'date': today}) p2 = Factory.create('payment', {'done': 1, 'date': today}) p3 = Factory.create('payment', {'done': 1, 'date': yesterday}) p4 = Factory.create('payment', {'done': 0, 'date': tomorrow}) p5 = Factory.create('payment', {'done': 0, 'date': yesterday}) p6 = Factory.create('payment', {'done': 1, 'date': today}) p7 = Factory.create('payment', {'done': 1, 'date': tomorrow}) payments = payment.Payment.filter(yesterday,yesterday,done = 1) for p in [p3]: self.assertIn(p,payments) for p in [p1,p2,p4,p5,p6,p7]: self.assertNotIn(p,payments) payments = payment.Payment.filter(today,today,done = 1) for p in [p2,p6]: self.assertIn(p, payments) for p in [p1,p3,p4,p5,p7]: self.assertNotIn(p, payments) payments = map(lambda p: p.id, payment.Payment.filter(tomorrow,tomorrow,done = 1)) self.assertEqual(payments, [p7.id]) payments = map(lambda p: p.id, payment.Payment.filter(yesterday,today,done = 1)) self.assertEqual(payments, [p3.id,p2.id,p6.id]) payments = map(lambda p: p.id, payment.Payment.filter(yesterday,tomorrow,done = 1)) self.assertEqual(payments, [p3.id,p2.id,p6.id,p7.id]) payments = map(lambda p: p.id, payment.Payment.filter(today,tomorrow,done = 1)) self.assertEqual(payments, [p2.id,p6.id,p7.id]) payments = map(lambda p: p.id, payment.Payment.filter(yesterday,yesterday,done = 0)) self.assertEqual(payments, [p5.id]) payments = map(lambda p: p.id, payment.Payment.filter(today,today,done = 0)) self.assertEqual(payments, [p1.id]) payments = map(lambda p: p.id, payment.Payment.filter(tomorrow,tomorrow,done = 0)) self.assertEqual(payments, [p4.id]) payments = map(lambda p: p.id, payment.Payment.filter(yesterday,today,done = 0)) self.assertEqual(payments, [p5.id,p1.id]) payments = map(lambda p: p.id, payment.Payment.filter(yesterday,tomorrow,done = 0)) self.assertEqual(payments, [p5.id,p1.id,p4.id]) payments = map(lambda p: p.id, payment.Payment.filter(today,tomorrow, done = 0)) self.assertEqual(payments, [p1.id,p4.id])
def test_cannot_be_deleted_if_there_is_a_membership(self): u = Factory.create('student') m = membership.Membership.create({'klass_or_package': self.package, 'student': u}) self.assertIsNot(self.package.can_delete(), True)
def test_saved_if_valid(self): mov = Factory.build('movement') self.assertTrue(mov.is_valid()) self.assertTrue(mov.save())
def test_is_not_valid_if_amount_is_zero(self): mov = Factory.build('movement', {'amount': 0}) self.assertFalse(mov.is_valid())
def _setUp(self): self.klass1 = Factory.create('klass', {'name': 'klass_1'}) self.klass2 = Factory.create('klass', {'name': 'klass_2'}) self.package = Factory.build('package') self.package.klasses = [self.klass1, self.klass2] self.package.save()
def _setUp(self): self.student = Factory.create('student') self.klass = Factory.create('klass') self.membership = Factory.create('membership', {'student': self.student, 'klass_or_package': self.klass})
def test_cannot_be_deleted_if_a_package_uses_it(self): k2 = Factory.create('klass') p = Factory.create('package', {'klasses': [self.klass,k2]}) self.assertIsNot(self.klass.delete(), True)
def test_cannot_be_deleted_if_a_membership_uses_it(self): s = Factory.create('student') m = Factory.create('membership', {'student': s, 'klass_or_package': self.klass}) self.assertIsNot(self.klass.delete(), True)
def test_saved_if_valid(self): p = Factory.build('payment') self.assertTrue(p.is_valid()) self.assertTrue(p.save())
def test_is_not_valid_if_amount_is_zero(self): p = Factory.build('payment', {'amount': 0}) self.assertFalse(p.is_valid())
def test_deletes_its_schedules(self): r = Factory.create('room') s = Factory.build('schedule', {'room': r}) self.klass.add_schedule(s) self.klass.delete() self.assertIs(schedule.Schedule.find(s.id), False)
def _setUp(self): self.klass = Factory.create('klass')