示例#1
0
    def test_gen_megadict_two_operations_filter_sow(self):
        request_json = copy.deepcopy(self.request_json)
        request_json['operations']['ws1_semination'] = True
        request_json['operations']['ws3_piglets_padej'] = True

        sow1 = sows_testings.create_sow_with_semination_usound(
            location=self.loc_ws1, week=22)
        sow2 = sows_testings.create_sow_with_semination_usound(
            location=self.loc_ws1, week=22)

        date_10d_ago = timezone.now() - timedelta(10)
        sow3 = sows_testings.create_sow_with_semination_usound(
            location=self.loc_ws1, week=22, date=date_10d_ago)
        sow4 = sows_testings.create_sow_with_semination_usound(
            location=self.loc_ws3_cells[0], week=22, date=date_10d_ago)

        farrow = SowFarrow.objects.create_sow_farrow(sow=sow4,
                                                     alive_quantity=10,
                                                     date=date_10d_ago)
        piglets = farrow.piglets_group

        CullingPiglets.objects.create_culling_piglets(piglets_group=piglets,
                                                      culling_type='padej',
                                                      date=date_10d_ago)

        request_json['filters']['farm_id'] = sow1.farm_id

        megalist = gen_megadict(request_json)['results']
        self.assertEqual(len(megalist), 1)
        self.assertEqual(megalist[0]['sow'], sow1.farm_id)
示例#2
0
    def test_add_piglets_target_date_quantity_v4(self):
        # calc at date
        for i in range(0, 20):
            piglets_testing.create_new_group_with_metatour_by_one_tour(
                self.tour1, self.loc_ws1, 10)

        piglets = Piglets.objects.all()
        for i in range(0, 5):
            CullingPiglets.objects.create_culling_piglets(
                piglets_group=piglets[i], culling_type='padej', quantity=2)

        sow = sows_testings.create_sow_with_semination_usound(
            self.loc_ws3_cells[0])
        SowFarrow.objects.create_sow_farrow(sow=sow, alive_quantity=15)

        past_date = timezone.now().date() - timedelta(10)
        for i in range(6, 9):
            CullingPiglets.objects.create_culling_piglets(
                piglets_group=piglets[i],
                culling_type='padej',
                quantity=2,
                date=past_date)

        target_date = timezone.now().date() - timedelta(5)
        sow2 = sows_testings.create_sow_with_semination_usound(
            self.loc_ws3_cells[1])
        SowFarrow.objects.create_sow_farrow(sow=sow2,
                                            alive_quantity=13,
                                            date=target_date)

        CullingPiglets.objects.create_culling_piglets(piglets_group=piglets[0],
                                                      culling_type='spec',
                                                      quantity=4,
                                                      date=target_date,
                                                      total_weight=43)
        CullingPiglets.objects.create_culling_piglets(piglets_group=piglets[1],
                                                      culling_type='spec',
                                                      quantity=3,
                                                      date=target_date,
                                                      total_weight=32)

        with self.assertNumQueries(1):
            rds = ReportDate.objects.all() \
                    .add_piglets_padej_qnty() \
                    .add_piglets_prirezka_qnty() \
                    .add_piglets_vinuzhd_qnty() \
                    .add_piglets_spec_qnty() \
                    .add_piglets_spec_total_weight() \
                    .add_born_alive() \
                    .add_piglets_today_quantity() \
                    .add_piglets_quantity_at_date_start() \
                    .add_piglets_quantity_at_date_end() \
                    .filter(date=target_date)
            bool(rds)
            self.assertEqual(rds[0].piglets_today_qnty, 200)
            self.assertEqual(rds[0].piglets_qnty_start_date, 194)
            self.assertEqual(rds[0].piglets_qnty_start_end, 200)
            self.assertEqual(rds[0].piglets_spec_total_weight, 75)
            self.assertEqual(rds[0].piglets_spec_qnty, 7)
