"""
Created on May 7, 2017

@author: magnus
"""
import os
import unittest

from helper.secrets import Secrets


class TestSecretsMock(unittest.TestCase):
    def test_constructor(self):
        """Test constructor"""
        s = Secrets('secrets.skeleton.json')

        self.assertEqual(s.ip_addr, '0.0.0.0',
                         'IP address does not match what is expected from file')
        self.assertEqual(s.user_name, 'REPLACE_THIS_USERNAME_WITH_CORRECT_12345',
                         'User name does not match what is expected from file')


@unittest.skipIf("TRAVIS" in os.environ and os.environ["TRAVIS"] == "true", "Skipping this test on Travis CI.")
class TestSecrets(unittest.TestCase):
    def test_constructor(self):
        """Test constructor
        Cannot guess what the IP address will be.
        Therefore I will just look for a non-empty string
        """

        # Check that file exists
        s_file = 'secrets.json'
        try:
            with open(s_file):
                pass
        except FileNotFoundError:
            self.fail('FileNotFoundError: Could not find file. Can be generated from secrets.skeleton.json')

        s = Secrets(s_file)
        s_skeleton = Secrets('secrets.skeleton.json')

        self.assertNotEqual(s.ip_addr, '', 'IP address can not be empty string')
        self.assertNotEqual(s.user_name, '', 'Username can not be empty string')
        self.assertNotEqual(s.ip_addr, s_skeleton.ip_addr, 'IP address can not be the same as skeleton file')
        self.assertNotEqual(s.user_name, s_skeleton.user_name, 'User name can not be the same as skeleton file')


if __name__ == "__main__":
    # import sys;sys.argv = ['', 'Test.test_get_ip']
    unittest.main()
