コード例 #1
0
    def test_repeated_seminations_v3(self):
        # файл с более поздними осеменениями. По факту узи есть в файле нет.
        wb = open_workbook('../data/seminations2.xls')
        rows = import_farm.get_semenation_rows(wb)
        shmigina = staff_testings.create_employee('ШМЫГИ')

        seminated_list, already_seminated_in_tour, sows_in_another_tour, proholost_list = \
            import_farm.create_semination_lists(rows, shmigina)

        self.assertEqual(Sow.objects.filter(tour__week_number=6).count(), 75)
        self.assertEqual(Sow.objects.filter(tour__week_number=7).count(), 75)

        # We have done usound by hand. Then FARM update file.
        # sow.farm_id = 20095 - usound - false by hand. file updated. tour 7
        sow = Sow.objects.filter(farm_id=20095).first()
        Ultrasound.objects.create_ultrasound(sow=sow,
                                             result=False,
                                             initiator=shmigina)

        wb = open_workbook('../data/seminations2_custom_uzi.xls')
        rows = import_farm.get_semenation_rows(wb)
        shmigina = staff_testings.create_employee('ШМЫГИ')

        seminated_list, already_seminated_in_tour, sows_in_another_tour, proholost_list = \
            import_farm.create_semination_lists(rows, shmigina)

        self.assertEqual(Sow.objects.filter(tour__week_number=6).count(), 75)
        self.assertEqual(Sow.objects.filter(tour__week_number=7).count(), 74)

        self.assertEqual(Ultrasound.objects.filter(sow=sow).count(), 1)
コード例 #2
0
 def test_get_seminator_by_farm_name(self):
     shmigina = staff_testings.create_employee('ШМЫГИ')
     ivanov = staff_testings.create_employee('ИВАНО')
     s***n = staff_testings.create_employee('СЕМЕН')
     boris = staff_testings.create_employee('БОРИС')
     
     user = WorkShopEmployee.objects.get_seminator_by_farm_name('ШМЫГИ')
     self.assertEqual(user, shmigina)
コード例 #3
0
    def setUp(self):
        self.client = APIClient()
        locations_testing.create_workshops_sections_and_cells()
        sows_testing.create_statuses()
        piglets_testing.create_piglets_statuses()
        sows_events_testings.create_types()

        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.loc_ws3 = Location.objects.get(workshop__number=3)
        self.loc_ws3_cells = Location.objects.filter(
            sowAndPigletsCell__isnull=False)

        self.ops_dict = gen_operations_dict()

        operations = dict()
        for op_key in self.ops_dict.keys():
            operations[op_key] = False

        self.request_json = {
            'operations': operations,
            'filters': {
                'start_date': None,
                'end_date': None,
                'farm_id': None
            },
            'target': None
        }
コード例 #4
0
 def setUp(self):
     self.client = APIClient()
     locations_testing.create_workshops_sections_and_cells()
     sows_testing.create_statuses()
     sows_testing.create_boars()
     sows_events_testing.create_types()
     piglets_testing.create_piglets_statuses()
     staff_testing.create_svinbin_users()
     self.user = staff_testing.create_employee()
     self.brig3 = User.objects.get(username='******')
     self.tour1 = Tour.objects.get_or_create_by_week_in_current_year(1)
コード例 #5
0
    def test_culling_brig2(self):
        self.client.force_authenticate(user=self.brig2)
        sow = sows_testing.create_sow_and_put_in_workshop_one()
        semination_employee = staff_testing.create_employee()

        response = self.client.post('/api/workshoponetwo/sows/%s/culling/' %
          sow.pk, {'culling_type': 'padej', 'reason': 'test reason', 'weight': 150})

        self.assertEqual(response.data['culling']['reason'], 'test reason')
        self.assertEqual(response.data['sow']['status'], 'Брак')
        self.client.logout()
コード例 #6
0
    def test_repeated_seminations_v4(self):
        # файл с более поздними осеменениями. По факту узи есть в файле нет.
        wb = open_workbook('../data/seminations2.xls')
        rows = import_farm.get_semenation_rows(wb)
        shmigina = staff_testings.create_employee('ШМЫГИ')

        seminated_list, already_seminated_in_tour, sows_in_another_tour, proholost_list = \
            import_farm.create_semination_lists(rows, shmigina)

        self.assertEqual(Sow.objects.filter(tour__week_number=6).count(), 75)
        self.assertEqual(Sow.objects.filter(tour__week_number=7).count(), 75)

        sow = Sow.objects.filter(farm_id=20095).first().delete()

        wb = open_workbook('../data/seminations2.xls')
        rows = import_farm.get_semenation_rows(wb)
        shmigina = staff_testings.create_employee('ШМЫГИ')

        seminated_list, already_seminated_in_tour, sows_in_another_tour, proholost_list = \
            import_farm.create_semination_lists(rows, shmigina)
