checks.py 1.07 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
def check_classic_models(classic_models):
    """
    Check that all "classic" models don't have a `get_serializer` method:
    they don't need it.
    See doc for more information:
    http://localhost:5000/#/Application/Backend/models_serializers_viewsets
    """
    for Model in classic_models:
        try:
            # Check that it doesn't have the get_serializer method
            Model.get_serializer()
            raise Exception(
                "A 'CLASSIC MODEL' SHOULDN'T have the "
                "get_serializer method, {}".format(Model)
            )
        except AttributeError:
            pass


def check_versionned_models(versionned_models):
    """
    Check that all "versionned" models have a `get_serializer` method.
    See doc for more information:
    http://localhost:5000/#/Application/Backend/models_serializers_viewsets
    """
    for Model in versionned_models:

        # Check that it has a get_serializer method
        if Model.get_serializer().Meta.model != Model:
            raise Exception("Get_serializer configuration incorrect in", str(Model))