Showing 47 of 47 total issues

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

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

    @pook.on
    def run():
        pook.get('httpbin.org/ip', reply=403,
                 response_headers={'pepe': 'lopez'},
                 response_json={'error': 'not found'})
    Severity: Major
    Found in examples/decorator_activate.py and 1 other location - About 5 hrs to fix
    examples/context_manager.py on lines 5..17

    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

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

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

      File api.py has 379 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 pook/api.py - About 5 hrs to fix

        File engine.py has 320 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 pook/engine.py - About 3 hrs to fix

          Engine has 30 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 pook/engine.py - About 3 hrs to fix

            Function match has a Cognitive Complexity of 19 (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 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

            HTTPHeaderDict has 23 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 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 pook/interceptors/urllib3.py and 1 other location - About 2 hrs to fix
              pook/interceptors/http.py on lines 115..129

              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

              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 pook/interceptors/http.py and 1 other location - About 2 hrs to fix
              pook/interceptors/urllib3.py on lines 198..212

              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 extend has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
              Open

                  def extend(self, *args, **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 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

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

              def test_context_manager():
                  with pook.use():
                      pook.get('server.com/baz', reply=204)
                      res = requests.get('http://server.com/baz')
                      assert res.status_code == 204
              Severity: Major
              Found in examples/pytest_example.py and 1 other location - About 1 hr to fix
              examples/nose_example.py on lines 27..31

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

              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 test_context_manager():
                  with pook.use():
                      pook.get('server.com/bar', reply=204)
                      res = requests.get('http://server.com/bar')
                      assert res.status_code == 204
              Severity: Major
              Found in examples/nose_example.py and 1 other location - About 1 hr to fix
              examples/pytest_example.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 47.

              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 trigger_methods has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

              def trigger_methods(instance, args):
                  """"
                  Triggers specific class methods using a simple reflection
                  mechanism based on the given input dictionary params.
              
              
              Severity: Minor
              Found in 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

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

              @pook.activate
              def test_simple_pook_request():
                  pook.get('server.com/foo').reply(204)
                  res = requests.get('http://server.com/foo')
                  assert res.status_code == 204
              Severity: Major
              Found in examples/pytest_example.py and 2 other locations - About 1 hr to fix
              examples/nose_example.py on lines 7..11
              examples/nose_example.py on lines 14..18

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

              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

              @pook.activate
              def test_simple_pook_request():
                  pook.get('server.com/foo').reply(204)
                  res = requests.get('http://server.com/foo')
                  assert res.status_code == 204
              Severity: Major
              Found in examples/nose_example.py and 2 other locations - About 1 hr to fix
              examples/nose_example.py on lines 14..18
              examples/pytest_example.py on lines 8..12

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

              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

              @pook.on
              def test_enable_engine():
                  pook.get('server.com/foo').reply(204)
                  res = requests.get('http://server.com/foo')
                  assert res.status_code == 204
              Severity: Major
              Found in examples/nose_example.py and 2 other locations - About 1 hr to fix
              examples/nose_example.py on lines 7..11
              examples/pytest_example.py on lines 8..12

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

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

              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 pook/matchers/url.py and 1 other location - About 1 hr to fix
              pook/matchers/url.py on lines 42..46

              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

              Severity
              Category
              Status
              Source
              Language