Get tox working 87/14687/1
authorMichael Hwang <mhwang@research.att.com>
Fri, 22 Sep 2017 14:05:05 +0000 (10:05 -0400)
committerMichael Hwang <mhwang@research.att.com>
Fri, 22 Sep 2017 17:04:33 +0000 (13:04 -0400)
* Use public onap dependencies
* Make to work with tox
* Fix unit tests

Change-Id: I08ed9fa33003f4ec017818f61acf83b9f29ec9a3
Issue-Id: DCAEGEN2-60
Signed-off-by: Michael Hwang <mhwang@research.att.com>
dcae-cli/.coveragerc [new file with mode: 0644]
dcae-cli/dcae_cli/util/tests/test_config.py
dcae-cli/dcae_cli/util/tests/test_profiles.py
dcae-cli/requirements.txt
dcae-cli/setup.py
dcae-cli/tox.ini [new file with mode: 0644]

diff --git a/dcae-cli/.coveragerc b/dcae-cli/.coveragerc
new file mode 100644 (file)
index 0000000..088c2da
--- /dev/null
@@ -0,0 +1,21 @@
+# .coveragerc to control coverage.py
+[run]
+branch = True
+
+[report]
+# Regexes for lines to exclude from consideration
+exclude_lines =
+    # Have to re-enable the standard pragma
+    pragma: no cover
+
+    # Don't complain about missing debug-only code:
+    def __repr__
+    if self\.debug
+
+    # Don't complain if tests don't hit defensive assertion code:
+    raise AssertionError
+    raise NotImplementedError
+
+    # Don't complain if non-runnable code isn't run:
+    if 0:
+    if __name__ == .__main__.:
index 82f0679..3b4cd6e 100644 (file)
@@ -66,7 +66,8 @@ def test_init_config(monkeypatch):
     monkeypatch.setattr("dcae_cli._version.__version__", "2.X.X")
 
     expected = {'cli_version': '2.X.X', 'user': 'bigmama', 'db_url': 'conn',
-            'server_url': 'http://some-nexus-in-the-sky.com'}
+            'server_url': 'http://some-nexus-in-the-sky.com',
+            'active_profile': 'default' }
     assert expected == config._init_config()
 
     # Test using of db fallback
@@ -74,12 +75,20 @@ def test_init_config(monkeypatch):
     monkeypatch.setattr(dcae_cli.util, 'fetch_file_from_web',
             lambda server_url, path: { "db_url": "" })
 
-    assert "sqlite" in config._init_config()["db_url"]
+    db_url = "postgresql://king:of@mountain:5432/dcae_onboarding_db"
+
+    def fake_init_config_db_url():
+        return db_url
+
+    monkeypatch.setattr(config, "_init_config_db_url",
+            fake_init_config_db_url)
+
+    assert db_url == config._init_config()["db_url"]
 
     monkeypatch.setattr(dcae_cli.util, 'fetch_file_from_web',
             lambda server_url, path: {})
 
-    assert "sqlite" in config._init_config()["db_url"]
+    assert db_url == config._init_config()["db_url"]
 
     # Simulate error trying to fetch
 
@@ -88,6 +97,8 @@ def test_init_config(monkeypatch):
 
     monkeypatch.setattr(dcae_cli.util, 'fetch_file_from_web',
             fetch_simulate_error)
+    # Case when user opts out of manually setting up
+    monkeypatch.setattr(click, "confirm", lambda msg: False)
 
     with pytest.raises(config.ConfigurationInitError):
         config._init_config()
index b15d9b5..969697a 100644 (file)
@@ -150,6 +150,8 @@ def test_reinit_profiles(monkeypatch, tmpdir):
         raise RuntimeError("Mysterious error")
 
     monkeypatch.setattr(util, "fetch_file_from_web", fetch_failure)
+    # Case when user opts out of manually setting up
+    monkeypatch.setattr(click, "confirm", lambda msg: False)
 
     with pytest.raises(profiles.ProfilesInitError):
         profiles.reinit_profiles()
index 52d5aa1..03244e7 100644 (file)
@@ -1,5 +1,4 @@
 # TODO: May need to add the following line
-# --extra-index-url <onap pypi url>
 python-consul==0.6.1
 six==1.10.0
 SQLAlchemy==1.1.4
@@ -8,7 +7,7 @@ click==6.6
 jsonschema==2.5.1
 docker-py==1.10.6
 terminaltables==3.1.0
-python-discovery-client==2.0.0
-python-dockering==1.2.1
+onap-dcae-discovery-client==2.1.0
+onap-dcae-dockering==1.3.0
 psycopg2==2.7.1
 genson==0.2.2
index 8c6405c..9cfdd3f 100644 (file)
@@ -32,7 +32,7 @@ with open(os.path.join(setup_dir, 'dcae_cli', '_version.py')) as file:
 
 
 setup(
-    name = "dcae_cli",
+    name = "onap-dcae-cli",
     version = __version__,
     packages = find_packages(),
     author = "Michael Hwang, Paul Triantafyllou, Tommy Carpenter",
@@ -48,12 +48,11 @@ setup(
                       'SQLAlchemy-Utils',
                       'click',
                       'jsonschema',
-                      'docker-py>=1.10,<2',
                       'terminaltables',
                       'psycopg2',
                       'genson',
-                      'python-discovery-client>=2.0.0',
-                      'python-dockering>=1.0.0,<2.0.0'
+                      'onap-dcae-discovery-client>=2.0.0',
+                      'onap-dcae-dockering>=1.0.0,<2.0.0'
                       ],
     tests_require=['pytest',
                    'mock'],
diff --git a/dcae-cli/tox.ini b/dcae-cli/tox.ini
new file mode 100644 (file)
index 0000000..b0f267a
--- /dev/null
@@ -0,0 +1,11 @@
+# content of: tox.ini , put in same dir as setup.py
+[tox]
+envlist = py27,py35
+
+[testenv]
+deps=
+    pytest
+    coverage
+    pytest-cov
+    mock
+commands=pytest --junitxml xunit-results.xml --cov {envsitepackagesdir}/dcae_cli --cov-report=xml