def test_create_token(self):
        runner = create_app().test_cli_runner()
        generate = runner.invoke(cli, ["--config-path", self.path, "generate", "-m", 1])
        name1 = generate.output.strip()

        status = runner.invoke(cli, ["--config-path", self.path, "status", "-s", name1])
        valid, info_dict_string = status.output.strip().split("\n", 1)
        self.assertEqual(valid, "This token is valid")
        comparison_dict = {
            "name": name1,
            "used": 0,
            "expiration_date": None,
            "max_usage": 1,
            "disabled": False,
            "ips": [],
            "active": True,
        }
        self.assertEqual(json.loads(info_dict_string), comparison_dict)

        runner.invoke(cli, ["--config-path", self.path, "status", "-d", name1])
        status = runner.invoke(cli, ["--config-path", self.path, "status", "-s", name1])
        valid, info_dict_string = status.output.strip().split("\n", 1)
        self.assertEqual(valid, "This token is not valid")
        comparison_dict = {
            "name": name1,
            "used": 0,
            "expiration_date": None,
            "max_usage": 1,
            "disabled": True,
            "ips": [],
            "active": False,
        }
        self.assertEqual(json.loads(info_dict_string), comparison_dict)

        generate = runner.invoke(
            cli, ["--config-path", self.path, "generate", "-e", "2220-05-12"]
        )
        name2 = generate.output.strip()

        status = runner.invoke(cli, ["--config-path", self.path, "status", "-s", name2])
        valid, info_dict_string = status.output.strip().split("\n", 1)
        self.assertEqual(valid, "This token is valid")
        comparison_dict = {
            "name": name2,
            "used": 0,
            "expiration_date": "2220-05-12 00:00:00",
            "max_usage": 0,
            "disabled": False,
            "ips": [],
            "active": True,
        }
        self.assertEqual(json.loads(info_dict_string), comparison_dict)

        status = runner.invoke(cli, ["--config-path", self.path, "status", "-l"])
        list = status.output.strip()
        self.assertEqual(list, f"{name1}, {name2}")
 def setUp(self):
     matrix_registration.config.config = Config(GOOD_CONFIG)
     app = create_app(testing=True)
     with app.app_context():
         app.config.from_mapping(
             SQLALCHEMY_DATABASE_URI=matrix_registration.config.config.db,
             SQLALCHEMY_TRACK_MODIFICATIONS=False)
         db.init_app(app)
         db.create_all()
         self.client = app.test_client()
     self.app = app
Beispiel #3
0
    def test_create_token(self):
        runner = create_app().test_cli_runner()
        generate = runner.invoke(
            cli, ['--config-path', self.path, 'generate', '-o'])
        name1 = generate.output.strip()

        status = runner.invoke(
            cli, ['--config-path', self.path, 'status', '-s', name1])
        valid, info_dict_string = status.output.strip().split('\n', 1)
        self.assertEqual(valid, "This token is valid")
        comparison_dict = {
            "name": name1,
            "used": 0,
            "ex_date": None,
            "one_time": True,
            "valid": True
        }
        self.assertEqual(json.loads(info_dict_string), comparison_dict)

        runner.invoke(cli, ['--config-path', self.path, 'status', '-d', name1])
        status = runner.invoke(
            cli, ['--config-path', self.path, 'status', '-s', name1])
        valid, info_dict_string = status.output.strip().split('\n', 1)
        self.assertEqual(valid, "This token is valid")
        comparison_dict = {
            "name": name1,
            "used": 0,
            "ex_date": "0001-01-01 00:00:00",
            "one_time": True,
            "valid": False
        }
        self.assertEqual(json.loads(info_dict_string), comparison_dict)

        generate = runner.invoke(
            cli, ['--config-path', self.path, 'generate', '-e', '2220-05-12'])
        name2 = generate.output.strip()

        status = runner.invoke(
            cli, ['--config-path', self.path, 'status', '-s', name2])
        valid, info_dict_string = status.output.strip().split('\n', 1)
        self.assertEqual(valid, "This token is valid")
        comparison_dict = {
            "name": name2,
            "used": 0,
            "ex_date": "2220-05-12 00:00:00",
            "one_time": False,
            "valid": True
        }
        self.assertEqual(json.loads(info_dict_string), comparison_dict)

        status = runner.invoke(cli,
                               ['--config-path', self.path, 'status', '-l'])
        list = status.output.strip()
        self.assertEqual(list, f"{name1}, {name2}")