Пример #1
0
    def test_create_nurse_event_error(self):
        sow = sows_testing.create_sow_and_put_in_workshop_one()
        Semination.objects.create_semination(sow=sow,
                                             week=1,
                                             initiator=None,
                                             semination_employee=None)
        Semination.objects.create_semination(sow=sow,
                                             week=1,
                                             initiator=None,
                                             semination_employee=None)
        Ultrasound.objects.create_ultrasound(sow, None, True)

        with self.assertRaises(ValidationError):
            sow.markasnurse_set.create_nurse_event(sow)
Пример #2
0
    def test_mass_semination(self):
        sow1 = sows_testing.create_sow_and_put_in_workshop_one()
        sow2 = sows_testing.create_sow_and_put_in_workshop_one()
        sow3 = sows_testing.create_sow_and_put_in_workshop_one()

        sow3.change_group_to('Ремонтная')

        sows_qs = Sow.objects.filter(pk__in=[sow1.pk, sow2.pk, sow3.pk])
        Semination.objects.mass_semination(sows_qs=sows_qs,
                                           week=1,
                                           initiator=None,
                                           semination_employee=None,
                                           boar=self.boar)

        self.assertEqual(Semination.objects.all().count(), 3)

        sow1.refresh_from_db()
        self.assertEqual(sow1.status.title, 'Осеменена 1')
        self.assertEqual(sow1.tour.week_number, 1)
        self.assertEqual(sow1.sow_group, None)

        sow3.refresh_from_db()
        self.assertEqual(sow3.sow_group.title, 'Проверяемая')
Пример #3
0
 def test_culling_permissions_403(self):
     self.client.force_authenticate(user=self.brig5)
     location1 = Location.objects.filter(
         sowAndPigletsCell__isnull=False).first()
     sow1 = sows_testing.create_sow_and_put_in_workshop_one()
     sow1.change_sow_current_location(location1)
     response = self.client.post(
         '/api/workshopthree/sows/%s/culling/' % sow1.pk, {
             'culling_type': 'padej',
             'reason': 'test',
             'weight': 150
         })
     self.assertEqual(response.status_code, 403)
     self.client.logout()
Пример #4
0
    def test_create_transaction(self):
        sow = sows_testing.create_sow_and_put_in_workshop_one()
        to_location = Location.objects.get(workshop__number='2')
        transaction = SowTransaction.objects.create_transaction(
            to_location=to_location,
            initiator=None,
            sow=sow
            )

        self.assertEqual(transaction.sow, sow)
        self.assertEqual(transaction.initiator, None)
        self.assertEqual(transaction.from_location,
         Location.objects.get(workshop__number=1))
        self.assertEqual(transaction.to_location, to_location)
Пример #5
0
 def test_double_semination(self):
     sow1 = sows_testing.create_sow_and_put_in_workshop_one()
     self.client.force_authenticate(user=self.brig1)
     response = self.client.post('/api/workshoponetwo/sows/double_semination/', 
         {'week': 55, 'seminator1': self.user.pk, 'seminator2': self.user.pk,
          'boar1': self.boar.pk,
          'boar2': Boar.objects.all()[1].pk, 'farm_id': sow1.farm_id})
     self.assertEqual(response.data['semination1']['tour'], 'Тур 55 2020г')
     self.assertEqual(response.data['semination2']['tour'], 'Тур 55 2020г')
     self.assertEqual(response.data['semination1']['boar'], self.boar.pk)
     self.assertEqual(response.data['semination2']['boar'], Boar.objects.all()[1].pk)
     self.assertEqual(response.data['semination1']['semination_employee'], self.user.pk)
     self.assertEqual(response.data['semination2']['semination_employee'], self.user.pk)
     self.client.logout()
Пример #6
0
    def test_mass_culling(self):
        sow1 = sows_testing.create_sow_and_put_in_workshop_one()
        sow2 = sows_testing.create_sow_and_put_in_workshop_one()
        sow3 = sows_testing.create_sow_and_put_in_workshop_one()

        self.client.force_authenticate(user=self.brig1)
        response = self.client.post('/api/workshoponetwo/sows/mass_culling/',
            { 
              'sows': [sow1.pk, sow2.pk, sow3.pk], 'culling_type': 'padej', 
              'reason': 'test_reason', 'weight': 0
            })

        sow1.refresh_from_db()
        sow2.refresh_from_db()
        sow3.refresh_from_db()

        self.assertEqual(sow1.alive, False)
        self.assertEqual(sow2.alive, False)
        self.assertEqual(sow3.alive, False)

        self.assertEqual(sow1.status.title, 'Брак')
        self.assertEqual(sow2.status.title, 'Брак')
        self.assertEqual(sow3.status.title, 'Брак')
        self.client.logout()