示例#3
0
    def test_serializer_queries(self):
        cells = Location.objects.filter(sowAndPigletsCell__isnull=False)
        sow = sows_testing.create_sow_with_semination_usound(cells[0], 1)
        farrow = SowFarrow.objects.create_sow_farrow(sow=sow,
                                                     alive_quantity=10)
        piglets = farrow.piglets_group
        gilt1 = Gilt.objects.create_gilt(birth_id='1a',
                                         mother_sow_farm_id=sow.farm_id,
                                         piglets=piglets)
        MarkAsGilt.objects.create_init_gilt_event(gilt=gilt1)
        gilt2 = Gilt.objects.create_gilt(birth_id='2a',
                                         mother_sow_farm_id=sow.farm_id,
                                         piglets=piglets)
        MarkAsGilt.objects.create_init_gilt_event(gilt=gilt2)

        sow2 = sows_testing.create_sow_with_semination_usound(cells[1], 1)
        farrow2 = SowFarrow.objects.create_sow_farrow(sow=sow2,
                                                      alive_quantity=10)
        piglets2 = farrow2.piglets_group
        gilt3 = Gilt.objects.create_gilt(birth_id='3a',
                                         mother_sow_farm_id=sow2.farm_id,
                                         piglets=piglets2)
        MarkAsGilt.objects.create_init_gilt_event(gilt=gilt3)
        gilt4 = Gilt.objects.create_gilt(birth_id='4a',
                                         mother_sow_farm_id=sow2.farm_id,
                                         piglets=piglets2)
        MarkAsGilt.objects.create_init_gilt_event(gilt=gilt4)

        sow3 = sows_testing.create_sow_with_semination_usound(cells[2], 1)
        farrow3 = SowFarrow.objects.create_sow_farrow(sow=sow3,
                                                      alive_quantity=10)
        piglets3 = farrow3.piglets_group
        gilt5 = Gilt.objects.create_gilt(birth_id='5a',
                                         mother_sow_farm_id=sow3.farm_id,
                                         piglets=piglets3)
        MarkAsGilt.objects.create_init_gilt_event(gilt=gilt5)
        gilt6 = Gilt.objects.create_gilt(birth_id='6a',
                                         mother_sow_farm_id=sow3.farm_id,
                                         piglets=piglets3)
        MarkAsGilt.objects.create_init_gilt_event(gilt=gilt6)

        mag_qs = MarkAsGilt.objects.all().select_related('gilt', 'sow', 'tour') \
            .order_by('-date')

        sows_pk_list = mag_qs.values_list('sow__pk', flat=True)

        sows_qs = Sow.objects.get_queryset_with_not_alive() \
            .filter(pk__in=sows_pk_list) \
            .add_mark_as_gilt_last_date_and_last_tour() \
            .order_by('-last_date_mark')

        with self.assertNumQueries(1):
            serializer = SowMarkAsGiltSerializer(sows_qs, many=True)
            serializer.data
示例#4
0
    def setUp(self):
        self.client = APIClient()
        locations_testing.create_workshops_sections_and_cells()
        sows_testing.create_statuses()
        sows_events_testing.create_types()
        piglets_testing.create_piglets_statuses()
        self.user = staff_testing.create_employee()
        self.client.force_authenticate(user=self.user)

        self.tour1 = Tour.objects.get_or_create_by_week_in_current_year(
            week_number=1)
        self.tour2 = Tour.objects.get_or_create_by_week_in_current_year(
            week_number=2)
        self.tour3 = Tour.objects.get_or_create_by_week_in_current_year(
            week_number=3)
        self.loc_ws3 = Location.objects.get(workshop__number=3)
        self.piglets = piglets_testing.create_new_group_with_metatour_by_one_tour(
            self.tour1, self.loc_ws3, 101)

        location1 = Location.objects.filter(
            sowAndPigletsCell__number=1).first()
        sow1 = sows_testing.create_sow_with_semination_usound(
            location=location1, week=1)

        location2 = Location.objects.filter(
            sowAndPigletsCell__number=2).first()
        sow2 = sows_testing.create_sow_with_semination_usound(
            location=location2, week=1)

        location3 = Location.objects.filter(
            sowAndPigletsCell__number=3).first()
        sow3 = sows_testing.create_sow_with_semination_usound(
            location=location3, week=1)

        SowFarrow.objects.create_sow_farrow(sow=sow1, alive_quantity=10)
        SowFarrow.objects.create_sow_farrow(sow=sow2, alive_quantity=10)
        SowFarrow.objects.create_sow_farrow(sow=sow3, alive_quantity=10)

        location8 = Location.objects.filter(
            pigletsGroupCell__isnull=False).first()
        Piglets.objects.init_piglets_by_farrow_date('2020-01-01', location8,
                                                    20)

        location9 = Location.objects.filter(pigletsGroupCell__isnull=False)[1]
        Piglets.objects.init_piglets_by_farrow_date('2020-01-02', location9,
                                                    21)

        location10 = Location.objects.filter(
            pigletsGroupCell__section__number=2).first()
        Piglets.objects.init_piglets_by_farrow_date('2020-01-02', location10,
                                                    53)
