stphivos/django-mock-queries

View on GitHub

Showing 20 of 20 total issues

MockSet has 41 functions (exceeds 20 allowed). Consider refactoring.
Open

class MockSet(MagicMock, metaclass=MockSetMeta):
    EVENT_ADDED = 'added'
    EVENT_UPDATED = 'updated'
    EVENT_SAVED = 'saved'
    EVENT_DELETED = 'deleted'
Severity: Minor
Found in django_mock_queries/query.py - About 5 hrs to fix

    File query.py has 388 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    import datetime
    import random
    from collections import OrderedDict, defaultdict, namedtuple
    from unittest.mock import Mock, MagicMock, PropertyMock
    
    
    Severity: Minor
    Found in django_mock_queries/query.py - About 5 hrs to fix

      Function get_attribute has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
      Open

      def get_attribute(obj, attr, default=None):
          result = obj
          comparison = None
          if isinstance(attr, F):
              attr = attr.deconstruct()[1][0]
      Severity: Minor
      Found in django_mock_queries/utils.py - About 4 hrs to fix

      Cognitive Complexity

      Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

      A method's cognitive complexity is based on a few simple rules:

      • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
      • Code is considered more complex for each "break in the linear flow of the code"
      • Code is considered more complex when "flow breaking structures are nested"

      Further reading

      File mocks.py has 342 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import os
      import sys
      import django
      import weakref
      from django.apps import apps
      Severity: Minor
      Found in django_mock_queries/mocks.py - About 4 hrs to fix

        Function mocked_relations has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

        def mocked_relations(*models):
            """ Mock all related field managers to make pure unit tests possible.
        
            The resulting patcher can be used just like one from the mock module:
            As a test method decorator, a test class decorator, a context manager,
        Severity: Minor
        Found in django_mock_queries/mocks.py - About 2 hrs to fix

        Cognitive Complexity

        Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

        A method's cognitive complexity is based on a few simple rules:

        • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
        • Code is considered more complex for each "break in the linear flow of the code"
        • Code is considered more complex when "flow breaking structures are nested"

        Further reading

        File utils.py has 267 lines of code (exceeds 250 allowed). Consider refactoring.
        Open

        from datetime import datetime, date
        from django.core.exceptions import FieldError
        from django.db.models import F, Value, Case
        from django.db.models.functions import Coalesce
        from unittest.mock import Mock
        Severity: Minor
        Found in django_mock_queries/utils.py - About 2 hrs to fix

          Function _item_values has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def _item_values(self, item, fields):
                  field_buckets = {}
                  result_count = 1
          
                  if len(fields) == 0:
          Severity: Minor
          Found in django_mock_queries/query.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function aggregate has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              def aggregate(self, *args, **kwargs):
                  result = {}
          
                  for expr in set(args):
                      kwargs['{0}__{1}'.format(expr.source_expressions[0].name, expr.function).lower()] = expr
          Severity: Minor
          Found in django_mock_queries/query.py - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function load_fields has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def load_fields(self, *field_names):
                  fields = {name: MockField(name) for name in field_names}
          
                  for key in ('_forward_fields_map', 'parents', 'fields_map'):
                      self.__dict__[key] = {}
          Severity: Minor
          Found in django_mock_queries/query.py - About 55 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function filter_results has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

          def filter_results(source, query):
              results = []
          
              for child in query.children:
                  filtered = _filter_single_q(source, child, query.negated)
          Severity: Minor
          Found in django_mock_queries/utils.py - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function compiler has 5 arguments (exceeds 4 allowed). Consider refactoring.
          Open

              def compiler(queryset, using=None, connection=None, elide_empty=True, **kwargs):
          Severity: Minor
          Found in django_mock_queries/mocks.py - About 35 mins to fix

            Function _get_order_fields has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def _get_order_fields(self, fields, field_name):
                    if fields and field_name is not None:
                        raise ValueError('Cannot use both positional arguments and the field_name keyword argument.')
            
                    if field_name is not None:
            Severity: Minor
            Found in django_mock_queries/query.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function is_match has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def is_match(first, second, comparison=None):
                if isinstance(first, django_mock_queries.query.MockSet):
                    return is_match_in_children(comparison, first, second)
                if (isinstance(first, (int, str)) and isinstance(second, django_mock_queries.query.MockSet)):
                    second = convert_to_pks(second)
            Severity: Minor
            Found in django_mock_queries/utils.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function annotate has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                def annotate(self, **kwargs):
                    results = list(self.items)
                    for key, value in kwargs.items():
                        for row in results:
                            if not (hasattr(row, '_annotated_fields') and isinstance(row._annotated_fields, list)):
            Severity: Minor
            Found in django_mock_queries/query.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function find_all_models has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def find_all_models(models):
                """ Yield all models and their parents. """
                for model in models:
                    yield model
                    # noinspection PyProtectedMember
            Severity: Minor
            Found in django_mock_queries/mocks.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Function find_field_names_from_meta has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

            def find_field_names_from_meta(meta, annotated=None, **kwargs):
                field_names = {}
                annotated = annotated or []
                concrete_only = kwargs.get('concrete_only', False)
            
            
            Severity: Minor
            Found in django_mock_queries/utils.py - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Avoid too many return statements within this function.
            Open

                return result, comparison
            Severity: Major
            Found in django_mock_queries/utils.py - About 30 mins to fix

              Function update_or_create has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def update_or_create(self, defaults=None, **attrs):
                      if defaults is not None:
                          validate_mock_set(self)
                      defaults = defaults or {}
                      lookup = attrs.copy()
              Severity: Minor
              Found in django_mock_queries/query.py - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function _values_row has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  def _values_row(self, values_dict, fields, **kwargs):
                      flat = kwargs.pop('flat', False)
                      named = kwargs.pop('named', False)
              
                      if kwargs:
              Severity: Minor
              Found in django_mock_queries/query.py - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Function is_disqualified has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

              def is_disqualified(obj, attrs, negated):
                  for attr_name, filter_value in attrs.items():
                      attr_value, comparison = get_attribute(obj, attr_name)
                      match = is_match(attr_value, filter_value, comparison)
              
              
              Severity: Minor
              Found in django_mock_queries/utils.py - About 25 mins to fix

              Cognitive Complexity

              Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

              A method's cognitive complexity is based on a few simple rules:

              • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
              • Code is considered more complex for each "break in the linear flow of the code"
              • Code is considered more complex when "flow breaking structures are nested"

              Further reading

              Severity
              Category
              Status
              Source
              Language