コード例 #7
0
    def test_repeated_seminations(self):
        wb = open_workbook('../data/seminations2.xls')
        rows = import_farm.get_semenation_rows(wb)
        shmigina = staff_testings.create_employee('ШМЫГИ')

        seminated_list, already_seminated_in_tour, sows_in_another_tour, proholost_list = \
            import_farm.create_semination_lists(rows, shmigina)

        self.assertEqual(Sow.objects.filter(tour__week_number=6).count(), 75)
        sow = Sow.objects.get(farm_id=19403)
        self.assertEqual(sow.birth_id, 'A0278')
コード例 #8
0
    def test_double_semination_or_not(self):
        sow = Sow.objects.create_new_and_put_in_workshop_one(1)

        shmigina = staff_testings.create_employee('ШМЫГИ')
        ivanov = staff_testings.create_employee('ИВАНО')

        boar1 = Boar.objects.get_or_create_boar(123)
        boar2 = Boar.objects.get_or_create_boar(124)

        date = timezone.now()
        tour = Tour.objects.get_or_create_by_week_in_current_year(50)

        sow, seminated = Semination.objects.double_semination_or_not(
            sow=sow,
            tour=tour,
            date=date,
            boar1=boar1,
            boar2=boar2,
            semination_employee1=shmigina,
            semination_employee2=ivanov,
            initiator=None)
        self.assertEqual(seminated, True)

        is_there_semination1 = Semination.objects.is_there_semination(
            sow, tour)
        self.assertEqual(is_there_semination1, True)
        self.assertEqual(
            Semination.objects.filter(sow=sow, tour=tour).count(), 2)

        # already seminated in tour
        sow, seminated = Semination.objects.double_semination_or_not(
            sow=sow,
            tour=tour,
            date=date,
            boar1=boar1,
            boar2=boar2,
            semination_employee1=shmigina,
            semination_employee2=ivanov,
            initiator=None)
        self.assertEqual(seminated, False)
コード例 #9
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)
コード例 #10
0
    def setUp(self):
        self.client = APIClient()
        locations_testing.create_workshops_sections_and_cells()
        sows_testing.create_statuses()
        sows_testing.create_boars()
        sows_events_testing.create_types()
        staff_testing.create_svinbin_users()
        self.boar = Boar.objects.all().first()
        self.user = staff_testing.create_employee() # is_seminator = True

        self.brig1 = User.objects.get(username='******')
        self.brig2 = User.objects.get(username='******')
        self.brig3 = User.objects.get(username='******')
        self.brig4 = User.objects.get(username='******')
        self.brig5 = User.objects.get(username='******')
コード例 #11
0
    def setUp(self):
        self.client = APIClient()
        locations_testing.create_workshops_sections_and_cells()
        sows_testing.create_statuses()
        piglets_testing.create_piglets_statuses()
        sows_events_testings.create_types()

        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)
コード例 #12
0
    def setUp(self):
        self.client = APIClient()
        locations_testing.create_workshops_sections_and_cells()
        sows_testing.create_statuses()
        piglets_testing.create_piglets_statuses()
        sows_events_testings.create_types()
        staff_testing.create_svinbin_users()

        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.tour4 = Tour.objects.get_or_create_by_week_in_current_year(week_number=4)

        self.loc_ws1 = Location.objects.get(workshop__number=1)
        self.loc_ws2 = Location.objects.get(workshop__number=2)

        self.loc_ws3 = Location.objects.get(workshop__number=3)
        self.loc_ws3_sec1 = Location.objects.get(section__workshop__number=3, section__number=1)
        self.loc_ws3_sec2 = Location.objects.get(section__workshop__number=3, section__number=2)

        self.loc_ws4 = Location.objects.get(workshop__number=4)
        self.loc_ws4_cell1 = Location.objects.filter(pigletsGroupCell__isnull=False)[0]
        self.loc_ws4_cell2 = Location.objects.filter(pigletsGroupCell__isnull=False)[1]

        self.loc_ws8 = Location.objects.get(workshop__number=8)

        self.loc_ws5 = Location.objects.get(workshop__number=5)
        self.loc_ws6 = Location.objects.get(workshop__number=6)
        self.loc_ws7 = Location.objects.get(workshop__number=7)

        # self.user = staff_testing.create_employee()
        # self.client.force_authenticate(user=self.user)

        self.brig1 = staff_testing.create_employee(workshop=self.loc_ws1.workshop)
        self.brig2 = staff_testing.create_employee(workshop=self.loc_ws2.workshop)
        self.brig3 = staff_testing.create_employee(workshop=self.loc_ws3.workshop)
        self.brig4 = staff_testing.create_employee(workshop=self.loc_ws4.workshop)
        self.brig5 = staff_testing.create_employee(workshop=self.loc_ws5.workshop)
        self.brig6 = staff_testing.create_employee(workshop=self.loc_ws6.workshop)
        self.brig7 = staff_testing.create_employee(workshop=self.loc_ws7.workshop)
        self.brig8 = staff_testing.create_employee(workshop=self.loc_ws8.workshop)

        self.admin = User.objects.get(username='******')