示例#5
0
    def test_add_piglets_today_quantity_v2(self):
        # cullings and farrows today
        for i in range(0, 20):
            piglets_testing.create_new_group_with_metatour_by_one_tour(
                self.tour1, self.loc_ws1, 10)

        piglets = Piglets.objects.all()
        for i in range(0, 5):
            CullingPiglets.objects.create_culling_piglets(
                piglets_group=piglets[i], culling_type='padej', quantity=2)

        self.assertEqual(CullingPiglets.objects.all().count(), 5)
        self.assertEqual(CullingPiglets.objects.all() \
            .aggregate(qnty=models.Sum('quantity'))['qnty'], 10)

        sow = sows_testings.create_sow_with_semination_usound(
            self.loc_ws3_cells[0])
        SowFarrow.objects.create_sow_farrow(sow=sow, alive_quantity=15)

        self.assertEqual(
            piglets.aggregate(qnty=models.Sum('quantity'))['qnty'], 205)

        with self.assertNumQueries(1):
            rds = ReportDate.objects.all() \
                    .add_piglets_today_quantity()
            bool(rds)
            # 205 + 10 - 15
            self.assertEqual(rds[0].piglets_today_qnty, 200)
示例#6
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()
示例#7
0
    def test_create_gilt_permissions(self):
        location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow = sows_testing.create_sow_with_semination_usound(location, 1)
        farrow = SowFarrow.objects.create_sow_farrow(sow=sow, alive_quantity=10)
        piglets = farrow.piglets_group

        self.client.force_authenticate(user=self.brig4)
        response = self.client.post('/api/piglets/%s/create_gilt/' % piglets.pk,
            {'mother_sow_farm_id': sow.farm_id, 'birth_id': '1s'})
        self.assertEqual(response.status_code, 403)
        self.client.logout()
示例#8
0
    def test_add_sows_count_by_sections(self):
        location8 = Location.objects.filter(
            sowAndPigletsCell__number=8).first()
        sow8 = sows_testing.create_sow_with_semination_usound(
            location=location8, week=5)

        location9 = Location.objects.filter(
            sowAndPigletsCell__number=9).first()
        sow9 = sows_testing.create_sow_with_semination_usound(
            location=location9, week=5)
        sow9.alive = False
        sow9.save()

        with self.assertNumQueries(1):
            locs = Location.objects \
                .filter(section__workshop__number=3, section__isnull=False) \
                .add_sows_count_by_sections()

            bool(locs)
            self.assertEqual(locs[0].sows_count, 8)
示例#9
0
    def test_create_gilt(self):
        location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow = sows_testing.create_sow_with_semination_usound(location, 1)
        farrow = SowFarrow.objects.create_sow_farrow(sow=sow, alive_quantity=10)
        piglets = farrow.piglets_group

        self.client.force_authenticate(user=self.brig3)
        response = self.client.post('/api/piglets/%s/create_gilt/' % piglets.pk,
            {'mother_sow_farm_id': sow.farm_id, 'birth_id': '1s'})
        self.assertEqual(response.data['message'], 'Ремонтная свинка создана успешно.')
        self.client.logout()
