Beispiel #1
0
    def _get_embedded_model_names(self, model, error, instance, success):
        """Get the names of the embedded instance models."""
        # Make a copy without the top level model
        # This is important in the case of a model that can embed
        # itself
        new_instance = instance.copy()
        del new_instance['_model']

        # Get all the model names used
        embedded_model_names = set()
        parse_instance(new_instance, embedded_model_names)

        # Skip any that we have in memory already
        if self.embedded_models:
            embedded_model_names = embedded_model_names - set(
                self.embedded_models.keys())

        # If we have them all, move along.
        if not embedded_model_names:
            return success(
                model=model,
                embedded_models=None)

        return self._get_embedded_models(model,
                                         instance,
                                         success,
                                         embedded_model_names)
Beispiel #2
0
    def test_parse_complex_instance(self):
        """Complex instance has embedded models."""

        # Setup the instance:
        instance = TEST_ARTICLE.copy()

        # We don't want the top level model:
        del instance['_model']

        # Store the results in results:
        results = set()

        # Parse the instance
        parse_instance(instance, results)

        # Test Result
        self.assertEqual(results, set(['comment', 'author']))
Beispiel #3
0
    def test_parse_simple_instance(self):
        """Simple instance has no embedded models."""

        # Setup the instance:
        instance = TEST_ARTICLE['author'].copy()

        # We don't want the top level model:
        del instance['_model']

        # Store the results in results:
        results = set()

        # Parse the instance
        parse_instance(instance, results)

        # Result should be an empty set
        self.assertFalse(results)
Beispiel #4
0
    def test_parse_complex_instance(self):
        """Complex instance has embedded models."""

        # Setup the instance:
        instance = TEST_ARTICLE.copy()

        # We don't want the top level model:
        del instance["_model"]

        # Store the results in results:
        results = set()

        # Parse the instance
        parse_instance(instance, results)

        # Test Result
        self.assertEqual(results, set(["comment", "author"]))
Beispiel #5
0
    def test_parse_simple_instance(self):
        """Simple instance has no embedded models."""

        # Setup the instance:
        instance = TEST_ARTICLE["author"].copy()

        # We don't want the top level model:
        del instance["_model"]

        # Store the results in results:
        results = set()

        # Parse the instance
        parse_instance(instance, results)

        # Result should be an empty set
        self.assertFalse(results)