示例#1
0
 def setUp(self):
     test_model = SketchupModel()
     test_model.google_id = "test1"
     test_model.tags = ["tag1", "tag2"]
     test_model.title = "title1"
     test_model.text = "Description of 'title1' SketchupModel."
     test_model.mesh = file("sketchup_models/fixtures/mesh_can.tri").read()
     test_model.save()
     self.test_model = SketchupModel.find_google_id("test1")
示例#2
0
 def setUp(self):
     test_model = SketchupModel()
     test_model.google_id = "test1"
     test_model.tags = ["tag1", "tag2"]
     test_model.title = "title1"
     test_model.text = "Description of 'title1' SketchupModel."
     test_model.mesh = file("sketchup_models/fixtures/mesh_can.tri").read()
     test_model.save()
     self.test_model = SketchupModel.find_google_id("test1")
示例#3
0
def retreive_model(google_id):
    """ Return the SketchupModel corresponding to the google_id. """
    json_data = api_get("GetEntity", id=google_id)
    try:
        model = SketchupModel.objects.get(google_id=google_id)
    except SketchupModel.DoesNotExist:
        model = SketchupModel()
    try:
        _parse_model_entry(model, json_data)
        model.save()
        return model
    except KeyError:
        return None
示例#4
0
def retreive_model(google_id):
    """ Return the SketchupModel corresponding to the google_id. """
    json_data = api_get("GetEntity", id=google_id)
    try:
        model = SketchupModel.objects.get(google_id=google_id)
    except SketchupModel.DoesNotExist:
        model = SketchupModel()
    try:
        _parse_model_entry(model, json_data)
        model.save()
        return model
    except KeyError:
        return None
示例#5
0
    def setUp(self):
        """ Run before starting testing. """
        # TODO : use fixtures
        test_model = SketchupModel()
        test_model.google_id = "test1"
        test_model.tags = ["tag1", "tag2"]
        test_model.title = "title1"
        test_model.text = "Description of 'title1' SketchupModel."
        test_model.mesh = file("sketchup_models/fixtures/mesh_can.tri").read()
        test_model.save()

        self.test_model = SketchupModel.find_google_id("test1")
        self.view = PartialView(model=self.test_model, theta=0.0, phi=0.0)
        self.distribution = ShapeDistribution.compute(self.view.pointcloud)
示例#6
0
    def setUp(self):
        """ Run before starting testing. """
        # TODO : use fixtures
        test_model = SketchupModel()
        test_model.google_id = "test1"
        test_model.tags = ["tag1", "tag2"]
        test_model.title = "title1"
        test_model.text = "Description of 'title1' SketchupModel."
        test_model.mesh = file("sketchup_models/fixtures/mesh_can.tri").read()
        test_model.save()

        self.test_model = SketchupModel.find_google_id("test1")
        self.view = PartialView(model=self.test_model, theta=0.0, phi=0.0)
        self.distribution = ShapeDistribution.compute(self.view.pointcloud)
示例#7
0
    def test_mesh_attribute_can_be_used_as_a_string(self):
        """
        As mesh is store in a gridfsfield, the attribute mesh would
        normally be returned as a GridFSOut object.
        The model has been modified so that it is a string instead.
        """
        model = SketchupModel()
        model.google_id = "test1"
        model.mesh = file("sketchup_models/fixtures/mesh_can.tri").read()

        def error_msg(model):
            return "The mesh should be of type str but is {} instead.".format(model.mesh.__class__)

        msg = error_msg(model)
        self.assertTrue(isinstance(model.mesh, basestring))
        model.save()
        msg = error_msg(model)
        self.assertTrue(isinstance(model.mesh, basestring))
        model = SketchupModel.find_google_id("test1")
        msg = error_msg(model)
        self.assertTrue(isinstance(model.mesh, basestring), msg=msg)
示例#8
0
    def test_mesh_attribute_can_be_used_as_a_string(self):
        """
        As mesh is store in a gridfsfield, the attribute mesh would
        normally be returned as a GridFSOut object.
        The model has been modified so that it is a string instead.
        """
        model = SketchupModel()
        model.google_id = "test1"
        model.mesh = file("sketchup_models/fixtures/mesh_can.tri").read()

        def error_msg(model):
            return ("The mesh should be of type str but is {} instead.".
                    format(model.mesh.__class__))

        msg = error_msg(model)
        self.assertTrue(isinstance(model.mesh, basestring))
        model.save()
        msg = error_msg(model)
        self.assertTrue(isinstance(model.mesh, basestring))
        model = SketchupModel.find_google_id("test1")
        msg = error_msg(model)
        self.assertTrue(isinstance(model.mesh, basestring), msg=msg)
示例#9
0
def search_by_keywords(keywords, create_models=False):
    """ Search the API for the keywords, return a list of model_ids. """
    params = {
        "startRow": 1,
        "endRow": NUMBER_OF_RESULTS,
        "q": keywords,
        "type": "SKETCHUP_MODEL",
        "class": "entity",
        "Lk": True,
    }
    json_data = api_get("Search", **params)
    if create_models:
        models = []
        for entry in json_data["entries"]:
            try:
                model = SketchupModel()
                _parse_model_entry(model, entry)
                model.save()
                models.append(model)
            except KeyError as exception:
                print exception
        return models
    else:
        return [entry["id"] for entry in json_data["entries"]]
示例#10
0
def search_by_keywords(keywords, create_models=False):
    """ Search the API for the keywords, return a list of model_ids. """
    params = {
        'startRow': 1,
        'endRow': NUMBER_OF_RESULTS,
        'q': keywords,
        'type': 'SKETCHUP_MODEL',
        'class': 'entity',
        'Lk': True
    }
    json_data = api_get('Search', **params)
    if create_models:
        models = []
        for entry in json_data['entries']:
            try:
                model = SketchupModel()
                _parse_model_entry(model, entry)
                model.save()
                models.append(model)
            except KeyError as exception:
                print exception
        return models
    else:
        return [entry['id'] for entry in json_data['entries']]