示例#10
0
    def test_create_farrow_without_tour(self):
        location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow1 = sows_testing.create_sow_with_semination_usound(
            location=location, week=1)
        sow1.tour = None
        sow1.save()

        with self.assertRaises(ValidationError):
            farrow = SowFarrow.objects.create_sow_farrow(sow=sow1,
                                                         alive_quantity=10,
                                                         dead_quantity=1)
示例#11
0
    def test_op_usound_serializer(self):
        initiator = User.objects.get(username='******')
        location = Location.objects.filter(workshop__number=1).first()
        sow1 = sows_testings.create_sow_with_semination_usound(
            location=location, week=1)
        usound = sow1.ultrasound_set.all().select_related('u_type')[1]

        qs = self.ops_dict['ws1_usound']['qs']
        serializer = self.ops_dict['ws1_usound']['serializer']

        with self.assertNumQueries(1):
            serializer = serializer(qs, many=True)
            self.assertEqual(serializer.data[0]['sow'], sow1.farm_id)
            self.assertEqual(serializer.data[0]['tour'], str(sow1.tour))
示例#12
0
    def test_create_gilt(self):
        # 1 cell 1 section
        location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow = sows_testings.create_sow_with_semination_usound(location, 1)
        farrow = SowFarrow.objects.create_sow_farrow(sow=sow, alive_quantity=10)
        piglets = farrow.piglets_group
        
        gilt = Gilt.objects.create_gilt(birth_id='1a', mother_sow_farm_id=sow.farm_id,
             piglets=piglets)

        self.assertEqual(gilt.mother_sow, sow)
        self.assertEqual(gilt.tour.week_number, 1)
        self.assertEqual(gilt.farrow, sow.get_last_farrow)
        self.assertEqual(piglets.gilts_quantity, 1)
示例#13
0
    def test_mark_as_gilt_qs(self):
        cells = Location.objects.filter(sowAndPigletsCell__isnull=False)
        sow = sows_testings.create_sow_with_semination_usound(cells[0], 1)
        farrow = SowFarrow.objects.create_sow_farrow(sow=sow, alive_quantity=10)
        piglets = farrow.piglets_group
        gilt1 = Gilt.objects.create_gilt(birth_id='1a', mother_sow_farm_id=sow.farm_id,
             piglets=piglets)
        mg1 = MarkAsGilt.objects.create_init_gilt_event(gilt=gilt1)
        gilt2 = Gilt.objects.create_gilt(birth_id='2a', mother_sow_farm_id=sow.farm_id,
             piglets=piglets)
        mg2 = MarkAsGilt.objects.create_init_gilt_event(gilt=gilt2)

        sow2 = sows_testings.create_sow_with_semination_usound(cells[1], 1)
        farrow2 = SowFarrow.objects.create_sow_farrow(sow=sow2, alive_quantity=10)
        piglets2 = farrow2.piglets_group
        gilt3 = Gilt.objects.create_gilt(birth_id='3a', mother_sow_farm_id=sow2.farm_id,
             piglets=piglets2)
        mg3 = MarkAsGilt.objects.create_init_gilt_event(gilt=gilt3)
        gilt4 = Gilt.objects.create_gilt(birth_id='4a', mother_sow_farm_id=sow2.farm_id,
             piglets=piglets2)
        mg4 = MarkAsGilt.objects.create_init_gilt_event(gilt=gilt4)

        sow3 = sows_testings.create_sow_with_semination_usound(cells[2], 1)
        farrow3 = SowFarrow.objects.create_sow_farrow(sow=sow3, alive_quantity=10)
        piglets3 = farrow3.piglets_group
        gilt5 = Gilt.objects.create_gilt(birth_id='5a', mother_sow_farm_id=sow3.farm_id,
             piglets=piglets3)
        mg5 = MarkAsGilt.objects.create_init_gilt_event(gilt=gilt5)
        gilt6 = Gilt.objects.create_gilt(birth_id='6a', mother_sow_farm_id=sow3.farm_id,
             piglets=piglets3)
        mg6 = MarkAsGilt.objects.create_init_gilt_event(gilt=gilt6)

        sows_qs = Sow.objects.get_queryset_with_not_alive()\
                             .add_mark_as_gilt_last_date_and_last_tour() \
                             .order_by('-last_date_mark')
        self.assertEqual(sows_qs.first().last_date_mark, mg6.date)
        self.assertEqual(sows_qs.first().last_week_mark, mg6.tour.week_number)
