Showing 34 of 34 total issues

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

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

from .response import Response
Severity: Major
Found in src/pook/mock.py - About 1 day to fix

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

    Severity: Major
    Found in examples/network_mode.py and 1 other location - About 7 hrs to fix
    examples/network_mode_httpx.py on lines 0..29

    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 121.

    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 2 locations. Consider refactoring.
    Open

    Severity: Major
    Found in examples/network_mode_httpx.py and 1 other location - About 7 hrs to fix
    examples/network_mode.py on lines 0..29

    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 121.

    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

    with pook.api.context():
        pook.get(
            "httpbin.org/ip",
            reply=403,
            response_headers={"pepe": "lopez"},
    Severity: Major
    Found in examples/context_manager.py and 1 other location - About 5 hrs to fix
    examples/decorator_activate.py on lines 5..21

    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 95.

    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

    @pook.on
    def run():
        pook.get(
            "httpbin.org/ip",
            reply=403,
    Severity: Major
    Found in examples/decorator_activate.py and 1 other location - About 5 hrs to fix
    examples/context_manager.py on lines 5..20

    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 95.

    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

    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 src/pook/mock.py - About 5 hrs to fix

      File api.py has 400 lines of code (exceeds 250 allowed). Consider refactoring.
      Open

      import functools
      import re
      from contextlib import contextmanager
      from inspect import isfunction
      
      
      Severity: Minor
      Found in src/pook/api.py - About 5 hrs to fix

        Engine has 31 functions (exceeds 20 allowed). Consider refactoring.
        Open

        class Engine(object):
            """
            Engine represents the mock interceptor and matcher engine responsible
            of triggering interceptors and match outgoing HTTP traffic.
        
        
        Severity: Minor
        Found in src/pook/engine.py - About 3 hrs to fix

          File engine.py has 321 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          from functools import partial
          from inspect import isfunction
          from .mock import Mock
          from .regex import isregex
          from .mock_engine import MockEngine
          Severity: Minor
          Found in src/pook/engine.py - About 3 hrs to fix

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

                    try:
                        # Create a new patcher for Urllib3 urlopen function
                        # used as entry point for all the HTTP communications
                        patcher = mock.patch(path, handler)
                        # Retrieve original patched function that we might need for real
            Severity: Major
            Found in src/pook/interceptors/urllib3.py and 1 other location - About 2 hrs to fix
            src/pook/interceptors/http.py on lines 116..130

            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 54.

            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

            HTTPHeaderDict has 22 functions (exceeds 20 allowed). Consider refactoring.
            Open

            class HTTPHeaderDict(MutableMapping):
                """
                :param headers:
                    An iterable of field-value pairs. Must not contain multiple field names
                    when compared case-insensitively.
            Severity: Minor
            Found in src/pook/headers.py - About 2 hrs to fix

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

                      try:
                          # Create a new patcher for Urllib3 urlopen function
                          # used as entry point for all the HTTP communications
                          patcher = mock.patch(path, handler)
                          # Retrieve original patched function that we might need for real
              Severity: Major
              Found in src/pook/interceptors/http.py and 1 other location - About 2 hrs to fix
              src/pook/interceptors/urllib3.py on lines 184..198

              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 54.

              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

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

                  def match(self, request):
                      """
                      Matches a given Request instance contract against the registered mocks.
              
                      If a mock passes all the matchers, its response will be returned.
              Severity: Minor
              Found in src/pook/engine.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

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

              def trigger_methods(instance, args, key_order=None):
                  """
                  Triggers specific class methods using a simple reflection
                  mechanism based on the given input dictionary params.
              
              
              Severity: Minor
              Found in src/pook/helpers.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 extend has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                  def extend(self, mapping, **kwargs):
                      """
                      Generic import function for any type of header-like object.
                      Adapted version of MutableMapping.update in order to insert items
                      with self.add instead of self.__setitem__
              Severity: Minor
              Found in src/pook/headers.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 body has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
              Open

                  def body(self, body, *, chunked=False):
                      """
                      Defines response body data.
              
                      Arguments:
              Severity: Minor
              Found in src/pook/response.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 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 src/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

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

                  def match_query(self, req):
                      query = self.expectation.query
                      if not query:
                          return True
                      return QueryMatcher(query).match(req)
              Severity: Major
              Found in src/pook/matchers/url.py and 1 other location - About 1 hr to fix
              src/pook/matchers/url.py on lines 38..42

              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 40.

              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 2 locations. Consider refactoring.
              Open

                  def match_path(self, req):
                      path = self.expectation.path
                      if not path:
                          return True
                      return PathMatcher(path).match(req)
              Severity: Major
              Found in src/pook/matchers/url.py and 1 other location - About 1 hr to fix
              src/pook/matchers/url.py on lines 44..48

              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 40.

              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 3 locations. Consider refactoring.
              Open

                  def __init__(self, schema):
                      BaseMatcher.__init__(self, schema)
              
                      if isinstance(schema, str):
                          self.expectation = json.loads(schema)
              Severity: Major
              Found in src/pook/matchers/json_schema.py and 2 other locations - About 1 hr to fix
              src/pook/matchers/json.py on lines 26..30
              src/pook/matchers/xml.py on lines 29..33

              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 39.

              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

              Severity
              Category
              Status
              Source
              Language