{"action":"created","issue":{"url":"https://api.github.com/repos/kizniche/Mycodo/issues/128","repository_url":"https://api.github.com/repos/kizniche/Mycodo","labels_url":"https://api.github.com/repos/kizniche/Mycodo/issues/128/labels{/name}","comments_url":"https://api.github.com/repos/kizniche/Mycodo/issues/128/comments","events_url":"https://api.github.com/repos/kizniche/Mycodo/issues/128/events","html_url":"https://github.com/kizniche/Mycodo/issues/128","id":184710906,"number":128,"title":"Refactor to introduce testing","user":{"login":"etiology","id":5456095,"avatar_url":"https://avatars.githubusercontent.com/u/5456095?v=3","gravatar_id":"","url":"https://api.github.com/users/etiology","html_url":"https://github.com/etiology","followers_url":"https://api.github.com/users/etiology/followers","following_url":"https://api.github.com/users/etiology/following{/other_user}","gists_url":"https://api.github.com/users/etiology/gists{/gist_id}","starred_url":"https://api.github.com/users/etiology/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/etiology/subscriptions","organizations_url":"https://api.github.com/users/etiology/orgs","repos_url":"https://api.github.com/users/etiology/repos","events_url":"https://api.github.com/users/etiology/events{/privacy}","received_events_url":"https://api.github.com/users/etiology/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-10-23T19:45:53Z","updated_at":"2016-10-31T16:23:38Z","closed_at":null,"body":"Currently we have less than 10 tests that can only check if the Flask UI is running and if some pages redirect to a login page for unknown users.  In order for this project to grow in a healthy way it's going to need more tests and more test coverage so that refactoring can improve the code quality.  Right now it takes me about 2-3 hours to restore a raspberry pi from a base image, install the mycodo app, and start clicking around just to see if new code broke anything.\n\nThis `Refactor to introduce testing`issue is a broad issue that will be broken up into smaller steps.  There are several smaller refactors that need to take place before tests can even be written.  Too many places in the code are reimplementing connections to other places and it means that we'd have to patch every single one of them to run just one unit test.\n\nHere is a table describing an issue and a prescribed solution (more will be added later):\n\n| issue | solution |\n| :-: | :-: |\n| Too many areas of code rebuild/reimplement their setups preventing a single way of configuring all of them.  Examples can be found in the DB setups where sqlalchemy URIs are rebuilt in multiple modules which means that each one needs to be modified if they are to be tested. [ [1](https://github.com/kizniche/Mycodo/blob/c0df5dc7a9c06255eceb54f8a28c1ad84da39279/mycodo/scripts/initialize_relays.py#L32), [2](https://github.com/kizniche/Mycodo/blob/40f832904dfb93107edece9a2783dc448e528ab9/mycodo/controller_log.py#L33), [3](https://github.com/kizniche/Mycodo/blob/840401471efc94ceca30908108ff030df89802e8/mycodo/controller_timer.py#L23), [4](https://github.com/kizniche/Mycodo/blob/4a4d1c10c3a8304ab9478266451be2941c748fcb/mycodo/config.py#L62), [5](https://github.com/kizniche/Mycodo/blob/58e8a9e3773fb6be67b6963f0c2a18d26c6b37e0/init_databases.py#L42), [6](https://github.com/kizniche/Mycodo/blob/40f832904dfb93107edece9a2783dc448e528ab9/mycodo/controller_lcd.py#L74), [7](https://github.com/kizniche/Mycodo/blob/840401471efc94ceca30908108ff030df89802e8/mycodo/controller_pid.py#L54), [8](https://github.com/kizniche/Mycodo/blob/840401471efc94ceca30908108ff030df89802e8/mycodo/mycodo_daemon.py#L87), [9](https://github.com/kizniche/Mycodo/blob/3d3f0d61d39e1382fb9160cb94466b98ed3a7b84/mycodo/controller_relay.py#L37), [10](https://github.com/kizniche/Mycodo/blob/4a4d1c10c3a8304ab9478266451be2941c748fcb/mycodo/controller_sensor.py#L59), [11](https://github.com/kizniche/Mycodo/blob/4a4d1c10c3a8304ab9478266451be2941c748fcb/mycodo/flaskutils.py#L65)] | Implement a [configuration objects](https://github.com/tylergaw/supporters-python-flask/blob/20a84963d75f29fc5cfc5488768439fe794d77bb/supporter_signup/config.py) and [application factories](http://flask.pocoo.org/docs/0.11/patterns/appfactories/).  Setup should happen once for each independent application.  There are basically two apps in this repo: **1)** The `Flask UI`, and **2)** the `daemon service`.  **Each one should configure their service from a single config object** |\n"},"comment":{"url":"https://api.github.com/repos/kizniche/Mycodo/issues/comments/257341930","html_url":"https://github.com/kizniche/Mycodo/issues/128#issuecomment-257341930","issue_url":"https://api.github.com/repos/kizniche/Mycodo/issues/128","id":257341930,"user":{"login":"kizniche","id":838427,"avatar_url":"https://avatars.githubusercontent.com/u/838427?v=3","gravatar_id":"","url":"https://api.github.com/users/kizniche","html_url":"https://github.com/kizniche","followers_url":"https://api.github.com/users/kizniche/followers","following_url":"https://api.github.com/users/kizniche/following{/other_user}","gists_url":"https://api.github.com/users/kizniche/gists{/gist_id}","starred_url":"https://api.github.com/users/kizniche/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kizniche/subscriptions","organizations_url":"https://api.github.com/users/kizniche/orgs","repos_url":"https://api.github.com/users/kizniche/repos","events_url":"https://api.github.com/users/kizniche/events{/privacy}","received_events_url":"https://api.github.com/users/kizniche/received_events","type":"User","site_admin":false},"created_at":"2016-10-31T16:23:38Z","updated_at":"2016-10-31T16:23:38Z","body":"> For some reason I would rather have each test as a tuple (endpoint, thing_to_find_there).\r\n\r\nI actually started [using tuples with the latest commit](https://github.com/kizniche/Mycodo/blob/mycodo_dev/mycodo/tests/software_tests/test_mycodo_flask/test_endpoints.py#L272-L304). Right now there's a check if it's a tuple, but I think moving them all to tuples would be better for consistency.\r\n\r\n> I wouldn't include the print, for tests it just too verbose. Having it only speak when it fails is preferred since later you may have hundreds of tests. \r\n\r\nGood idea. I'll change that later today to a message from the assert.\r\n\r\n> If `norm_user` is an admin then it should be `admin_user` for clarity.\r\n\r\nGood point. I just copied what you had written just to get it working initially. I'll also change this later."}}
{"actor":{"display_login":"kizniche"}}