示例#14
0
def create_from_sow_farrow(tour, location, quantity=0, gilts_quantity=0, status=None, date=timezone.now()):
    sow1 = sows_testing.create_sow_with_semination_usound(location=location, week=tour.week_number)
    alive_quantity = 10

    if quantity > 0:
        alive_quantity = quantity

    farrow = SowFarrow.objects.create_sow_farrow(
        sow=sow1,
        alive_quantity=alive_quantity,
        dead_quantity=1,
        date=date
        )

    return farrow.piglets_group
示例#15
0
    def test_add_priplod_by_sow(self):
        for i in range(0, 5):
            sow = sows_testings.create_sow_with_semination_usound(
                self.loc_ws3_cells[i])
            SowFarrow.objects.create_sow_farrow(sow=sow,
                                                alive_quantity=(10 + i))

        with self.assertNumQueries(1):
            rds = ReportDate.objects.all() \
                    .add_born_alive() \
                    .add_priplod_by_sow() \
                    .order_by('-date')
            bool(rds)
            self.assertEqual(rds[0].born_alive, 60)
            self.assertEqual(rds[0].priplod_by_sow, 12)
示例#16
0
    def test_op_semination_serializer(self):
        initiator = User.objects.get(username='******')
        location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow1 = sows_testings.create_sow_with_semination_usound(
            location=location, week=1)
        semination = sow1.semination_set.all().select_related('boar').first()

        qs = self.ops_dict['ws1_semination']['qs']
        serializer = self.ops_dict['ws1_semination']['serializer']

        with self.assertNumQueries(1):
            serializer = serializer(qs, many=True)
            self.assertEqual(serializer.data[0]['sow'], sow1.farm_id)
            self.assertEqual(serializer.data[0]['tour'], str(sow1.tour))
            self.assertEqual(serializer.data[0]['boar'],
                             semination.boar.birth_id)
示例#17
0
    def test_create_farrow_v2(self):
        # there are another piglets in cell
        location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        piglets2 = piglets_testing.create_new_group_with_metatour_by_one_tour(
            self.tour2, location, 10)

        sow1 = sows_testing.create_sow_with_semination_usound(
            location=location, week=1)

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

        self.assertEqual(farrow.piglets_group.quantity, 10)
        self.assertEqual(location.piglets.all().count(), 1)
        new_piglets = location.piglets.all().first()
        self.assertEqual(new_piglets.metatour.records.all().count(), 2)
示例#18
0
    def test_gen_megadict_one_operation(self):
        request_json = copy.deepcopy(self.request_json)
        request_json['operations']['ws1_semination'] = True

        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=22)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=22)

        date_10d_ago = timezone.now() - timedelta(10)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=22,
                                                        date=date_10d_ago)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=22,
                                                        date=date_10d_ago)

        megalist = gen_megadict(request_json)['results']
        self.assertEqual(len(megalist), 4)
示例#19
0
    def test_create_gilt(self):
        # 1 cell 1 section
        location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow = sows_testing.create_sow_with_semination_usound(location, 1)
        farrow = SowFarrow.objects.create_sow_farrow(sow=sow,
                                                     alive_quantity=10)
        piglets = farrow.piglets_group

        gilt = Gilt.objects.create_gilt(birth_id='1a',
                                        mother_sow_farm_id=sow.farm_id,
                                        piglets=piglets)

        MarkAsGilt.objects.create_init_gilt_event(gilt=gilt)

        marks_as_gilt_event = MarkAsGilt.objects.all().first()

        self.assertEqual(marks_as_gilt_event.gilt, gilt)
        self.assertEqual(marks_as_gilt_event.sow, gilt.mother_sow)
        self.assertEqual(marks_as_gilt_event.tour, gilt.tour)
