How to import keys in intern 4? - intern

I'm trying to press tab key in one of my test using intern framework but i'm unable to do so . I have tried using
var keys = require("keys"); ,
import * as keys from keys and
var keys = require("leadfoot/keys");
but non of these worked i am getting Cannot find module error can someone please help.
Thanks.

You can import the keys module as follows:
const keys = require('#theintern/leadfoot/keys').default;

Related

Executing UDF ( User Defined function ) containing a Node module in Cosmos Db

I have created a UDF function to process some content based on dates in Azure cosmos database. The function looks like below
function userDefinedFunction(array,dateString){
var moment = require('moment');
const startDate = moment(dateString);
const endDate = moment(dateString).add(1,'days');
// filter the array by the dates and return a value
}
When the above UDF is used inside a query the following error message is thrown .
Encountered exception while executing Javascript. Exception = ReferenceError: 'require' is not defined
This error is seemed to be an error orginating from incorrect import of the moment node module.
i have already tried checking on the microsoft offcial docs about the UDFs and using of node module inside UDF.
I tried surfing through the internet about this issue, but both the methods did not provide me with satisfactory answer.
so i would like to know how to import a node module and use it inside an UDF function . Thanks a lot in advance .
Importing modules is not supported for any of the service-side features including stored procedures, triggers and user-defined functions.
This is not currently documented. Will ask for this to be updated.

Function service_account.Credentials.from_service_account_info() not working

I'm writing an application based on GCP services and I need to access to an external project. I stored on my Firestore database the authentication file's informations of the other project I need to access to. I read this documentation and I tried to apply it but my code does not work. As the documentaion says, what I pass to the authentication method is a dictionary[str, str].
This is my code:
from googleapiclient import discovery
from google.oauth2 import service_account
from google.cloud import firestore
project_id = body['project_id']
user = body['user']
snap_id = body['snapshot_id']
debuggee_id = body['debuggee_id']
db = firestore.Client()
ref = db.collection(u'users').document(user).collection(u'projects').document(project_id)
if ref.get().exists:
service_account_info = ref.get().to_dict()
else:
return None, 411
credentials = service_account.Credentials.from_service_account_info(
service_account_info,
scopes=['https://www.googleapis.com/auth/cloud-platform'])
service = discovery.build('clouddebugger', 'v2', credentials=credentials)
body is just a dictionary containing all the informations of the other project. What I can't understand is why this doesn't work and instead using the method from_service_account_file it works.
The following code will give to that method the same informations of the previous code, but inside a json file instead of a dictionary. Maybe the order of the elements is different, but I think that it doesn't matter at all.
credentials = service_account.Credentials.from_service_account_file(
[PATH_TO_PROJECT_KEY_FILE],
scopes=['https://www.googleapis.com/auth/cloud-platform'])
Can you tell me what I'm doing wrong with the method from_service_account_info?
Problem solved. When I posted the question I manually inserted from the GCP Firestore Console all the info about the other project. Then I wrote the code to make it authomatically and it worked. Honestly I don't know why it didn't worked before, the informations put inside Firestore were the same and the format as well.

nodejs gremlin update if exist or else create

I am using nodejs gremlin against AWS neptune, the requirement is to update properties if vertice exist, or else, create a new vertice, i tried below
g.V().has('event','id','1').
fold().
coalesce(unfold(),
addV('event').property('id','1'))
but I got 'unfold is not defined' error, how do I resolve this?
You probably just need to import unfold() properly. Some common imports for working with Gremlin can be found here but in your case I think you just need to do:
const __ = gremlin.process.statics
and then refer to unfold() as __.unfold() - or just import unfold() as a function explicitly to use it as you were using it.

Web Service returns: sqlite3.OperationalError: no such table:

I'm trying to set up some simple web service with Python and Flask and SQlite3. It doesn't work.
The DB connection without web service works; the web service without DB connections works. Together they don't.
if I run this, it works:
import sqlite3
conn = sqlite3.connect('scuola.db')
sql = "SELECT matricola,cognome,nome FROM studenti"
cur = conn.cursor()
cur.execute(sql)
risultato = cur.fetchall()
conn.close()
print(risultato)
(so query is correct)
and if I run this, it works
import flask
app = flask.Flask(__name__)
def funzione():
return 'Applicazione Flask'
app.add_url_rule('/', 'funzione', funzione)
but if I run this...
from flask import Flask
import sqlite3
app = Flask(__name__)
#app.route('/',methods=['GET'])
def getStudenti():
conn = sqlite3.connect('scuola.db')
sql = "SELECT matricola,cognome,nome FROM studenti"
cur = conn.cursor()
cur.execute(sql)
risultato = cur.fetchall()
conn.close()
return risultato
It returns Internal Server Error in the browser, and
sqlite3.OperationalError: no such table: studenti
on the DOS prompt.
Thank you for your help!
You haven't provided the internal server error output - but my first guess is that you're trying to return the raw list object returned from fetchall.
When returning from a view function you need to send the results either by returning a template, or by jsonifying the output to make it a proper HTTP response that the browser can receive.
You need to add
from flask import jsonify
in your imports, then when returning;
return jsonify(risultato)
If you get errors like something is not JSON serializable if means you're trying to send an instance of a class or similar. You'll need to make sure you're returning only plain python data structures (e.g. list/dict/str etc).
For the command line problem, you need to make sure you've ran a CREATE TABLE command to first generate the table in the database, before you select from it. Also check you're accessing the correct sqlite database file with the table in it.
I'm not sure, but from the look of things I don't think you've configured the flask app to support the db you created There should be some sort of app.config() that integrates the db.

NetSuite Crypto createHmac showing invalid algorithm value

I am using the crypto module in NetSuite SuiteScript 2.0 . I am using the createHmac method in crypto like below
var hmacSignature = crypto.createHmac({
algorithm: crypto.HashAlg.SHA1 ,
key: sKey
});
I am getting a invalid Type Argument for 'algorithm' value. This is the specified way to set the type as given on NetSuite SuiteScript PDF. What am I doing wrong??
Thanks to Krypton , I could solve this problem by passing a crypto.SecretKey object by generating it using crypto.CreateSecretKey method

Resources