pook/mock.py

Summary

Maintainability
D
2 days
Test Coverage

File mock.py has 636 lines of code (exceeds 250 allowed). Consider refactoring.
Open

import re
import functools
from furl import furl
from inspect import isfunction, ismethod

Severity: Major
Found in pook/mock.py - About 1 day to fix

    Mock has 42 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Mock(object):
        """
        Mock is used to declare and compose the HTTP request/response mock
        definition and matching expectations, which provides fluent API DSL.
    
    
    Severity: Minor
    Found in pook/mock.py - About 5 hrs to fix

      Function match has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
      Open

          def match(self, request):
              """
              Matches an outgoing HTTP request against the current mock matchers.
      
              This method acts like a delegator to `pook.MatcherEngine`.
      Severity: Minor
      Found in pook/mock.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 __call__ has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          def __call__(self, fn):
              """
              Overload Mock instance as callable object in order to be used
              as decorator definition syntax.
      
      
      Severity: Minor
      Found in pook/mock.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

      Similar blocks of code found in 5 locations. Consider refactoring.
      Open

          def json(self, json):
              """
              Defines the JSON body to match.
      
              ``json`` argument can be an JSON string, a JSON serializable
      Severity: Major
      Found in pook/mock.py and 4 other locations - About 50 mins to fix
      pook/mock.py on lines 136..151
      pook/mock.py on lines 153..166
      pook/mock.py on lines 361..375
      pook/mock.py on lines 408..420

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 5 locations. Consider refactoring.
      Open

          def body(self, body):
              """
              Defines the body data to match.
      
              ``body`` argument can be a ``str``, ``binary`` or a regular expression.
      Severity: Major
      Found in pook/mock.py and 4 other locations - About 50 mins to fix
      pook/mock.py on lines 136..151
      pook/mock.py on lines 153..166
      pook/mock.py on lines 377..393
      pook/mock.py on lines 408..420

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 5 locations. Consider refactoring.
      Open

          def method(self, method):
              """
              Defines the HTTP method to match.
              Use ``*`` to match any method.
      
      
      Severity: Major
      Found in pook/mock.py and 4 other locations - About 50 mins to fix
      pook/mock.py on lines 136..151
      pook/mock.py on lines 361..375
      pook/mock.py on lines 377..393
      pook/mock.py on lines 408..420

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 5 locations. Consider refactoring.
      Open

          def url(self, url):
              """
              Defines the mock URL to match.
              It can be a full URL with path and query params.
      
      
      Severity: Major
      Found in pook/mock.py and 4 other locations - About 50 mins to fix
      pook/mock.py on lines 153..166
      pook/mock.py on lines 361..375
      pook/mock.py on lines 377..393
      pook/mock.py on lines 408..420

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 5 locations. Consider refactoring.
      Open

          def xml(self, xml):
              """
              Defines a XML body value to match.
      
              Arguments:
      Severity: Major
      Found in pook/mock.py and 4 other locations - About 50 mins to fix
      pook/mock.py on lines 136..151
      pook/mock.py on lines 153..166
      pook/mock.py on lines 361..375
      pook/mock.py on lines 377..393

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 36.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Identical blocks of code found in 2 locations. Consider refactoring.
      Open

              for mapper in self.mappers:
                  request = mapper(request, self)
                  if not request:
                      raise ValueError('map function must return a request object')
      Severity: Minor
      Found in pook/mock.py and 1 other location - About 35 mins to fix
      pook/engine.py on lines 406..409

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 33.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      There are no issues that match your filters.

      Category
      Status