jacquev6/LowVoltage

View on GitHub
LowVoltage/connection/connection.py

Summary

Maintainability
F
1 wk
Test Coverage

File connection.py has 436 lines of code (exceeds 250 allowed). Consider refactoring.
Open

# coding: utf8

# Copyright 2014-2015 Vincent Jacques <vincent@vincent-jacques.net>

import datetime
Severity: Minor
Found in LowVoltage/connection/connection.py - About 6 hrs to fix

    Function __raise has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        def __raise(self, status_code, r):
            try:
                data = r.json()
            except ValueError:
                data = r.text
    Severity: Minor
    Found in LowVoltage/connection/connection.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 12 (exceeds 5 allowed). Consider refactoring.
    Open

        def __call__(self, action):
            """
            Send requests and return responses.
            """
            errors = []
    Severity: Minor
    Found in LowVoltage/connection/connection.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 test_different_statuses has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def test_different_statuses(self):
            self.requests_response.expect.status_code.andReturn(400)
            self.requests_response.expect.json().andReturn({})
            with self.assertRaises(_exn.ClientError):
                self.responder(self.response_class.object, self.requests_response.object)
    Severity: Minor
    Found in LowVoltage/connection/connection.py - About 1 hr to fix

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

          def __init__(self, region, credentials, endpoint=None, retry_policy=None, requests_session=None):
      Severity: Minor
      Found in LowVoltage/connection/connection.py - About 35 mins to fix

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

            def __call__(self, key, secret, now, action, payload):
        Severity: Minor
        Found in LowVoltage/connection/connection.py - About 35 mins to fix

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

              def test_server_error_without_json(self):
                  self.requests_response.expect.status_code.andReturn(500)
                  self.requests_response.expect.json().andRaise(ValueError)
                  self.requests_response.expect.text.andReturn("Message: tralala")
          
          
          Severity: Major
          Found in LowVoltage/connection/connection.py and 3 other locations - About 6 hrs to fix
          LowVoltage/connection/connection.py on lines 351..358
          LowVoltage/connection/connection.py on lines 384..391
          LowVoltage/connection/connection.py on lines 450..457

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

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

              def test_non_json_response_with_good_status(self):
                  self.requests_response.expect.status_code.andReturn(200)
                  self.requests_response.expect.json().andRaise(ValueError)
                  self.requests_response.expect.text.andReturn("foobar")
          
          
          Severity: Major
          Found in LowVoltage/connection/connection.py and 3 other locations - About 6 hrs to fix
          LowVoltage/connection/connection.py on lines 384..391
          LowVoltage/connection/connection.py on lines 417..424
          LowVoltage/connection/connection.py on lines 450..457

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

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

              def test_unknown_client_error_without_json(self):
                  self.requests_response.expect.status_code.andReturn(400)
                  self.requests_response.expect.json().andRaise(ValueError)
                  self.requests_response.expect.text.andReturn("Message: tralala")
          
          
          Severity: Major
          Found in LowVoltage/connection/connection.py and 3 other locations - About 6 hrs to fix
          LowVoltage/connection/connection.py on lines 351..358
          LowVoltage/connection/connection.py on lines 417..424
          LowVoltage/connection/connection.py on lines 450..457

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

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

              def test_unknown_error_without_json(self):
                  self.requests_response.expect.status_code.andReturn(750)
                  self.requests_response.expect.json().andRaise(ValueError)
                  self.requests_response.expect.text.andReturn("Message: tralala")
          
          
          Severity: Major
          Found in LowVoltage/connection/connection.py and 3 other locations - About 6 hrs to fix
          LowVoltage/connection/connection.py on lines 351..358
          LowVoltage/connection/connection.py on lines 384..391
          LowVoltage/connection/connection.py on lines 417..424

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

          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 test_unknown_error_with_correct_json(self):
                  self.requests_response.expect.status_code.andReturn(750)
                  self.requests_response.expect.json().andReturn({"__type": "NobodyKnewThisCouldHappen", "Message": "tralala"})
          
                  with self.assertRaises(_exn.UnknownError) as catcher:
          Severity: Major
          Found in LowVoltage/connection/connection.py and 2 other locations - About 6 hrs to fix
          LowVoltage/connection/connection.py on lines 360..366
          LowVoltage/connection/connection.py on lines 393..399

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

          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 test_unknown_client_error_with_correct_json(self):
                  self.requests_response.expect.status_code.andReturn(400)
                  self.requests_response.expect.json().andReturn({"__type": "NobodyKnewThisCouldHappen", "Message": "tralala"})
          
                  with self.assertRaises(_exn.UnknownClientError) as catcher:
          Severity: Major
          Found in LowVoltage/connection/connection.py and 2 other locations - About 6 hrs to fix
          LowVoltage/connection/connection.py on lines 393..399
          LowVoltage/connection/connection.py on lines 426..432

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

          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 test_server_error_with_correct_json(self):
                  self.requests_response.expect.status_code.andReturn(500)
                  self.requests_response.expect.json().andReturn({"__type": "NobodyKnewThisCouldHappen", "Message": "tralala"})
          
                  with self.assertRaises(_exn.ServerError) as catcher:
          Severity: Major
          Found in LowVoltage/connection/connection.py and 2 other locations - About 6 hrs to fix
          LowVoltage/connection/connection.py on lines 360..366
          LowVoltage/connection/connection.py on lines 426..432

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

          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 test_unknown_error_with_json_without_type(self):
                  self.requests_response.expect.status_code.andReturn(750)
                  self.requests_response.expect.json().andReturn({"Message": "tralala"})
          
                  with self.assertRaises(_exn.UnknownError) as catcher:
          Severity: Major
          Found in LowVoltage/connection/connection.py and 2 other locations - About 5 hrs to fix
          LowVoltage/connection/connection.py on lines 368..374
          LowVoltage/connection/connection.py on lines 401..407

          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

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

              def test_unknown_client_error_with_json_without_type(self):
                  self.requests_response.expect.status_code.andReturn(400)
                  self.requests_response.expect.json().andReturn({"Message": "tralala"})
          
                  with self.assertRaises(_exn.UnknownClientError) as catcher:
          Severity: Major
          Found in LowVoltage/connection/connection.py and 2 other locations - About 5 hrs to fix
          LowVoltage/connection/connection.py on lines 401..407
          LowVoltage/connection/connection.py on lines 434..440

          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

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

              def test_server_error_with_json_without_type(self):
                  self.requests_response.expect.status_code.andReturn(500)
                  self.requests_response.expect.json().andReturn({"Message": "tralala"})
          
                  with self.assertRaises(_exn.ServerError) as catcher:
          Severity: Major
          Found in LowVoltage/connection/connection.py and 2 other locations - About 5 hrs to fix
          LowVoltage/connection/connection.py on lines 368..374
          LowVoltage/connection/connection.py on lines 434..440

          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

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

              def test_unknown_client_error_with_non_dict_json(self):
                  self.requests_response.expect.status_code.andReturn(400)
                  self.requests_response.expect.json().andReturn(["Message", "tralala"])
          
                  with self.assertRaises(_exn.UnknownClientError) as catcher:
          Severity: Major
          Found in LowVoltage/connection/connection.py and 2 other locations - About 5 hrs to fix
          LowVoltage/connection/connection.py on lines 409..415
          LowVoltage/connection/connection.py on lines 442..448

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

          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 test_unknown_error_with_non_dict_json(self):
                  self.requests_response.expect.status_code.andReturn(750)
                  self.requests_response.expect.json().andReturn(["Message", "tralala"])
          
                  with self.assertRaises(_exn.UnknownError) as catcher:
          Severity: Major
          Found in LowVoltage/connection/connection.py and 2 other locations - About 5 hrs to fix
          LowVoltage/connection/connection.py on lines 376..382
          LowVoltage/connection/connection.py on lines 409..415

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

          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 test_server_error_with_non_dict_json(self):
                  self.requests_response.expect.status_code.andReturn(500)
                  self.requests_response.expect.json().andReturn(["Message", "tralala"])
          
                  with self.assertRaises(_exn.ServerError) as catcher:
          Severity: Major
          Found in LowVoltage/connection/connection.py and 2 other locations - About 5 hrs to fix
          LowVoltage/connection/connection.py on lines 376..382
          LowVoltage/connection/connection.py on lines 442..448

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

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

                  try:
                      r = self.__session.post(self.__endpoint, data=payload, headers=headers)
                  except requests.exceptions.RequestException as e:
                      raise _exn.NetworkError(e)
                  except Exception as e:
          Severity: Major
          Found in LowVoltage/connection/connection.py and 2 other locations - About 45 mins to fix
          LowVoltage/connection/credentials.py on lines 86..91
          LowVoltage/connection/credentials.py on lines 119..124

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

          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