def test_get_host_process_status(self, session, _HostMeta):
        _insert_data = SSHPermissionMeta(user_id=1, host_id=2)
        session.add(_insert_data)
        _HostMeta.get_all_hosts_status.return_value = {
            1: {
                "Hostname": "Marvin",
                "IP": "123.456.78.9"
            },
            2: {
                "Hostname": "Bob",
                "IP": "132.654.87.9"
            }
        }

        with mock.patch.object(
            SSHPermissionMeta, "query", session.query_property()
        ) as _query:
            ssh_permission_items = (
                SSHPermissionMeta.get_ssh_permission_by_user_id(user_id=1)
            )
            self.assertEqual(ssh_permission_items, {
                1: {
                    "Hostname": "Marvin",
                    "IP": "123.456.78.9",
                    "Has Permission": False
                },
                2: {
                    "Hostname": "Bob",
                    "IP": "132.654.87.9",
                    "Has Permission": True
                }
            })
示例#2
0
 def get(self):
     username = self.get_secure_cookie("username")
     user_id = UserMeta.query.filter_by(username=username).first().id
     self.write(
         SSHPermissionMeta.get_ssh_permission_by_user_id(user_id=user_id)
     )