Example #1
0
 def _validate_instance(self, model, instance):
     """Validate an instance against a model."""
     try:
         validate_model_instance(model, instance)
     except MissingFields as fields:
         raise tornado.web.HTTPError(400, "Missing Fields %s" % fields)
     except ValidationError:
         raise tornado.web.HTTPError(400, "Validation Error")
     self._create_instance(instance)
Example #2
0
File: api.py Project: zeth/magpy
 def _validate_instance(self, model, instance):
     """Validate an instance against a model."""
     try:
         validate_model_instance(model, instance)
     except MissingFields as fields:
         raise tornado.web.HTTPError(400, "Missing Fields %s" % fields)
     except ValidationError:
         raise tornado.web.HTTPError(400, "Validation Error")
     self._create_instance(instance)
Example #3
0
 def _do_validate(model, instance, success,
                  embedded_models=None):
     """Validate an instance."""
     try:
         validate_model_instance(model,
                                 instance,
                                 embedded_models=embedded_models)
     except MissingFields as fields:
         raise tornado.web.HTTPError(400, "Missing Fields %s" % fields)
     except ValidationError:
         raise tornado.web.HTTPError(400, "Validation Error")
     success(instance)
Example #4
0
 def test_embed_comment_example(self):
     """Test that the embedded comment is valid on its own."""
     self.assertEqual(
         validate_model_instance(
             EMBEDDED_MODELS["comment"], TEST_ARTICLE["comments"][0], embedded_models=EMBEDDED_MODELS
         ),
         None,
     )
Example #5
0
    def add_instance(self, instance,
                     skip_validation=False,
                     handle_none=False):
        """Add an instance to the db."""
        model_name = instance['_model']

        if not skip_validation:
            model = self.get_model(model_name)

            try:
                validate_model_instance(model,
                                        instance,
                                        handle_none=handle_none)
            except ValidationError:
                print("Died on instance:")
                print(instance)
                raise

        # We got this far, yay!
        instance_collection = self.get_collection(model_name)
        instance_collection.save(instance)
        sys.stdout.write(model_name[0])
Example #6
0
 def test_embed_article_example(self):
     """Test that the whole article is valid."""
     self.assertEqual(
         validate_model_instance(EMBEDDED_MODELS['article'],
                                 TEST_ARTICLE,
                                 embedded_models=EMBEDDED_MODELS), None)
Example #7
0
 def test_embed_comment_example(self):
     """Test that the embedded comment is valid on its own."""
     self.assertEqual(
         validate_model_instance(EMBEDDED_MODELS['comment'],
                                 TEST_ARTICLE['comments'][0],
                                 embedded_models=EMBEDDED_MODELS), None)
Example #8
0
 def test_embed_author_example(self):
     """Test that the embedded author is valid on its own."""
     self.assertEqual(
         validate_model_instance(EMBEDDED_MODELS['author'],
                                 TEST_ARTICLE['author'],
                                 embedded_models=EMBEDDED_MODELS), None)
Example #9
0
 def test_embed_article_example(self):
     """Test that the whole article is valid."""
     self.assertEqual(
         validate_model_instance(EMBEDDED_MODELS["article"], TEST_ARTICLE, embedded_models=EMBEDDED_MODELS), None
     )
Example #10
0
 def test_embed_author_example(self):
     """Test that the embedded author is valid on its own."""
     self.assertEqual(
         validate_model_instance(EMBEDDED_MODELS["author"], TEST_ARTICLE["author"], embedded_models=EMBEDDED_MODELS),
         None,
     )