Beispiel #1
0
    def setUp(self):
        self.worked_days = []
        self.work_times = []
        for i in range(10):
            worked_day = WorkedDay(month_payment_id=i,
                                   day=datetime.now().date() -
                                   timedelta(days=10 - i),
                                   paid=False)
            self.worked_days.append(worked_day)
        for i in range(10):
            work_time = WorkTime(
                id=i,
                hour_payment_id=1,
                start_work=datetime.now().replace(
                    hour=10, minute=0, second=0) - timedelta(days=10 - i),
                end_work=datetime.now().replace(hour=19, minute=0, second=0) -
                timedelta(days=10 - i),
                paid=False)
            self.work_times.append(work_time)

        self.tasks = []
        for i in range(10):
            task = WorkTask(
                id=i,
                project_id=1,
                price=(i + 1) * 100,
            )
            self.tasks.append(task)
Beispiel #2
0
    def test_method__get_worked_days_filter_paid(self):
        month_payment = MonthPayment(
            rate=100,
            project_id=self.project.id,
        )

        month_payment = self.month_payment_repo.create(month_payment)
        for i in range(self.COUNT_WORK_DAY):
            worked_day = WorkedDay(
                month_payment_id=month_payment.id,
                paid=i % 2 == 0,
                day=datetime.datetime.now().date() + timedelta(days=i)
            )

            self.worked_day_repo.create(worked_day)

        worked_days = self.month_payment_repo._get_worked_days(month_payment.id, paid=True)
        self.assertEqual(type(worked_days), list)
        self.assertEqual(len(worked_days), 5)
        for worked_day in worked_days:
            self.assertEqual(worked_day.paid, True)

        worked_days = self.month_payment_repo._get_worked_days(month_payment.id, paid=False)
        self.assertEqual(type(worked_days), list)
        self.assertEqual(len(worked_days), 5)
        for worked_day in worked_days:
            self.assertEqual(worked_day.paid, False)
Beispiel #3
0
    def test_method__get_worked_days_filter_last_month_days(self):
        month_payment = MonthPayment(
            rate=100,
            project_id=self.project.id,
        )

        month_payment = self.month_payment_repo.create(month_payment)
        for i in range(20):
            worked_day = WorkedDay(
                month_payment_id=month_payment.id,
                paid=i % 2 == 0,
                day=datetime.datetime.now().date() - timedelta(days=(datetime.datetime.now().day - 10) - i + 30)
            )

            self.worked_day_repo.create(worked_day)

        worked_days = self.month_payment_repo._get_worked_days(month_payment.id,
                                                               last_month_days=timezone.now().replace(day=1).date())
        self.assertEqual(type(worked_days), list)
        self.assertEqual(len(worked_days), 10)

        worked_days = self.month_payment_repo._get_worked_days(month_payment.id,
                                                               last_month_days=timezone.now().replace(day=1).date(),
                                                               paid=True)
        self.assertEqual(type(worked_days), list)
        self.assertEqual(len(worked_days), 10)

        month_payment2 = self.month_payment_repo.create(month_payment)
        for i in range(20):
            worked_day = WorkedDay(
                month_payment_id=month_payment2.id,
                paid=i % 2 == 0,
                day=datetime.datetime.now().replace(day=1).date() + timedelta(days=i)
            )


            self.worked_day_repo.create(worked_day)

        worked_days = self.month_payment_repo._get_worked_days(month_payment2.id,
                                                               last_month_days=timezone.now().replace(day=1).date())
        self.assertEqual(type(worked_days), list)
        self.assertEqual(len(worked_days), 0)

        worked_days = self.month_payment_repo._get_worked_days(month_payment2.id,
                                                               last_month_days=timezone.now().date())
        self.assertEqual(type(worked_days), list)
        self.assertEqual(len(worked_days), 5)
Beispiel #4
0
 def setUp(self):
     self.worked_days = []
     for i in range(10):
         worked_day = WorkedDay(month_payment_id=1,
                                day=datetime.now().date() -
                                timedelta(days=10 - i),
                                paid=False)
         self.worked_days.append(worked_day)
Beispiel #5
0
    def _decode_db_worked_day(self, db_worked_day):

        fileds = {
            'id': db_worked_day.id,
            'month_payment_id': db_worked_day.month_payment.id,
            'day': db_worked_day.day,
            'paid': db_worked_day.paid
        }
        return WorkedDay(**fileds)
Beispiel #6
0
    def test_method_update(self):
        worked_day = WorkedDay(
            month_payment_id=self.month_payment.id,
            paid=False,
            day=datetime.datetime.now().date()
        )

        worked_day_create = self.worked_day_repo.create(worked_day)

        worked_day_update_1 = WorkedDay(
            id=worked_day_create.id,
            paid=True,
            day=datetime.datetime.now().date() + timedelta(days=2)
        )

        worked_day_update = self.worked_day_repo.update(worked_day_update_1)

        self.assertEqual(worked_day_update.id, worked_day_create.id)
        self.assertEqual(worked_day_update.month_payment_id, worked_day_create.month_payment_id)
        self.assertEqual(worked_day_update.day, datetime.datetime.now().date() + timedelta(days=2))
        self.assertEqual(worked_day_update.paid, True)
