Example #1
0
 def test_cli_remove_correct(self):
     args = cli.parse_args([
         "traffic-object", "--remove",
         "805e130b-3e54-11e8-819f-a0c5897a10ac"
     ])
     r = cli.dispatch(args)
     self.assertEqual(r["status"], 200)
Example #2
0
    def test_cli_add_correct(self):
        data = {"name": "object1", "protocol": "UDP"}
        args = cli.parse_args([
            "traffic-object", '--add', '{"name": "object1", "protocol": "UDP"}'
        ])
        r = cli.dispatch(args)
        self.assertEqual(r["status"], 200)

        connection = traffic.getConnection()
        cur = connection.cursor()
        cur.execute("SELECT * from trafficObjects where uuid=:id",
                    {"id": r["uuid"]})
        list = cur.fetchone()

        for i in data:
            self.assertTrue(data[i] in list)
Example #3
0
def main():
    logging_setup()

    args = cli.parse_args()

    # TODO better log configuration (e.g. file-based logging)
    if args.verbose:
        coloredlogs.install(level="DEBUG")
    else:
        coloredlogs.install(level="INFO")

    traffic.start_dbconnection("traffic.db")

    if 'service_address' in args and 'service_port' in args:
        # Run in service mode
        rest.serve(args)
    else:
        # Run in CLI mode
        cli.dispatch(args)
Example #4
0
 def test_cli_remove_incorrect(self):
     args = cli.parse_args(["traffic-object", "--remove", "incorrect-id"])
     r = cli.dispatch(args)
     self.assertEqual(r["status"], 404)
Example #5
0
 def test_cli_list(self):
     args = cli.parse_args(["traffic-object", "--list"])
     r = cli.dispatch(args)
     self.assertEqual(r["status"], 200)
Example #6
0
 def test_cli_add_incorrect(self):
     args = cli.parse_args(
         ["traffic-object", "--add", '{"name": "object1"}'])
     r = cli.dispatch(args)
     self.assertEqual(r["status"], 400)