Пример #7
0
    def test_get_by_tour(self):
        sow = sows_testings.create_sow_and_put_in_workshop_one()
        Semination.objects.create_semination(sow=sow, week=1, initiator=None,
         semination_employee=None)
        Semination.objects.create_semination(sow=sow, week=1, initiator=None,
         semination_employee=None)
        tour = Tour.objects.filter(week_number=1).first()
        self.assertEqual(sow.get_seminations_by_tour(tour).count(), 2)

        Ultrasound.objects.create_ultrasound(sow, None, True)
        self.assertEqual(sow.get_ultrasounds1_by_tour(tour).count(), 1)

        sow.location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow.save()
        SowFarrow.objects.create_sow_farrow(sow=sow, alive_quantity=7, mummy_quantity=1)
        self.assertEqual(sow.get_farrows_by_tour(tour).count(), 1)
Пример #8
0
    def test_create_abortion(self):
        sow = sows_testing.create_sow_and_put_in_workshop_one()
        Semination.objects.create_semination(sow=sow,
                                             week=1,
                                             initiator=None,
                                             semination_employee=None)
        Semination.objects.create_semination(sow=sow,
                                             week=1,
                                             initiator=None,
                                             semination_employee=None)
        Ultrasound.objects.create_ultrasound(sow, None, True)

        abort = AbortionSow.objects.create_abortion(sow, None)
        sow.refresh_from_db()
        self.assertEqual(sow.tour, None)
        self.assertEqual(sow.status.title, 'Аборт')
        self.assertEqual(abort.location, sow.location)
Пример #9
0
    def test_model_change_group_to_restrict1(self):
        # should not change to Проверяемая if not Ремонтная
        sow1 = sows_testings.create_sow_and_put_in_workshop_one()
        sow1.change_group_to('Проверяемая')
 
        sow1.refresh_from_db()
        self.assertEqual(sow1.sow_group, None)
        self.assertEqual(sow1.group_records.all().count(), 0)

        sow1.change_group_to('Ремонтная')
        sow1.change_group_to('Проверяемая')
        sow1.refresh_from_db()
        self.assertEqual(sow1.sow_group.title, 'Проверяемая')
        self.assertEqual(sow1.group_records.all().count(), 2)

        sow1_group_record = sow1.group_records.all().first()
        self.assertEqual(sow1_group_record.group_before.title, 'Ремонтная')
        self.assertEqual(sow1_group_record.group_after.title, 'Проверяемая')
Пример #10
0
    def test_to_seminate(self):
        self.client.force_authenticate(user=self.brig1)

        # not seminated sow
        sow1 = sows_testing.create_sow_and_put_in_workshop_one()

        # sow one time seminated
        seminated_sow1 = sows_testing.create_sow_with_semination(sow1.location)
        
        # sow two times seminated
        seminated_sow3 = sows_testing.create_sow_with_semination(sow1.location)
        Semination.objects.create_semination(sow=seminated_sow3, week=1, initiator=None,
         semination_employee=None)

        # sow have usound 30
        seminated_sow2 = sows_testing.create_sow_with_semination(sow1.location)
        Semination.objects.create_semination(sow=seminated_sow2, week=1, initiator=None,
         semination_employee=None)
        Ultrasound.objects.create_ultrasound(sow=seminated_sow2,
         initiator=None, result=True, days=30)

        # sow have usound 60
        seminated_sow4 = sows_testing.create_sow_with_semination(sow1.location)
        Semination.objects.create_semination(sow=seminated_sow4, week=1, initiator=None,
         semination_employee=None)
        Ultrasound.objects.create_ultrasound(sow=seminated_sow4,
         initiator=None, result=True, days=30)
        Ultrasound.objects.create_ultrasound(sow=seminated_sow4,
         initiator=None, result=True, days=60)

        # sow have usound 30
        seminated_sow5 = sows_testing.create_sow_with_semination(sow1.location)
        Semination.objects.create_semination(sow=seminated_sow5, week=1, initiator=None,
         semination_employee=None)
        Ultrasound.objects.create_ultrasound(sow=seminated_sow5,
         initiator=None, result=False, days=30)

        response =self.client.get('/api/sows/?to_seminate=True')
        self.assertEqual(response.data['count'], 2)
        for result_sow in response.data['results']:
            self.assertEqual(
                result_sow['id'] in [sow1.pk, seminated_sow5.pk],
                True)
        self.client.logout()
