Exemple #1
0
class ListFieldTestCase(FieldTestCase):

    field = ListField(IntegerField(min_value=0))

    def test_conversion(self):
        self.assertConversion(self.field, [1, 2, 3], [1, 2, 3])
        self.assertConversion(self.field, [1, 2, 3], ['1', '2', '3'])

    def test_validate(self):
        with self.assertRaisesRegex(ValidationError, 'less than minimum'):
            self.field.validate([-1, 3, 4])
        self.field.validate([1, 2, 3])

    def test_get_default(self):
        self.assertEqual([], self.field.get_default())

    def test_generic_list_field(self):
        class MyModel(MongoModel):
            data = ListField()

        mydata = [1, 'hello', {'a': 1}]
        mymodel = MyModel(data=mydata).save()
        mymodel.refresh_from_db()

        self.assertEqual(mymodel.data, mydata)

    def test_field_validation_on_initialization(self):
        # Initializing ListField with field type raises exception.
        with self.assertRaisesRegex(
                ValueError, "field must be an instance of MongoBaseField"):
            _ = ListField(CharField)
Exemple #2
0
class IfcGroup(MongoModel):
    pid = IntegerField()
    ptype = CharField()
    name = CharField(blank=True)
    pset = ListField(ReferenceField(IfcSingleProperty))
    version = ListField(ReferenceField(Version))

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'
Exemple #3
0
class ExecutionLogModel(MongoModel):
    uniq_combo = CharField(primary_key=True)
    namespace = CharField()
    repository = CharField()
    commit_id = CharField()
    execution_number = IntegerField()
    stdout = CharField()
    stderr = CharField()
    deterministic = BooleanField()
    execution_time = TimestampField()

    class Meta:
        #indexes = [IndexModel([('namespace', TEXT), ('repository', TEXT), ('commit_id', TEXT),
        #                       ('execution_number', TEXT)], unique=True)]
        #connection_alias = 'mongo_000'
        pass

    def __str__(self):
        if isinstance(self.execution_time, Timestamp):
            execution_time = self.execution_time.as_datetime().__str__()
        else:
            execution_time = self.execution_time
        return "ExecutionLogMongoModel: %s/%s@%s#%s: [\"%s\", \"%s\"] %s@%s" % (
            self.namespace, self.repository, self.commit_id,
            self.execution_number, self.stdout, self.stderr,
            self.deterministic, execution_time)

    @classmethod
    def calc_uniq_combo(cls, namespace, repository, commit_id,
                        execution_number):
        if namespace is None:
            raise ValueError("Namespace can't be None")
        if repository is None:
            raise ValueError("Repository can't be None")
        if commit_id is None:
            raise ValueError("Commit_ID can't be None")
        if execution_number is None:
            raise ValueError("Execution_Number can't be None")
        return "%s/%s@%s#%s" % (namespace, repository, commit_id,
                                str(execution_number))

    def build_uniq_combo(self):
        return self.calc_uniq_combo(namespace=self.namespace,
                                    repository=self.repository,
                                    commit_id=self.commit_id,
                                    execution_number=self.execution_number)

    def save_uniq_combo(self):
        self.uniq_combo = self.build_uniq_combo()

    def save(self, cascade=None, full_clean=True, force_insert=False):
        self.save_uniq_combo()
        super().save(cascade=cascade,
                     full_clean=full_clean,
                     force_insert=force_insert)
Exemple #4
0
class ProductSignal(MongoModel):
    name = CharField()
    signalType = CharField()
    terminals = ListField()
    wires = IntegerField()
    min_value = FloatField()
    max_value = FloatField()

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'
Exemple #5
0
class IfcSingleProperty(MongoModel):
    pid = IntegerField()
    ptype = CharField()
    value_type = CharField(blank=True)
    value = CharField(blank=True)
    unit = CharField(blank=True)
    name = CharField(blank=True)

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'
Exemple #6
0
class Movie(MongoModel):
    path = CharField()
    file = CharField()
    name = CharField()
    file_id = CharField(primary_key=True)
    # fields below this point are for TMDB movie queries against a movie id
    # GET 	/movie/{movie_id}
    # https://api.themoviedb.org/3/movie/{movie_id}?api_key=<<api_key>>&language=en-US
    adult = BooleanField()
    backdrop_path = CharField()
    budget = IntegerField()
    genres = EmbeddedDocumentListField('Genre')
    homepage = URLField()
    id = IntegerField()
    imdb_id = CharField()
    original_language = CharField()
    original_title = CharField()
    overview = CharField()
    popularity = IntegerField()
    poster_path = CharField()
    production_companies = EmbeddedDocumentListField('Production_Company')
    production_countries = EmbeddedDocumentListField('Production_Country')
    release_date = DateTimeField()
    revenue = IntegerField()
    runtime = IntegerField()
    spoken_languages = EmbeddedDocumentListField('Spoken_Language')
    status = CharField()
    tagline = CharField()
    title = CharField()
    video = BooleanField()
    vote_average = Decimal128Field()
    vote_count = IntegerField()
Exemple #7
0
class IfcShapeRepresentation(EmbeddedMongoModel):
    pid = IntegerField()
    identifier = CharField()
    RepresentationType = CharField()
    footprint = ListField(ListField())
    footprint_react = DictField()
    top = FloatField()
    bottom = FloatField()
    center = ListField()

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'
Exemple #8
0
class Version(MongoModel):
    project = ReferenceField(Project)
    branch = CharField()
    version = IntegerField()

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'

    def to_json(self):
        items = self.to_son()
        items['project'] = self.project.to_son()
        return items
