示例#1
0
    def test_init(self):
        with self.assertRaises(BundleConfigError):
            TestModel(connection=Mockup())

        with self.assertRaises(ValueError):
            TestModel()

        event = Event()
        bundle = Bundle(bundle_dir=bundle_dir)
        tm = TestModel(bundle=bundle,
                       connection=Mockup(),
                       stop_event=event,
                       test_variable=True)

        # bypassing test_variable to init()
        self.assertTrue(tm.test_variable)
 def test_get_status_by_id_with_no_cid(self):
     self.cellular = Cellular(connection=Mockup())
     with patch("cellular.subprocess") as subprocess:
         self.cellular.cid = "1234"
         subprocess.check_output.return_value = True
         subprocess.call.return_value = True
         res = self.cellular.get_status_by_id(0)
         self.assertEqual(res, 2)
示例#3
0
    def setUp(self, mock_ifaddresses, mock_ifconfig, mock_ifupdown,
              mock_interfaces):
        # Setup the mock
        mock_interfaces.return_value = ["eth0", "eth1"]
        mock_ifaddresses.side_effect = mock_ip_ifaddresses

        self.name = "ethernet"
        self.bundle = Ethernet(connection=Mockup())
 def test_get_status_by_id_search_fail(self):
     self.cellular = Cellular(connection=Mockup())
     with patch("cellular.subprocess") as subprocess:
         subprocess.check_output.return_value =\
             "xxxx"
         subprocess.call.return_value = None
         res = self.cellular.get_status_by_id(0)
         self.assertEqual(res, 2)
 def setUp(self, set_pincode_by_id):
     sh.echo("1234, 1234", _out="/run/shm/cellular.tmp")
     try:
         os.unlink(dirpath + "/../data/cellular.json")
     except Exception:
         pass
     set_pincode_by_id.return_value = True
     self.cellular = Cellular(connection=Mockup())
 def test_set_offline_by_id_with_no_cid(self):
     self.cellular = Cellular(connection=Mockup())
     with patch("cellular.subprocess") as subprocess:
         subprocess.check_output.return_value = True
         self.cellular.cid = ""
         self.cellular.pdh = ""
         res = self.cellular.set_offline_by_id(0)
         self.assertEqual(res, True)
示例#7
0
 def setUp(self):
     root_path = os.path.dirname(os.path.realpath(__file__)) + "/../"
     try:
         os.unlink(root_path + "data/ntp.json")
         os.unlink(root_path + "data/ntp.json.backup")
     except:
         pass
     self.index = Index(connection=Mockup())
 def test_get_status_by_id_connect(self):
     self.cellular = Cellular(connection=Mockup())
     with patch("cellular.subprocess") as subprocess:
         subprocess.check_output.return_value =\
             "Connection status: 'connected'"
         subprocess.call.return_value = True
         res = self.cellular.get_status_by_id(0)
         self.assertEqual(res, 1)
示例#9
0
    def setUp(self):
        root_path = os.path.dirname(os.path.realpath(__file__)) + "/../"
        try:
            os.unlink(root_path + "data/{{cookiecutter.project_slug}}.json")
            os.unlink(root_path +
                      "data/{{cookiecutter.project_slug}}.json.backup")
        except Exception:
            pass

        self.index = Index(connection=Mockup())
示例#10
0
 def test_boot(self, Thread):
     Thread.return_value = Mock()
     options = {
         "bundle": Bundle(dirpath + "/mock_bundles/bundle_1"),
         "bundle_dir": os.path.normpath(dirpath + "/mock_bundles/bundle_1"),
         "connection": Mockup(),
         "stop_event": Event()
     }
     meta = self.sanjikeeper.boot(**options)
     self.assertIsInstance(meta, BundleMeta)
示例#11
0
    def test_route(self):
        bundle = Bundle(bundle_dir=bundle_dir)
        test_model = TestModel(connection=Mockup(), bundle=bundle)
        routes = test_model.router.routes
        self.assertIn("/model/test/:id", routes)
        self.assertEqual(4, len(routes["/model/test/:id"].handlers))
        self.assertIn("/model", routes)
        self.assertEqual(1, len(routes["/model"].handlers))
        self.assertIn("/model/:id", routes)
        self.assertEqual(3, len(routes["/model/:id"].handlers))

        # while test=True don't warp function
        def resp(test):
            self.assertTrue(test)

        test_model.mockup_handler(True, resp, test=True)
    def test_set_online_by_id(self):
        self.cellular = Cellular(connection=Mockup())
        self.cellular.model.db = [{
            'enable': 1,
            'name': 'wwan1',
            'modemPort': '/dev/ttyS0',
            'id': 0,
            'atPort': '/dev/ttyS0',
            'enableAuth': 1,
            'apn': 'internet',
            'authType': 'PAP',
            'username': '******',
            'password': '******'
        }]
        self.cellular.check_dhclient = Mock()
        with patch("cellular.subprocess") as subprocess:
            subprocess.check_output.\
                return_value = "\
                                Packet data handle: '123'\
                                CID: '23'"

            self.cellular.cid = "1234"
            res = self.cellular.set_online_by_id(0)
            self.assertEqual(res, True)