Пример #11
0
    def test_sow_farrows(self):
        sow1 = sows_testing.create_sow_with_semination_usound(
            Location.objects.filter(sowAndPigletsCell__isnull=False).first())
        farrow = SowFarrow.objects.create_sow_farrow(sow=sow1, alive_quantity=7, mummy_quantity=1)

        sow2 = sows_testing.create_sow_with_semination_usound(
            Location.objects.filter(sowAndPigletsCell__isnull=False)[1])
        farrow2 = SowFarrow.objects.create_sow_farrow(sow=sow2, alive_quantity=9, mummy_quantity=1)

        sow3 = sows_testing.create_sow_with_semination_usound(
            Location.objects.filter(sowAndPigletsCell__isnull=False)[2])
        farrow3 = SowFarrow.objects.create_sow_farrow(sow=sow3, alive_quantity=17, mummy_quantity=1)
        
        sow4 = sows_testing.create_sow_and_put_in_workshop_one()

        self.client.force_authenticate(user=self.brig3)
        response = self.client.get(f'/api/sows/farrows/')
        self.assertEqual(len(response.data), 3)
        self.client.logout()
Пример #12
0
    def test_change_status_and_create_status_record(self):
        sow1 = sows_testings.create_sow_and_put_in_workshop_one()

        status1 = SowStatus.objects.get(title='Ожидает осеменения')
        status2 = SowStatus.objects.get(title='Осеменена 1')
        status3 = SowStatus.objects.get(title='Супорос 35')

        sow1.change_status_to('Ожидает осеменения')

        self.assertEqual(SowStatusRecord.objects.all().count(), 1)
        status_record = SowStatusRecord.objects.all().first()
        self.assertEqual(status_record.status_before, None)
        self.assertEqual(status_record.status_after.title, 'Ожидает осеменения')

        sow1.change_status_to('Осеменена 1')

        status_record = SowStatusRecord.objects.all().order_by('-created_at').first()
        self.assertEqual(status_record.status_before.title, 'Ожидает осеменения')
        self.assertEqual(status_record.status_after.title, 'Осеменена 1')
Пример #13
0
    def test_sowtransaction_save(self):
        sow = sows_testing.create_sow_and_put_in_workshop_one(1, '100')
        to_location = Location.objects.create_location(
            SowSingleCell.objects.get(number='2'))

        transaction = SowTransaction(from_location=sow.location,
                                     to_location=to_location,
                                     sow=sow)

        self.assertEqual(sow.location.sowSingleCell.sow, sow)
        transaction.to_empty_from_location_single_cell
        self.assertEqual(sow.location.sowSingleCell.sow, None)

        transaction.to_fill_to_location_single_cell
        to_location.refresh_from_db()
        self.assertEqual(to_location.sowSingleCell.sow, sow)

        transaction.change_sow_current_location
        sow.refresh_from_db()
        self.assertEqual(sow.location, to_location)
Пример #14
0
    def test_create_nurse_event(self):
        sow = sows_testing.create_sow_and_put_in_workshop_one()
        Semination.objects.create_semination(sow=sow,
                                             week=1,
                                             initiator=None,
                                             semination_employee=None)
        Semination.objects.create_semination(sow=sow,
                                             week=1,
                                             initiator=None,
                                             semination_employee=None)
        Ultrasound.objects.create_ultrasound(sow, None, True)
        location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow.change_sow_current_location(location)

        SowFarrow.objects.create_sow_farrow(sow=sow,
                                            alive_quantity=10,
                                            dead_quantity=1)

        sow.markasnurse_set.create_nurse_event(sow)
        sow.refresh_from_db()
        self.assertEqual(sow.tour, None)
        self.assertEqual(sow.status.title, 'Кормилица')