Exemple #9
0
class DataFrame(MongoModel):
    from_model = BooleanField()
    pset = BooleanField(blank=True)
    type = CharField(blank=True)
    name = CharField(blank=True)
    calculation = ListField(ReferenceField(Calculation))
    version = ReferenceField(Version)
    excelfile = ReferenceField(ExcelFile)
    header = IntegerField(blank=True)
    sheetname = CharField(blank=True)

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'
Exemple #10
0
class IfcProductType(MongoModel):
    pid = IntegerField()
    guid = CharField()
    ptype = CharField()
    name = CharField(blank=True)
    predefined = CharField(blank=True)
    tag = CharField(blank=True)
    pset = ListField(ReferenceField(IfcSingleProperty))
    material = ListField(ReferenceField(IfcMaterial))
    shape = EmbeddedDocumentField(IfcShapeRepresentation)
    version = ListField(ReferenceField(Version))

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'
Exemple #11
0
class IfcBuilding(MongoModel):
    pid = IntegerField()
    guid = CharField()
    ptype = CharField(blank=True)
    name = CharField(blank=True)
    description = CharField(blank=True)
    longName = CharField(blank=True)
    site = ReferenceField(IfcSite)
    pset = ListField(ReferenceField(IfcSingleProperty))
    shape = EmbeddedDocumentField(IfcShapeRepresentation)
    version = ListField(ReferenceField(Version))

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'
Exemple #12
0
class IntegerFieldTestCase(FieldTestCase):

    field = IntegerField(min_value=0, max_value=100)

    def test_conversion(self):
        self.assertConversion(self.field, 42, '42')
        self.assertConversion(self.field, 42, 42)

    def test_validate(self):
        with self.assertRaisesRegex(ValidationError, 'greater than maximum'):
            self.field.validate(101)
        with self.assertRaisesRegex(ValidationError, 'less than minimum'):
            self.field.validate(-1)
        # No Exception.
        self.field.validate(42)
Exemple #13
0
class ListFieldTestCase(FieldTestCase):

    field = ListField(IntegerField(min_value=0))

    def test_conversion(self):
        self.assertConversion(self.field, [1, 2, 3], [1, 2, 3])
        self.assertConversion(self.field, [1, 2, 3], ['1', '2', '3'])

    def test_validate(self):
        with self.assertRaisesRegex(ValidationError, 'less than minimum'):
            self.field.validate([-1, 3, 4])
        self.field.validate([1, 2, 3])

    def test_get_default(self):
        self.assertEqual([], self.field.get_default())
Exemple #14
0
class IfcProject(MongoModel):
    pid = IntegerField()
    guid = CharField()
    ptype = CharField()
    name = CharField(blank=True)
    longName = CharField(blank=True)
    description = CharField(blank=True)
    phase = CharField(blank=True)
    lengthUnit = CharField(blank=True)
    lengthPrefix = CharField(blank=True)
    dir = ListField(FloatField(blank=True))
    pset = ListField(ReferenceField(IfcSingleProperty))
    version = ListField(ReferenceField(Version))

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'
Exemple #15
0
class IfcSite(MongoModel):
    pid = IntegerField()
    guid = CharField()
    ptype = CharField()
    name = CharField(blank=True)
    description = CharField(blank=True)
    refLatitude = ListField(blank=True)
    refLongitude = ListField(blank=True)
    refElevation = FloatField(blank=True)
    LandTitleNumber = CharField(blank=True)
    #quitself.SiteAddress = element.SiteAddress
    pset = ListField(ReferenceField(IfcSingleProperty))
    project = ReferenceField(IfcProject)
    version = ListField(ReferenceField(Version))

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'
Exemple #16
0
class IfcProduct(MongoModel):
    pid = IntegerField(blank=True)
    guid = CharField(blank=True)
    ptype = CharField(blank=True)
    name = CharField(blank=True)
    description = CharField(blank=True)
    pset = ListField(ReferenceField(IfcSingleProperty))
    group = ListField(ReferenceField(IfcGroup))
    material = ListField(ReferenceField(IfcMaterial))
    building = ListField(ReferenceField(IfcBuilding))
    storey = ListField(ReferenceField(IfcStorey))
    shape = EmbeddedDocumentField(IfcShapeRepresentation)
    space = ListField(ReferenceField(IfcSpace))
    system = ListField(ReferenceField(IfcSystem))
    productType = ReferenceField(IfcProductType)
    product = ReferenceField(ProductType)
    version = ListField(ReferenceField(Version))
    filepath = CharField(blank=True)

    class Meta:
        write_concern = WriteConcern(j=True)
        connection_alias = 'my-app'
Exemple #17
0
class Production_Company(EmbeddedMongoModel):
    id = IntegerField(primary_key=True)
    name = CharField()
Exemple #18
0
class Genre(EmbeddedMongoModel):
    id = IntegerField(primary_key=True)
    name = CharField()
Exemple #19
0
class Document(MongoModel):
    region_code = CharField(
        validators=[must_be_all_caps, must_be_three_letters])
    number = IntegerField(min_value=0, max_value=100)
    title = CharField(required=True)