示例#1
0
    def run(self):
        """
        Runs the commands for each parser.
        """
        if self.parser_args.topic == "cert":
            self.jwt = DojotAPI.get_jwt()
            self.cert_commands()

        elif self.parser_args.topic == "dojot":
            self.jwt = DojotAPI.get_jwt()
            if self.parser_args.dojot == "create":
                self.dojot_create_commands()
            if self.parser_args.dojot == "clear":
                self.dojot_clear_commands()

        elif self.parser_args.topic == "redis":
            self.redis_commands()
示例#2
0
    def get_jwt(self):
        """
        Retrieves the JWT from the dadtabase or create a new one.
        """
        jwt = self.mapped.get('jwt')

        if jwt:
            return jwt.decode('utf-8')

        jwt = DojotAPI.get_jwt()
        self.mapped.setex('jwt', CONFIG['locust']['redis']['jwt_expire_time'], jwt)

        return jwt
示例#3
0
    def redis_commands(self):
        """
        Redis commands execution.
        """
        if self.parser_args.restore:
            self.restore_db_state()

        elif self.parser_args.clear:
            self.clear_db()
            self.restore_db_state()

        elif self.parser_args.map:
            self.map_device_ids()

        elif self.parser_args.export:
            # Retrieve JWT token
            self.jwt = DojotAPI.get_jwt()
            # Exports the certificates' files
            self.export_certs()
            # Retrieving the CA certificate
            self.retrieve_ca_cert()
示例#4
0
    def test_successfully_get_jwt(self, mock_requests):
        """
        Should successfully get a JWT from Dojot.
        """
        args = {
            "url": "{0}/auth".format(MOCK_CONFIG['dojot']['url']),
            "data": json.dumps({
                "username": MOCK_CONFIG['dojot']['user'],
                "passwd": MOCK_CONFIG['dojot']['passwd'],
            }),
            "headers": {
                "Accept": "application/json",
                "Content-Type": "application/json"
            },
        }
        DojotAPI.call_api.return_value = {"jwt": "testJWT"}

        jwt = DojotAPI.get_jwt()

        DojotAPI.call_api.assert_called_once()
        DojotAPI.call_api.assert_called_with(mock_requests.post, args)
        self.assertEqual(jwt, "testJWT")