Exemple #1
0
    def dummy_store(self, is_global):
        server = MagicMock()
        server.__dict__ = {"host": "http://1.2.2.2/xcode/api", "port": "8080"}

        user = MagicMock()
        user.__dict__ = {"user": "******", "password": "******"}
        settings = Settings(server, user)
        settings.store(is_global, "test_xserverpy")
Exemple #2
0
    def dummy_store(self, is_global):
        server = MagicMock()
        server.__dict__ = {"host": "http://1.2.2.2/xcode/api", "port": "8080"}

        user = MagicMock()
        user.__dict__ = {"user": "******", "password": "******"}
        settings = Settings(server, user)
        settings.store(is_global, "test_xserverpy")
Exemple #3
0
    def test_can_save_to_local_file(self):

        server = MagicMock()
        server.__dict__ = {"host": "123123", "port": "8080"}

        user = MagicMock()
        user.__dict__ = {"user": "******", "password": "******"}

        self.assertEqual(os.path.exists(".test_xserverpy"), False)
        settings = Settings(server, user)
        settings.store(False, "test_xserverpy")
        self.assertEqual(os.path.exists(".test_xserverpy"), True)
Exemple #4
0
    def test_can_save_to_local_file(self):

        server = MagicMock()
        server.__dict__ = {"host": "123123", "port": "8080"}

        user = MagicMock()
        user.__dict__ = {"user": "******", "password": "******"}

        self.assertEqual(os.path.exists(".test_xserverpy"), False)
        settings = Settings(server, user)
        settings.store(False, "test_xserverpy")
        self.assertEqual(os.path.exists(".test_xserverpy"), True)
Exemple #5
0
    def test_returns_none_if_no_file(self):
        path = os.path.expanduser("~/.test_xserverpy")
        self.assertEqual(os.path.exists(path), False)
        self.assertEqual(os.path.exists(".test_xserverpy"), False)

        settings = Settings.load("test_xserverpy")
        self.assertIsInstance(settings, EmptySettings)
Exemple #6
0
    def test_can_updated_a_non_empty_with_user_and_server(self):
        self.dummy_store(False)
        path = os.path.expanduser("~/.test_xserverpy")
        self.assertEqual(os.path.exists(path), False)
        self.assertEqual(os.path.exists(".test_xserverpy"), True)

        settings = Settings.load("test_xserverpy")
        self.assertEqual(settings.server.host, "http://1.2.2.2/xcode/api")
        self.assertEqual(settings.server.port, "8080")
        self.assertEqual(settings.user.user, "testuser")
        self.assertEqual(settings.user.password, "password")

        server = MagicMock()
        server.__dict__ = {"host": "http://1.2.2.4/xcode/api", "port": "80820"}

        user = MagicMock()
        user.__dict__ = {"user": "******", "password": "******"}
        settings.update(server, user)
        self.assertEqual(settings.server.host, "http://1.2.2.4/xcode/api")
        self.assertEqual(settings.server.port, "80820")
        self.assertEqual(settings.user.user, "testuser2")
        self.assertEqual(settings.user.password, "2222")

        # If value is none, dont overwrite it
        server = MagicMock()
        server.__dict__ = {"host": None, "port": None}

        user = MagicMock()
        user.__dict__ = {"user": "******", "password": "******"}
        settings.update(server, user)
        self.assertEqual(settings.server.host, "http://1.2.2.4/xcode/api")
        self.assertEqual(settings.server.port, "80820")
        self.assertEqual(settings.user.user, "testuser2")
        self.assertEqual(settings.user.password, "2222")
Exemple #7
0
    def test_returns_none_if_no_file(self):
        path = os.path.expanduser("~/.test_xserverpy")
        self.assertEqual(os.path.exists(path), False)
        self.assertEqual(os.path.exists(".test_xserverpy"), False)

        settings = Settings.load("test_xserverpy")
        self.assertIsInstance(settings, EmptySettings)