コード例 #13
0
    def setUp(self):
        self.client = APIClient()
        locations_testing.create_workshops_sections_and_cells()
        sows_testing.create_statuses()
        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.tour4 = Tour.objects.get_or_create_by_week_in_current_year(week_number=4)
        self.loc_ws3 = Location.objects.get(workshop__number=3)
        self.loc_ws3_sec1 = Location.objects.get(section__workshop__number=3, section__number=1)
        self.loc_ws3_sec2 = Location.objects.get(section__workshop__number=3, section__number=2)

        self.loc_ws4 = Location.objects.get(workshop__number=4)
        self.loc_ws4_cell1 = Location.objects.filter(pigletsGroupCell__isnull=False)[0]
        self.loc_ws4_cell2 = Location.objects.filter(pigletsGroupCell__isnull=False)[1]
コード例 #14
0
    def setUp(self):
        self.client = APIClient()
        locations_testing.create_workshops_sections_and_cells()
        sows_testing.create_statuses()
        piglets_testing.create_piglets_statuses()
        sows_events_testings.create_types()

        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.loc_ws4 = Location.objects.get(workshop__number=4)
        self.loc_ws5_cells = Location.objects.filter(
            pigletsGroupCell__workshop__number=5)
        self.loc_ws3_cells = Location.objects.filter(
            sowAndPigletsCell__workshop__number=3)
コード例 #15
0
    def setUp(self):
        locations_testing.create_workshops_sections_and_cells()
        sows_testing.create_statuses()
        sows_events_testings.create_types()
        piglets_testing.create_piglets_statuses()
        staff_testing.create_svinbin_users()
        self.client = APIClient()
        self.user = staff_testing.create_employee()
        self.brig1 = User.objects.get(username='******')
        self.brig2 = User.objects.get(username='******')
        self.brig3 = User.objects.get(username='******')
        self.brig4 = User.objects.get(username='******')
        self.brig5 = User.objects.get(username='******')

        self.loc_ws1 = Location.objects.get(workshop__number=1)
        self.loc_ws2 = Location.objects.get(workshop__number=2)

        self.loc_ws3 = Location.objects.get(workshop__number=3)
        self.loc_ws3_sec1 = Location.objects.get(section__workshop__number=3,
                                                 section__number=1)
        self.loc_ws3_sec2 = Location.objects.get(section__workshop__number=3,
                                                 section__number=2)
コード例 #16
0
    def setUp(self):
        self.client = APIClient()
        locations_testing.create_workshops_sections_and_cells()
        sows_testing.create_statuses()
        sows_testing.create_boars()
        sows_events_testing.create_types()
        piglets_testing.create_piglets_statuses()
        staff_testing.create_svinbin_users()
        self.user = staff_testing.create_employee()
        self.boar = Boar.objects.all().first()

        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.tour4 = Tour.objects.get_or_create_by_week_in_current_year(week_number=4)

        self.loc_ws1 = Location.objects.get(workshop__number=1)
        self.loc_ws2 = Location.objects.get(workshop__number=2)

        self.loc_ws3 = Location.objects.get(workshop__number=3)
        self.loc_ws3_sec1 = Location.objects.get(section__workshop__number=3, section__number=1)
        self.loc_ws3_sec2 = Location.objects.get(section__workshop__number=3, section__number=2)

        self.loc_ws4 = Location.objects.get(workshop__number=4)
        self.loc_ws4_cell1 = Location.objects.filter(pigletsGroupCell__isnull=False)[0]
        self.loc_ws4_cell2 = Location.objects.filter(pigletsGroupCell__isnull=False)[1]

        self.loc_ws8 = Location.objects.get(workshop__number=8)

        self.loc_ws5 = Location.objects.get(workshop__number=5)
        self.loc_ws6 = Location.objects.get(workshop__number=6)
        self.loc_ws7 = Location.objects.get(workshop__number=7)

        self.brig1 = User.objects.get(username='******')
        self.brig2 = User.objects.get(username='******')
        self.brig3 = User.objects.get(username='******')
        self.brig4 = User.objects.get(username='******')
        self.brig5 = User.objects.get(username='******')
