Improve tests

- refactor tests to avoid code duplication and flake8 reports
- raised coverage to 80%