Exemple #8
0
    def test_can_updated_a_non_empty_with_user_and_server(self):
        self.dummy_store(False)
        path = os.path.expanduser("~/.test_xserverpy")
        self.assertEqual(os.path.exists(path), False)
        self.assertEqual(os.path.exists(".test_xserverpy"), True)

        settings = Settings.load("test_xserverpy")
        self.assertEqual(settings.server.host, "http://1.2.2.2/xcode/api")
        self.assertEqual(settings.server.port, "8080")
        self.assertEqual(settings.user.user, "testuser")
        self.assertEqual(settings.user.password, "password")

        server = MagicMock()
        server.__dict__ = {"host": "http://1.2.2.4/xcode/api", "port": "80820"}

        user = MagicMock()
        user.__dict__ = {"user": "******", "password": "******"}
        settings.update(server, user)
        self.assertEqual(settings.server.host, "http://1.2.2.4/xcode/api")
        self.assertEqual(settings.server.port, "80820")
        self.assertEqual(settings.user.user, "testuser2")
        self.assertEqual(settings.user.password, "2222")

        # If value is none, dont overwrite it
        server = MagicMock()
        server.__dict__ = {"host": None, "port": None}

        user = MagicMock()
        user.__dict__ = {"user": "******", "password": "******"}
        settings.update(server, user)
        self.assertEqual(settings.server.host, "http://1.2.2.4/xcode/api")
        self.assertEqual(settings.server.port, "80820")
        self.assertEqual(settings.user.user, "testuser2")
        self.assertEqual(settings.user.password, "2222")
Exemple #9
0
    def test_can_load_from_local_file(self):
        self.dummy_store(False)
        path = os.path.expanduser("~/.test_xserverpy")
        self.assertEqual(os.path.exists(path), False)
        self.assertEqual(os.path.exists(".test_xserverpy"), True)

        settings = Settings.load("test_xserverpy")
        self.assertEqual(settings.server.host, "http://1.2.2.2/xcode/api")
        self.assertEqual(settings.server.port, "8080")
        self.assertEqual(settings.user.user, "testuser")
        self.assertEqual(settings.user.password, "password")
Exemple #10
0
    def test_can_load_from_local_file(self):
        self.dummy_store(False)
        path = os.path.expanduser("~/.test_xserverpy")
        self.assertEqual(os.path.exists(path), False)
        self.assertEqual(os.path.exists(".test_xserverpy"), True)

        settings = Settings.load("test_xserverpy")
        self.assertEqual(settings.server.host, "http://1.2.2.2/xcode/api")
        self.assertEqual(settings.server.port, "8080")
        self.assertEqual(settings.user.user, "testuser")
        self.assertEqual(settings.user.password, "password")
Exemple #11
0
    def test_validates_correctly(self):
        server = MagicMock()
        server.__dict__ = {"host": None, "port": "80820"}

        user = MagicMock()
        user.__dict__ = {"user": "******", "password": "******"}
        settings = Settings(server, user)

        with self.assertRaises(RuntimeError):
            settings.validate()

        server = MagicMock()
        server.__dict__ = {"host": "http://1.2.2.2/xcode/api", "port": None}
        settings.server = server
        with self.assertRaises(RuntimeError):
            settings.validate()
Exemple #12
0
    def test_validates_correctly(self):
        server = MagicMock()
        server.__dict__ = {"host": None, "port": "80820"}

        user = MagicMock()
        user.__dict__ = {"user": "******", "password": "******"}
        settings = Settings(server, user)

        with self.assertRaises(RuntimeError):
            settings.validate()

        server = MagicMock()
        server.__dict__ = {"host": "http://1.2.2.2/xcode/api", "port": None}
        settings.server = server
        with self.assertRaises(RuntimeError):
            settings.validate()
Exemple #13
0
 def setUp(self):
     user = User(user="******", password="******")
     server = XcodeServer(host="https://127.0.0.1")
     self.settings = Settings(server, user)