Example #1
0
    def test_create_molecules(self):
        required = rescue_bag.get_required(self.params)

        output = rescue_bag.create_molecules(required["molecules"].keys(),
                                             required["molecules"])

        image_field = TypeDefinition(name='image_field',
                                     included_types=(ImageFieldFile, ),
                                     excluded_types=())
        Validator.types_mapping['image_field'] = image_field

        schema_path = settings.VALIDATOR_PATH.joinpath("parsers", "rescue_bag",
                                                       "single_item.json")
        schema = json.loads(schema_path.read_text())
        validator = Validator(schema)

        for item in output:
            result = validator.validate(output[item])
            if not result:
                log.error(validator.errors)
                log.debug(output[item])
            self.assertTrue(result)

        schema = {"data": {"type": "dict", "keysrules": {"type": "integer"}}}
        validator = Validator(schema)
        self.assertTrue(validator.validate({"data": output}))
Example #2
0
    def test_merge_bags(self):
        required = rescue_bag.get_required(self.params)

        equipments = rescue_bag.get_articles(self.params,
                                             required["equipments"],
                                             [110, 111])

        molecules = rescue_bag.get_medicines(self.params,
                                             required["molecules"], [110, 111])

        bags = models.RescueBag.objects.all()

        output = rescue_bag.merge_bags(bags, molecules, equipments)

        image_field = TypeDefinition(name='image_field',
                                     included_types=(ImageFieldFile, ),
                                     excluded_types=())
        Validator.types_mapping['image_field'] = image_field

        schema_path = settings.VALIDATOR_PATH.joinpath("parsers", "rescue_bag",
                                                       "merged_bags.json")
        schema = json.loads(schema_path.read_text())
        validator = Validator(schema)

        result = validator.validate({"data": output})
        if not result:
            log.error(validator.errors)
            log.debug(output)
        self.assertTrue(result)
Example #3
0
    def test_get_required(self):
        output = rescue_bag.get_required(self.params)

        schema_path = settings.VALIDATOR_PATH.joinpath("parsers", "rescue_bag",
                                                       "get_required.json")
        schema = json.loads(schema_path.read_text())
        validator = Validator(schema)

        result = validator.validate(output)
        if not result:
            log.error(validator.errors)
            log.debug(output)
        self.assertTrue(result)
Example #4
0
    def test_create_equipment(self):

        required = rescue_bag.get_required(self.params)
        equipment = models.Equipment.objects.get(id=2)

        output = rescue_bag.create_equipment(equipment, required["equipments"])

        image_field = TypeDefinition(name='image_field',
                                     included_types=(ImageFieldFile, ),
                                     excluded_types=())
        Validator.types_mapping['image_field'] = image_field

        schema_path = settings.VALIDATOR_PATH.joinpath("parsers", "rescue_bag",
                                                       "single_item.json")
        schema = json.loads(schema_path.read_text())
        validator = Validator(schema)

        result = validator.validate(output)
        if not result:
            log.error(validator.errors)
            log.debug(output)
        self.assertTrue(result)