示例#13
0
 def setUp(self):
     self.bundle = Reboot(connection=Mockup())
     self.bundle.publish = MagicMock()
 def setUp(self):
     self.cellular = Cellular(connection=Mockup())
 def test_search_subnet_fail(self):
     self.cellular = Cellular(connection=Mockup())
     res = self.cellular.search_subnet()
     self.assertEqual(res, 'N/A')
 def test_search_subnet(self):
     self.cellular = Cellular(connection=Mockup())
     self.cellular.dhclient_info = self.filetext
     res = self.cellular.search_subnet()
     self.assertEqual(res, '255.255.0.0')
 def test_search_ip_fail(self):
     self.cellular = Cellular(connection=Mockup())
     self.cellular.dhclient_info = self.filetext_fail
     res = self.cellular.search_ip()
     self.assertEqual(res, 'N/A')
 def test_search_ip(self):
     self.cellular = Cellular(connection=Mockup())
     self.cellular.dhclient_info = self.filetext
     res = self.cellular.search_ip()
     self.assertEqual(res, '192.168.10.26')
 def test_get_cops_by_id_fail(self):
     self.cellular = Cellular(connection=Mockup())
     with patch("cellular.modemcmd") as modemcmd:
         modemcmd.return_value = ""
         res = self.cellular.get_cops_by_id(0)
         self.assertEqual(res, "Unknown Operator")
 def test_search_name(self):
     self.cellular = Cellular(connection=Mockup())
     self.cellular.dhclient_info = self.filetext
     res = self.cellular.search_name()
     self.assertEqual(res, 'eth0')
 def test_set_offline_by_id_exception(self):
     self.cellular = Cellular(connection=Mockup())
     with patch("cellular.subprocess") as subprocess:
         subprocess.check_output.side_effect = Exception
         res = self.cellular.set_offline_by_id(0)
         self.assertFalse(res)
示例#22
0
 def setUp(self, Thread):
     self.conn = Mockup()
     self.session = Session()
     self.publish = Publish(self.conn, self.session)
 def test_get_signal_by_id_fail(self):
     self.cellular = Cellular(connection=Mockup())
     with patch("cellular.subprocess") as subprocess:
         subprocess.check_output.return_value = ""
         res = self.cellular.get_signal_by_id(0)
         self.assertEqual(res, 99)
 def test_get_status_by_id_exception(self):
     self.cellular = Cellular(connection=Mockup())
     with patch("cellular.subprocess") as subprocess:
         subprocess.check_output.side_effect = Exception
         res = self.cellular.get_status_by_id(0)
         self.assertEqual(res, 2)
示例#25
0
 def setUp(self, Thread):
     self.bundle = Bundle(bundle_dir=bundle_dir)
     self.test_model = TestModel(connection=Mockup(), bundle=self.bundle)
 def test_get_cops_by_id(self):
     self.cellular = Cellular(connection=Mockup())
     with patch("cellular.modemcmd") as modemcmd:
         modemcmd.return_value = "+COPS: 0,0,\"Chunghwa Telecom\",2\r\nOK"
         res = self.cellular.get_cops_by_id(0)
         self.assertEqual(res, "Chunghwa Telecom")
示例#27
0
 def setUp(self, mock_update_default):
     self.name = "route"
     self.bundle = IPRoute(connection=Mockup())
 def test_search_dns(self):
     self.cellular = Cellular(connection=Mockup())
     self.cellular.dhclient_info = self.filetext
     res = self.cellular.search_dns()
     self.assertEqual(res, ["8.8.8.58", "20.20.20.20", "40.40.4.1"])
 def test_get_cops_by_id_exception(self):
     self.cellular = Cellular(connection=Mockup())
     with patch("cellular.modemcmd") as modemcmd:
         modemcmd.side_effect = Exception
         res = self.cellular.get_cops_by_id(0)
         self.assertEqual(res, "Unknown Operator")