コード例 #17
0
    def test_create_semination_lists(self):
        shmigina = staff_testings.create_employee('ШМЫГИ')
        ivanov = staff_testings.create_employee('ИВАНО')
        s***n = staff_testings.create_employee('СЕМЕН')
        boris = staff_testings.create_employee('БОРИС')

        # all new sows
        rows1 = [
            [1, '1a', 1, '1924',
             timezone.now(), 1, 'ШМЫГИ', 2, 'ШМЫГИ'],
            [2, '2a', 1, '1924',
             timezone.now(), 12, 'БОРИС', 23, 'БОРИС'],
            [3, '3a', 1, '1924',
             timezone.now(), 13, 'СЕМЕН', 24, 'СЕМЕН'],
            [4, '4a', 1, '1924',
             timezone.now(), 14, 'ШМЫГИ', 25, 'ШМЫГИ'],
        ]

        seminated_list, already_seminated_in_tour, sows_in_another_tour, proholost_list = \
            import_farm.create_semination_lists(rows1, shmigina)

        monday_24_week = Tour.objects.get_monday_date_by_week_number(
            week_number=24, year=2019)
        self.assertEqual(seminated_list[0].tour.week_number, 24)
        self.assertEqual(len(seminated_list), 4)
        self.assertEqual(len(already_seminated_in_tour), 0)
        self.assertEqual(len(sows_in_another_tour), 0)

        # sows already seminated in tour
        rows2 = [
            [1, '1a', 1, '1924',
             timezone.now(), 1, 'ШМЫГИ', 2, 'ШМЫГИ'],
            [2, '2a', 1, '1924',
             timezone.now(), 12, 'БОРИС', 23, 'БОРИС'],
            [3, '3a', 1, '1924',
             timezone.now(), 13, 'СЕМЕН', 24, 'СЕМЕН'],
            [4, '4a', 1, '1924',
             timezone.now(), 14, 'ШМЫГИ', 25, 'ШМЫГИ'],
        ]

        seminated_list, already_seminated_in_tour, sows_in_another_tour, proholost_list = \
            import_farm.create_semination_lists(rows2, shmigina)

        self.assertEqual(len(seminated_list), 0)
        self.assertEqual(len(already_seminated_in_tour), 4)
        self.assertEqual(len(sows_in_another_tour), 0)

        # sows in another tour still
        rows3 = [
            [1, '1a', 1, '1923',
             timezone.now(), 1, 'ШМЫГИ', 2, 'ШМЫГИ'],
            [2, '2a', 1, '1923',
             timezone.now(), 12, 'БОРИС', 23, 'БОРИС'],
            [3, '3a', 1, '1923',
             timezone.now(), 13, 'СЕМЕН', 24, 'СЕМЕН'],
            [4, '4a', 1, '1923',
             timezone.now(), 14, 'ШМЫГИ', 25, 'ШМЫГИ'],
        ]

        seminated_list, already_seminated_in_tour, sows_in_another_tour, proholost_list = \
            import_farm.create_semination_lists(rows3, shmigina)

        self.assertEqual(len(seminated_list), 0)
        self.assertEqual(len(already_seminated_in_tour), 0)
        self.assertEqual(len(sows_in_another_tour), 4)

        # mixed
        rows4 = [
            [1, '1a', 1, '1924',
             timezone.now(), 1, 'ШМЫГИ', 2, 'ШМЫГИ'],
            [2, '2a', 1, '1924',
             timezone.now(), 12, 'БОРИС', 23, 'БОРИС'],
            [3, '3a', 1, '1924',
             timezone.now(), 13, 'СЕМЕН', 24, 'СЕМЕН'],
            [4, '4a', 1, '1923',
             timezone.now(), 14, 'ШМЫГИ', 25, 'ШМЫГИ'],
            [5, '5a', 1, '1924',
             timezone.now(), 14, 'ШМЫГИ', 25, 'ШМЫГИ'],
        ]

        seminated_list, already_seminated_in_tour, sows_in_another_tour, proholost_list = \
            import_farm.create_semination_lists(rows4, shmigina)

        self.assertEqual(len(seminated_list), 1)
        self.assertEqual(len(already_seminated_in_tour), 3)
        self.assertEqual(len(sows_in_another_tour), 1)