Esempio n. 1
0
def create_rule(**fields):
    if not fields.get('device'):
        fields['device'] = create_device()

    limit_value_kwargs = {
        'right_digits': 2,
        'min_value': ceil(fields.get('device').min_value),
        'max_value': floor(fields.get('device').max_value)
    }
    fake_rule_fields = {
        'coefficient':
        fake.pyfloat(right_digits=2, min_value=0, max_value=1),
        'possible_deviation':
        fake.pyfloat(min_value=0, max_value=10),
        'time_interval':
        timedelta(hours=fake.pyint(max_value=24),
                  minutes=fake.pyint(max_value=60)),
        **{
            k: v
            for k, v in zip(['min_value', 'max_value'],
                            sorted([
                                fake.pyfloat(**limit_value_kwargs),
                                fake.pyfloat(**limit_value_kwargs)
                            ]))
        }
    }

    if not fields.get('freight'):
        fields['freight'] = create_freight()

    for field, value in fake_rule_fields.items():
        if field not in fields:
            fields[field] = value

    return Rule.objects.create(**fields)
    def setUp(self) -> None:
        self.device = create_device()
        self.freight = create_freight(need_transfer=True)
        self.rule = create_rule(device=self.device, freight=self.freight)

        not_valid_max_value = fake.pyfloat(right_digits=2, min_value=ceil(self.device.max_value))

        self.valid_partial_data = {
            'max_value': fake.pyfloat(right_digits=2, min_value=ceil(self.rule.min_value),
                                      max_value=floor(self.device.max_value))
        }
        self.invalid_partial_data = {
            'max_value': not_valid_max_value
        }
        self.valid_data = {
            'coefficient': self.rule.coefficient,
            'possible_deviation': fake.pyfloat(right_digits=2, min_value=0, max_value=10),
            'time_interval': self.rule.time_interval,
            'device': self.device.id,
            'freight': self.freight.id,
            'min_value': self.rule.min_value,
            'max_value': self.rule.max_value,
        }

        self.invalid_data = {
            **self.valid_data,
            'min_value': self.valid_data['max_value'],
            'max_value': self.valid_data['min_value'],
        }

        self.rule_detail_url = reverse('freights:rule-detail', kwargs={'freight_pk': self.freight.id,
                                                                       'rule_pk': self.rule.id})
 def setUp(self) -> None:
     self.freight = create_freight()
     self.not_existing_freight_pk = 1000000
     self.freight_detail_url = reverse('freights:detail',
                                       kwargs={'pk': self.freight.id})
     self.invalid_freight_detail_url = reverse(
         'freights:detail', kwargs={'pk': self.not_existing_freight_pk})
    def setUp(self) -> None:
        self.freight = create_freight(need_transfer=True)
        self.new_delivery_service = create_robot_service(
            type=Service.Type.DELIVERY)

        not_valid_value = [1, 2, 3, 4]
        not_valid_status = fake.sentence(2)

        self.valid_partial_data = {'name': fake.sentence(1)}
        self.invalid_partial_data = {'name': not_valid_value}

        self.valid_data = {
            'name': fake.sentence(1),
            'status': self.freight.status,
            'transfer': {
                'delivery_service': self.new_delivery_service.id,
                'reception_service':
                self.freight.transfer.reception_service.id,
            },
        }

        self.invalid_data = {
            'name': fake.sentence(1),
            'status': not_valid_status,
            'transfer': {
                'delivery_service': self.freight.transfer.delivery_service.id,
                'reception_service':
                self.freight.transfer.reception_service.id,
            },
        }

        self.freight_detail_url = reverse('freights:detail',
                                          kwargs={'pk': self.freight.id})
    def setUp(self) -> None:
        self.freight = create_freight(need_transfer=True)
        self.rule = create_rule(freight=self.freight)
        self.state = create_state(rule=self.rule)

        invalid_value = fake.pyfloat(right_digits=2,
                                     min_value=ceil(
                                         self.rule.device.max_value))

        self.valid_partial_data = {
            'value':
            fake.pyfloat(right_digits=2,
                         min_value=ceil(self.rule.min_value),
                         max_value=floor(self.rule.max_value))
        }
        self.invalid_partial_data = {'value': invalid_value}
        self.valid_data = {
            'value':
            fake.pyfloat(right_digits=2,
                         min_value=ceil(self.rule.min_value),
                         max_value=floor(self.rule.max_value)),
            'rule':
            self.rule.id
        }
        self.invalid_data = {'value': invalid_value, 'rule': self.rule.id}

        self.state_detail_url = reverse('freights:state-detail',
                                        kwargs={
                                            'freight_pk': self.freight.id,
                                            'rule_pk': self.rule.id,
                                            'state_pk': self.state.id
                                        })
 def setUp(self) -> None:
     self.freight = create_freight(need_transfer=True)
     self.rule = create_rule(freight=self.freight)
     self.not_existing_rule_pk = 1000000
     self.rule_detail_url = reverse('freights:rule-detail', kwargs={'freight_pk': self.freight.id,
                                                                    'rule_pk': self.rule.id})
     self.invalid_rule_detail_url = reverse('freights:rule-detail', kwargs={'freight_pk': self.not_existing_rule_pk,
                                                                            'rule_pk': self.rule.id})
    def setUp(self) -> None:
        self.freight = create_freight()
        self.rule = create_rule(freight=self.freight)
        for i in range(20):
            create_state(limit_values=(self.rule.min_value,
                                       self.rule.max_value),
                         rule=self.rule)

        self.health_check_url = reverse('freights:check-health',
                                        kwargs={'pk': self.freight.id})
 def setUp(self) -> None:
     self.freight = create_freight(need_transfer=True)
     self.rule = create_rule(freight=self.freight)
     self.state = create_state(rule=self.rule)
     self.state_detail_url = reverse('freights:state-detail',
                                     kwargs={
                                         'freight_pk': self.freight.id,
                                         'rule_pk': self.rule.id,
                                         'state_pk': self.state.id
                                     })
    def setUp(self) -> None:
        self.device = create_device()
        self.freight = create_freight(need_transfer=True)

        limit_value_kwargs = {'right_digits': 2, 'min_value': ceil(self.device.min_value),
                              'max_value': floor(self.device.max_value)}
        self.valid_rule = {
            'coefficient': fake.pyfloat(right_digits=2, min_value=0, max_value=1),
            'possible_deviation': fake.pyfloat(min_value=0, max_value=10),
            'time_interval': str(timedelta(hours=fake.pyint(max_value=24), minutes=fake.pyint(max_value=60))),
            'device': self.device.id,
            'freight': self.freight.id,
            **{k: v for k, v in zip(['min_value', 'max_value'],
                                    sorted([fake.pyfloat(**limit_value_kwargs), fake.pyfloat(**limit_value_kwargs)]))}
        }
        not_existing_device = 10000000
        self.invalid_rule = {
            **self.valid_rule,
            'device': not_existing_device
        }
        self.rule_list_url = reverse('freights:rule-list', kwargs={'pk': self.freight.id})
Esempio n. 10
0
 def setUp(self) -> None:
     self.freight = create_freight(need_transfer=True)
     self.rule = create_rule(freight=self.freight)
     self.valid_state = {
         'value':
         fake.pyfloat(right_digits=2,
                      min_value=floor(self.rule.min_value),
                      max_value=ceil(self.rule.max_value)),
         'rule':
         self.rule.id,
     }
     invalid_value = fake.pyfloat(right_digits=2,
                                  min_value=ceil(
                                      self.rule.device.max_value))
     self.invalid_state = {
         'value': invalid_value,
         'rule': self.rule.id,
     }
     self.state_list_url = reverse('freights:state-list',
                                   kwargs={
                                       'freight_pk': self.freight.id,
                                       'rule_pk': self.rule.id
                                   })
 def setUp(self) -> None:
     self.freight = create_freight(need_transfer=True)
     self.freight_detail_url = reverse('freights:detail',
                                       kwargs={'pk': self.freight.id})