示例#20
0
    def test_queryset_serializer(self):
        location1 = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow1 = sows_testings.create_sow_with_semination_usound(location=location1, week=1)

        location2 = Location.objects.filter(sowAndPigletsCell__number=2).first()
        sow2 = sows_testings.create_sow_with_semination_usound(location=location2, week=1)

        location3 = Location.objects.filter(sowAndPigletsCell__number=3).first()
        sow3 = sows_testings.create_sow_with_semination_usound(location=location3, week=2)

        location4 = Location.objects.filter(sowAndPigletsCell__number=4).first()
        sow4 = sows_testings.create_sow_with_semination_usound(location=location4, week=2)

        location5 = Location.objects.filter(sowAndPigletsCell__number=5).first()
        sow5 = sows_testings.create_sow_with_semination_usound(location=location5, week=3)

        location6 = Location.objects.filter(sowAndPigletsCell__number=6).first()
        sow6 = sows_testings.create_sow_with_semination_usound(location=location6, week=4)

        location7 = Location.objects.filter(sowAndPigletsCell__number=6).first()
        sow7 = sows_testings.create_sow_with_semination_usound(location=location7, week=5)

        location8 = Location.objects.filter(workshop__number=2).first()
        sow8 = sows_testings.create_sow_with_semination_usound(location=location8, week=5)

        sows_qs = Sow.objects.filter(pk__in=[sow1.pk, sow2.pk, sow3.pk, sow4.pk, sow5.pk, sow6.pk, sow7.pk])

        with self.assertNumQueries(4):
            data = Sow.objects.all() \
                .select_related('location__workshop') \
                .select_related('location__sowAndPigletsCell__section', 'status', 'tour') \
                .prefetch_related('semination_set__tour') \
                .prefetch_related(
                    Prefetch(
                        'ultrasound_set',
                        queryset=Ultrasound.objects.all().select_related('u_type', 'tour'),
                    )
                )
            serializer = SowManySerializer(data, many=True)
            serializer.data
示例#21
0
    def test_op_sow_transaction_serializer(self):
        initiator = User.objects.get(username='******')
        location = Location.objects.filter(workshop__number=1).first()
        sow1 = sows_testings.create_sow_with_semination_usound(
            location=location, week=1)
        SowTransaction.objects.create_transaction(sow=sow1,
                                                  to_location=self.loc_ws3,
                                                  initiator=initiator)

        qs = self.ops_dict['w1_peregon_sow']['qs']
        serializer = self.ops_dict['w1_peregon_sow']['serializer']

        with self.assertNumQueries(1):
            serializer = serializer(qs, many=True)
            self.assertEqual(serializer.data[0]['from_location'], 'Цех 1')
            self.assertEqual(serializer.data[0]['to_location'], 'Цех 3')
            self.assertEqual(serializer.data[0]['sow'], sow1.farm_id)
            self.assertEqual(serializer.data[0]['tour'], str(sow1.tour))
            self.assertEqual(serializer.data[0]['initiator'],
                             initiator.username)
示例#22
0
    def test_gen_megadict_two_operations_filter_start_date(self):
        request_json = copy.deepcopy(self.request_json)
        request_json['operations']['ws1_semination'] = True
        request_json['operations']['ws1_usound'] = True
        request_json['filters']['start_date'] = timezone.now().date().strftime(
            "%Y-%m-%d")

        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=22)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=22)

        date_10d_ago = timezone.now() - timedelta(10)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=22,
                                                        date=date_10d_ago)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=22,
                                                        date=date_10d_ago)

        megalist = gen_megadict(request_json)['results']
        self.assertEqual(len(megalist), 6)