Пример #15
0
    def test_get_sow(self):
        self.client.force_authenticate(user=self.brig5)
        sow = sows_testing.create_sow_and_put_in_workshop_one()
        boar = Boar.objects.all().first()

        response = self.client.get('/api/sows/%s/' % sow.pk)

        Semination.objects.create_semination(sow=sow, week=1,
         initiator=self.user, semination_employee=self.user, boar=boar)
        response = self.client.get('/api/sows/%s/' % sow.pk)
        self.assertEqual(response.data['tours_info'][0]['seminations'][0]['semination_employee'],
            self.user.pk)

        Semination.objects.create_semination(sow=sow, week=1,
         initiator=self.user, semination_employee=self.user, boar=boar)
        response = self.client.get('/api/sows/%s/' % sow.pk)
        self.assertEqual(len(response.data['tours_info'][0]['seminations']), 2)

        Ultrasound.objects.create_ultrasound(sow, self.user, True)
        response = self.client.get('/api/sows/%s/' % sow.pk)
        self.assertEqual(response.data['tours_info'][0]['ultrasounds'][0]['result'], True)

        location = Location.objects.filter(sowAndPigletsCell__isnull=False).first()
        sow.change_sow_current_location(location)
        SowFarrow.objects.create_sow_farrow(sow=sow, alive_quantity=7, mummy_quantity=1)
        response = self.client.get('/api/sows/%s/' % sow.pk)
        self.assertEqual(response.data['tours_info'][0]['farrows'][0]['alive_quantity'], 7)
        
        Semination.objects.create_semination(sow=sow, week=2,
         initiator=self.user, semination_employee=self.user, boar=boar)
        response = self.client.get('/api/sows/%s/' % sow.pk)
        self.assertEqual(response.data['tours_info'][1]['seminations'][0]['semination_employee'],
            self.user.pk)

        Ultrasound.objects.create_ultrasound(sow, self.user, False)
        response = self.client.get('/api/sows/%s/' % sow.pk)
        self.assertEqual(response.data['tours_info'][1]['ultrasounds'][0]['result'], False)
        self.client.logout()
Пример #16
0
    def test_model_change_group_to_restrict2(self):
        # should not create new records if С опоросом already
        sow1 = sows_testings.create_sow_and_put_in_workshop_one()

        sow1.change_group_to('Ремонтная')
        sow1.change_group_to('Проверяемая')
        sow1.change_group_to('С опоросом')
        sow1.refresh_from_db()
        self.assertEqual(sow1.sow_group.title, 'С опоросом')
        self.assertEqual(sow1.group_records.all().count(), 3)

        sow1_group_record = sow1.group_records.all().first()
        self.assertEqual(sow1_group_record.group_before.title, 'Проверяемая')
        self.assertEqual(sow1_group_record.group_after.title, 'С опоросом') 

        sow1.change_group_to('С опоросом')
        sow1.refresh_from_db()
        self.assertEqual(sow1.sow_group.title, 'С опоросом')
        self.assertEqual(sow1.group_records.all().count(), 3)

        sow1_group_record = sow1.group_records.all().first()
        self.assertEqual(sow1_group_record.group_before.title, 'Проверяемая')
        self.assertEqual(sow1_group_record.group_after.title, 'С опоросом')
Пример #17
0
    def test_create_sow_and_put_in_workshop_one(self):
        sow = sows_testing.create_sow_and_put_in_workshop_one(1, '100')

        self.assertEqual(sow.location.sowSingleCell.number, '100')
Пример #18
0
 def test_move_to_permissions_401(self):
     sow1 = sows_testing.create_sow_and_put_in_workshop_one()
     response = self.client.post('/api/workshoponetwo/sows/%s/move_to/' % sow1.pk,
      {'location': self.loc_ws2})
     self.assertEqual(response.status_code, 401)
Пример #19
0
 def test_culling_permissions_401(self):
     sow1 = sows_testing.create_sow_and_put_in_workshop_one()
     response = self.client.post('/api/workshoponetwo/sows/%s/culling/' % sow1.pk,
      {'culling_type': 'padej', 'reason': 'test', 'weight': 150})
     self.assertEqual(response.status_code, 401)
Пример #20
0
 def test_abortion_permissions_403(self):
     self.client.force_authenticate(user=self.brig3)
     sow1 = sows_testing.create_sow_and_put_in_workshop_one()
     response = self.client.post('/api/workshoponetwo/sows/%s/abortion/' % sow1.pk)
     self.assertEqual(response.status_code, 403)
     self.client.logout()
Пример #21
0
 def test_abortion_permissions_401(self):
     sow1 = sows_testing.create_sow_and_put_in_workshop_one()
     response = self.client.post('/api/workshoponetwo/sows/%s/abortion/' % sow1.pk)
     self.assertEqual(response.status_code, 401)