<commit_before>"""
Submits the apks to BrowserStack to run the instrumentation tests.
"""

import os
import shlex
import subprocess
from subprocess import PIPE
import sys
import json

def appendData(command, dataUrl):
    var = 'data={\"url\": \"%s\"}' % dataUrl
    return command + " " + json.dumps(var)

def buildTestCommand(appToken, testToken):
    test = {}
    test["devices"] = ["LG G5-6.0"] #using just 1 device right now.
    test["app"] = appToken
    test["deviceLogs"] = True
    test["testSuite"] = testToken
    return json.dumps(json.dumps(test))

if __name__ == "__main__":

    if "BROWSERSTACK_USERNAME" in os.environ:
        userName = os.environ["BROWSERSTACK_USERNAME"]

    if "BROWSERSTACK_PASSWORD" in os.environ:
        password = <PASSWORD>["BROWSERSTACK_PASSWORD"]

    if "BUILD_NUMBER" in os.environ:
        buildNumber = os.environ["BUILD_NUMBER"]

    base = "https://jenkins.dimagi.com/job/commcare-android-instrumentation-tests/{}".format(buildNumber)
    debugApk = base + "/artifact/app-commcare-debug.apk"
    testApk = base + "/artifact/app-commcare-debug-androidTest.apk"

    debugUrl = "https://api-cloud.browserstack.com/app-automate/upload"
    testUrl = "https://api-cloud.browserstack.com/app-automate/espresso/test-suite"

    command = 'curl -u "{}:{}" -X POST "{}" -F'

    debugUploadCmd = appendData(command.format(userName, password, debugUrl), debugApk)
    output = subprocess.Popen(shlex.split(debugUploadCmd), stdout=PIPE, stderr=None, shell=False)
    appToken = json.loads(output.communicate()[0])["app_url"]

    testUploadCmd = appendData(command.format(userName, password, testUrl), testApk)<commit_msg>Use environment variable for absolute location<commit_after>"""
Submits the apks to BrowserStack to run the instrumentation tests.
"""

import os
import shlex
import subprocess
from subprocess import PIPE
import sys
import json

def appendData(command, dataUrl):
    var = "file=@{}".format(dataUrl)
    return command + " " + json.dumps(var)

def buildTestCommand(appToken, testToken):
    test = {}
    test["devices"] = ["LG G5-6.0"] #using just 1 device right now.
    test["app"] = appToken
    test["deviceLogs"] = True
    test["testSuite"] = testToken
    return json.dumps(json.dumps(test))

if __name__ == "__main__":

    if "BROWSERSTACK_USERNAME" in os.environ:
        userName = os.environ["BROWSERSTACK_USERNAME"]

    if "BROWSERSTACK_PASSWORD" in os.environ:
        password = os.environ["BROWSERSTACK_PASSWORD"]

    if "BASE_LOCATION" in os.environ:
        baseLoc = os.environ["BASE_LOCATION"]

    debugApk = baseLoc + "commcare/debug/app-commcare-debug.apk"
    testApk = baseLoc + "androidTest/commcare/debug/app-commcare-debug-androidTest.apk"

    debugUrl = "https://api-cloud.browserstack.com/app-automate/upload"
    testUrl = "https://api-cloud.browserstack.com/app-automate/espresso/test-suite"

    command = 'curl -u "{}:{}" -X POST "{}" -F'

    debugUploadCmd = appendData(command.format(userName, password, debugUrl), debugApk)
    output = subprocess.Popen(shlex.split(debugUploadCmd), stdout=PIPE, stderr=None, shell=False)
    appToken = json.loads(output.communicate()[0])["app_url"]

    testUploadCmd = appendData(command.format(userName, password, testUrl), testApk)
{'fraction_non_alphanumeric': 0.13854134879462923, 'fraction_numerical': 0.003051571559353067, 'mean_word_length': 4.137931034482759, 'pattern_counts': {'":': 3, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 5, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '500452', 'n_tokens_mistral': 1123, 'n_tokens_neox': 1088, 'n_words': 224}