示例#23
0
    def test_op_sow_farrow_serializer(self):
        initiator = User.objects.get(username='******')
        location = Location.objects.filter(
            sowAndPigletsCell__number=1,
            sowAndPigletsCell__section__number=1).first()
        sow1 = sows_testings.create_sow_with_semination_usound(
            location=location, week=1)
        farrow = SowFarrow.objects.create_sow_farrow(sow=sow1,
                                                     alive_quantity=10,
                                                     dead_quantity=1,
                                                     initiator=initiator)

        qs = self.ops_dict['ws3_farrow']['qs']
        serializer = self.ops_dict['ws3_farrow']['serializer']

        with self.assertNumQueries(1):
            serializer = serializer(qs, many=True)
            self.assertEqual(serializer.data[0]['location'], '3/1/1')
            self.assertEqual(serializer.data[0]['sow'], sow1.farm_id)
            self.assertEqual(serializer.data[0]['tour'], str(sow1.tour))
            self.assertEqual(serializer.data[0]['initiator'],
                             initiator.username)
示例#24
0
    def test_create_weaning(self):
        location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow1 = sows_testing.create_sow_with_semination_usound(
            location=location, week=1)

        # first sow farrow in tour in section
        farrow = SowFarrow.objects.create_sow_farrow(sow=sow1,
                                                     alive_quantity=10,
                                                     dead_quantity=1)

        piglets = farrow.piglets_group

        weaning1 = sow1.weaningsow_set.create_weaning(sow=sow1,
                                                      piglets=piglets)

        self.assertEqual(weaning1.piglets, piglets)
        self.assertEqual(weaning1.sow, sow1)
        self.assertEqual(weaning1.quantity, piglets.quantity)

        sow1.refresh_from_db()
        # self.assertEqual(sow1.tour, None)
        self.assertEqual(sow1.status.title, 'Отъем')
示例#25
0
    def test_get_tours(self):
        location1 = Location.objects.filter(workshop__number=1).first()
        sow1 = sows_testings.create_sow_with_semination_usound(location=location1, week=1)
        sow2 = sows_testings.create_sow_with_semination_usound(location=location1, week=1)
        sow3 = sows_testings.create_sow_with_semination_usound(location=location1, week=2)

        location2 = Location.objects.filter(workshop__number=2).first()
        sow4 = sows_testings.create_sow_with_semination_usound(location=location2, week=2)
        sow5 = sows_testings.create_sow_with_semination_usound(location=location2, week=3)

        location6 = Location.objects.filter(sowAndPigletsCell__number=6).first()
        sow6 = sows_testings.create_sow_with_semination_usound(location=location6, week=4)
        location7 = Location.objects.filter(sowAndPigletsCell__number=6).first()
        sow7 = sows_testings.create_sow_with_semination_usound(location=location7, week=5)

        ws1_tours = Sow.objects.all().get_tours_pks(workshop_number=1)
        # self.assertEqual(ws1_tours[0], 1)
        # self.assertEqual(ws1_tours[1], 2)
        ws2_tours = Sow.objects.all().get_tours_pks(workshop_number=2)
        # self.assertEqual(ws2_tours[0], 2)
        # self.assertEqual(ws2_tours[1], 3)
        ws3_tours = Sow.objects.all().get_tours_pks(workshop_number=3)        
示例#26
0
    def test_create_farrow(self):
        location = Location.objects.filter(sowAndPigletsCell__number=1).first()
        sow1 = sows_testing.create_sow_with_semination_usound(
            location=location, week=1)

        # first sow farrow in tour in section
        farrow = SowFarrow.objects.create_sow_farrow(sow=sow1,
                                                     alive_quantity=10,
                                                     dead_quantity=1)

        self.assertEqual(farrow.piglets_group.quantity, 10)
        self.assertEqual(farrow.piglets_group.metatour.records.all().count(),
                         1)
        self.assertEqual(
            farrow.piglets_group.metatour.records.all().first().tour,
            sow1.tour)
        self.assertEqual(
            farrow.piglets_group.metatour.records.all().first().quantity, 10)
        self.assertEqual(
            farrow.piglets_group.metatour.records.all().first().percentage,
            100.0)

        self.assertEqual(farrow.alive_quantity, 10)
        self.assertEqual(farrow.dead_quantity, 1)
