<commit_before>#!/usr/bin/env python
# Test REST interface by spawning server and sending a bunch of commands.

import sys
import os
import time
import subprocess
import unittest
import json
import pdb

import urllib2
import urllib

server_exe = sys.argv[1]
opencog_conf = sys.argv[2]
del sys.argv[1:3]
server_process=None

base_url = 'http://localhost:17034/'
rest_url = base_url + 'rest/0.2/'

def spawn_server():
    global server_process
    print "Spawning server"
    server_process = subprocess.Popen([server_exe, '-c',
            '../../../lib/opencog.conf'], stdout=sys.stdout)
#stderr=subprocess.PIPE, stdout=subprocess.PIPE) #, '-DLOG_TO_STDOUT=TRUE'])
    time.sleep(1) # Allow modules time to load
    print "Server spawned with pid %d" % (server_process.pid,)

def kill_server():
    print "Killing server"
    server_process.terminate()
    #req = urllib2.Request(base_url + '/opencog/request/shutdown')
    #response = urllib2.urlopen(req).read()
    #stdout,stderr = server_process.communicate()
    print "Server killed"

class TestPostAtom(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass
        
    def testPostSuccess(self):
        """ Just test a very basic add """
        data = '{ "type":"ConceptNode", "name":"testPostSuccess1", "truthvalue": {"simple": {"str":0.5, "count":10}}}'
        req = urllib2.Request(rest_url + 'atom/',data)
        response = urllib2.urlopen(req).read()
        result = json.loads(response)
        self.assertTrue("result" in result)
        self.assertEqual(result["result"], "created")<commit_msg>fix finding config file for rest test<commit_after>#!/usr/bin/env python
# Test REST interface by spawning server and sending a bunch of commands.

import sys
import os
import time
import subprocess
import unittest
import json
import pdb

import urllib2
import urllib

server_exe = sys.argv[1]
opencog_conf = sys.argv[2]
del sys.argv[1:3]
server_process=None

base_url = 'http://localhost:17034/'
rest_url = base_url + 'rest/0.2/'

def spawn_server():
    global server_process
    print "Spawning server"
    server_process = subprocess.Popen([server_exe, '-c',
            opencog_conf], stdout=sys.stdout)
            #'../../../lib/opencog.conf'], stdout=sys.stdout)
#stderr=subprocess.PIPE, stdout=subprocess.PIPE) #, '-DLOG_TO_STDOUT=TRUE'])
    time.sleep(1) # Allow modules time to load
    print "Server spawned with pid %d" % (server_process.pid,)

def kill_server():
    print "Killing server"
    server_process.terminate()
    #req = urllib2.Request(base_url + '/opencog/request/shutdown')
    #response = urllib2.urlopen(req).read()
    #stdout,stderr = server_process.communicate()
    print "Server killed"

class TestPostAtom(unittest.TestCase):

    def setUp(self):
        pass

    def tearDown(self):
        pass
        
    def testPostSuccess(self):
        """ Just test a very basic add """
        data = '{ "type":"ConceptNode", "name":"testPostSuccess1", "truthvalue": {"simple": {"str":0.5, "count":10}}}'
        req = urllib2.Request(rest_url + 'atom/',data)
        response = urllib2.urlopen(req).read()
        result = json.loads(response)
        self.assertTrue("result" in result)
        self.assertEqual(result["result"], "created")
{'fraction_non_alphanumeric': 0.13662702043305885, 'fraction_numerical': 0.013418725221103996, 'mean_word_length': 3.5303867403314917, 'pattern_counts': {'":': 12, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '7450396', 'n_tokens_mistral': 1092, 'n_tokens_neox': 1067, 'n_words': 253}