Beispiel #7
0
    def test_method_create(self):
        worked_day = WorkedDay(
            month_payment_id=self.month_payment.id,
            paid=False,
            day=datetime.datetime.now().date()
        )

        worked_day_create = self.worked_day_repo.create(worked_day)
        db_worked_day = WorkedDayORM.objects.get(id=worked_day_create.id)
        self.assertEqual(worked_day_create.id, db_worked_day.id)
        self.assertEqual(worked_day_create.paid, db_worked_day.paid)
        self.assertEqual(worked_day_create.month_payment_id, db_worked_day.month_payment.id)
        self.assertEqual(worked_day_create.day, db_worked_day.day)
Beispiel #8
0
    def test_method_gat_all(self):
        COUNT_WORK_DAY = 10
        for i in range(COUNT_WORK_DAY):
            worked_day = WorkedDay(
                month_payment_id=self.month_payment.id,
                paid=False,
                day=datetime.datetime.now().date() + timedelta(days=i)
            )

            self.worked_day_repo.create(worked_day)

        worked_days = self.worked_day_repo.get_all(self.month_payment.id)
        self.assertEqual(type(worked_days), list)
        self.assertEqual(len(worked_days), COUNT_WORK_DAY)
Beispiel #9
0
    def test_total_month_payment(self):
        month_payment = MonthPayment(project_id=1,
                                     rate=500,
                                     work_days=self.worked_days)

        self.assertEqual(month_payment.total, 5000)
        self.worked_days.append(
            WorkedDay(month_payment_id=1,
                      day=datetime.now().date() - timedelta(days=1),
                      paid=False))
        month_payment = MonthPayment(project_id=1,
                                     rate=500,
                                     work_days=self.worked_days)
        self.assertEqual(month_payment.total, 5000)
Beispiel #10
0
    def test_method_delete(self):
        worked_day = WorkedDay(
            month_payment_id=self.month_payment.id,
            paid=False,
            day=datetime.datetime.now().date()
        )

        worked_day_create = self.worked_day_repo.create(worked_day)
        self.assertIsNotNone(self.worked_day_repo.get(worked_day_create.id))
        self.assertIsNotNone(WorkedDayORM.objects.get(id=worked_day_create.id))
        self.worked_day_repo.delete(worked_day_create.id)

        with self.assertRaises(EntityDoesNotExistException):
            self.worked_day_repo.get(worked_day_create.id)

        with self.assertRaises(WorkedDayORM.DoesNotExist):
            WorkedDayORM.objects.get(id=worked_day_create.id)
Beispiel #11
0
    def test_method_get(self):

        worked_day = WorkedDay(
            month_payment_id=self.month_payment.id,
            paid=False,
            day=datetime.datetime.now().date()
        )

        worked_day_create = self.worked_day_repo.create(worked_day)
        worked_day_get = self.worked_day_repo.get(worked_day_create.id)

        self.assertEqual(worked_day_get.id, worked_day_create.id)
        self.assertEqual(worked_day_get.month_payment_id, worked_day_create.month_payment_id)
        self.assertEqual(worked_day_get.day, worked_day_create.day)
        self.assertEqual(worked_day_get.paid, worked_day_create.paid)

        with self.assertRaises(EntityDoesNotExistException):
            self.worked_day_repo.get(worked_day_create.id + 56156)
Beispiel #12
0
    def test_method___get_entity_type_list_month_of_payment(self):
        COUNT_MONTH_PAYMENT = 5
        COUNT_WORKED_DAY = 10
        project = Project(
            title='Test Project',
            description='My Test project',
            type_of_payment=''
                            'M_P',
            start_date=datetime.datetime.now(),
            user_id=self.user.id
        )

        project_create = self.project_repo.create(project)
        month_payment_repo = MonthPaymentRepo()
        for i in range(COUNT_MONTH_PAYMENT):
            month_payment = MonthPayment(
                project_id=project_create.id,
                rate=100,

            )

            month_payment = month_payment_repo.create(month_payment)
            for j in range(COUNT_WORKED_DAY):
                worked_day = WorkedDay(
                    month_payment_id=month_payment.id,
                    paid=False,
                    day=datetime.datetime.now().date()-timedelta(days=i)
                )
                WorkedDayRepo().create(worked_day)

        month_payments = self.project_repo._get_entity_type_list(project_id=project_create.id)

        self.assertEqual(type(month_payments), list)
        self.assertEqual(len(month_payments), COUNT_MONTH_PAYMENT)
        self.assertEqual(type(month_payments.pop()), MonthPayment)
        self.assertEqual(type(month_payments.pop()._work_days), list)
        self.assertEqual(len(month_payments.pop()._work_days), COUNT_WORKED_DAY)
        self.assertEqual(type(month_payments.pop()._work_days.pop()), WorkedDay)
Beispiel #13
0
 def create(**kwargs):
     return WorkedDay(**kwargs)