示例#27
0
    def test_gen_megadict_sort_by_opername(self):
        request_json = copy.deepcopy(self.request_json)
        request_json['operations']['ws1_semination'] = True
        request_json['operations']['ws1_usound'] = True

        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=21)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=21)

        date_10d_ago = timezone.now() - timedelta(10)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=22,
                                                        date=date_10d_ago)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=22,
                                                        date=date_10d_ago)

        date_15d_ago = timezone.now() - timedelta(15)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=23,
                                                        date=date_15d_ago)
        sows_testings.create_sow_with_semination_usound(location=self.loc_ws1,
                                                        week=23,
                                                        date=date_15d_ago)

        megalist = gen_megadict(request_json)['results']

        date1 = datetime.strptime(megalist[0]['date'], '%d-%m-%Y %H:%M:%S')
        date2 = datetime.strptime(megalist[-1]['date'], '%d-%m-%Y %H:%M:%S')

        self.assertEqual(date1 > date2, True)
示例#28
0
    def setUp(self):
        locations_testing.create_workshops_sections_and_cells()
        sows_testing.create_statuses()
        piglets_testing.create_piglets_statuses()
        sows_events_testing.create_types()

        self.ws3_cells = Location.objects.filter(
            sowAndPigletsCell__isnull=False)

        location1 = Location.objects.filter(
            sowAndPigletsCell__number=1).first()
        sow1 = sows_testing.create_sow_with_semination_usound(
            location=location1, week=1)
        location2 = Location.objects.filter(
            sowAndPigletsCell__number=2).first()
        sow2 = sows_testing.create_sow_with_semination_usound(
            location=location2, week=1)
        location3 = Location.objects.filter(
            sowAndPigletsCell__number=3).first()
        sow3 = sows_testing.create_sow_with_semination_usound(
            location=location3, week=2)
        location4 = Location.objects.filter(
            sowAndPigletsCell__number=4).first()
        sow4 = sows_testing.create_sow_with_semination_usound(
            location=location4, week=2)
        location5 = Location.objects.filter(
            sowAndPigletsCell__number=5).first()
        sow5 = sows_testing.create_sow_with_semination_usound(
            location=location5, week=3)
        location6 = Location.objects.filter(
            sowAndPigletsCell__number=6).first()
        sow6 = sows_testing.create_sow_with_semination_usound(
            location=location6, week=4)
        location7 = Location.objects.filter(
            sowAndPigletsCell__number=7).first()
        sow7 = sows_testing.create_sow_with_semination_usound(
            location=location7, week=5)

        SowFarrow.objects.create_sow_farrow(sow=sow1, alive_quantity=10)
        SowFarrow.objects.create_sow_farrow(sow=sow2, alive_quantity=10)
        SowFarrow.objects.create_sow_farrow(sow=sow3, alive_quantity=10)
        SowFarrow.objects.create_sow_farrow(sow=sow4, alive_quantity=10)
        SowFarrow.objects.create_sow_farrow(sow=sow5, alive_quantity=10)
        SowFarrow.objects.create_sow_farrow(sow=sow6, alive_quantity=10)
        SowFarrow.objects.create_sow_farrow(sow=sow7, alive_quantity=10)

        piglets3_7 = location7.piglets.all().first()
        piglets3_7.deactivate()

        location8 = Location.objects.filter(
            pigletsGroupCell__isnull=False).first()
        Piglets.objects.init_piglets_by_farrow_date('2020-01-01', location8,
                                                    20)

        location9 = Location.objects.filter(pigletsGroupCell__isnull=False)[1]
        Piglets.objects.init_piglets_by_farrow_date('2020-01-02', location9,
                                                    21)

        location10 = Location.objects.filter(
            pigletsGroupCell__section__number=2).first()
        Piglets.objects.init_piglets_by_farrow_date('2020-01-02', location10,
                                                    53)