Exemple #1
0
class TestNodeConnector(unittest.TestCase):
    def setUp(self):
       self.client=Resource('http://127.0.0.1:8000')
       self.client.post('/environments',headers={'Content-Type': 'application/json'},payload='{"name":"test"}')
       self.client.post('/environments/0/nodes',headers={'Content-Type': 'application/json'},payload='{"name":"testNode","type":"reprap"}')
    
    def test_ConnectorCreate(self):          
        self.client.put('/environments/0/nodes/0/connector',headers={'Content-Type': 'application/json'},payload='{"driverType":"teacup","driverParams":{"speed":115200}}')
        self.failUnlessEqual(200, self.client.status)
         
    def test_ConnectorRead(self):
        self.client.get('/environments/0/nodes/0/connector',headers={'Content-Type': 'application/json'})
        self.failUnlessEqual(200, self.client.status)
        
    def test_ConnectorUpdate(self):
        self.client.put('/environments/0/nodes/0/connector',headers={'Content-Type': 'application/json'},payload='{"driverType":"teacup","driverParams":{"speed":115200}}')
        self.failUnlessEqual(200, self.client.status)
        
    def test_ConnectorDelete(self):
        self.client.delete('/environments/0/nodes/0/connector',headers={'Content-Type': 'application/json'})
        self.failUnlessEqual(200, self.client.status)
        
    def test_ConnectorStatusUpdate(self):
        self.client.put('/environments/0/nodes/0/connector',headers={'Content-Type': 'application/json'},payload='{"driverType":"teacup","driverParams":{"speed":115200}}')
        self.failUnlessEqual(200, self.client.status)
        
        self.client.post('/environments/0/nodes/0/connector/status',headers={'Content-Type': 'application/json'},payload='{"connected":"True"}')
        self.failUnlessEqual(200, self.client.status)
        
    def tearDown(self):
        self.client.delete('/environments',headers={'Content-Type': 'application/json'})
Exemple #2
0
class TestNodeTasks(unittest.TestCase):
    def setUp(self):
       self.client=Resource('http://127.0.0.1:8000')
       self.client.post('/environments',headers={'Content-Type': 'application/json'},payload='{"name":"test"}')
       self.client.post('/environments/0/nodes',headers={'Content-Type': 'application/json'},payload='{"name":"testNode","type":"reprap"}')
    
    def test_TaskCreate(self):          
        response=self.client.post('/environments/0/nodes/0/tasks',headers={'Content-Type': 'application/json'},payload='{"name":"testTask","type":"print"}')
        self.failUnlessEqual(200, self.client.status)
         
    def test_TaskRead(self):
        self.client.get('/environments/0/nodes/0/connector',headers={'Content-Type': 'application/json'})
        self.failUnlessEqual(200, self.client.status)
        
    def test_ConnectorUpdate(self):
        self.client.put('/environments/0/nodes/0/connector',headers={'Content-Type': 'application/json'},payload='{"driverType":"teacup","driverParams":{"speed":115200}}')
        self.failUnlessEqual(200, self.client.status)
        
    def test_ConnectorDelete(self):
        self.client.delete('/environments/0/nodes/0/connector',headers={'Content-Type': 'application/json'})
        self.failUnlessEqual(200, self.client.status)
        
    def test_ConnectorStatusUpdate(self):
        self.client.put('/environments/0/nodes/0/connector',headers={'Content-Type': 'application/json'},payload='{"driverType":"teacup","driverParams":{"speed":115200}}')
        self.failUnlessEqual(200, self.client.status)
        
        self.client.post('/environments/0/nodes/0/connector/status',headers={'Content-Type': 'application/json'},payload='{"connected":"True"}')
        self.failUnlessEqual(200, self.client.status)
        
    def tearDown(self):
        self.client.delete('/environments',headers={'Content-Type': 'application/json'})
Exemple #3
0
class TestEnvironments(unittest.TestCase):
    def setUp(self):
       self.client=Resource('http://127.0.0.1:8000')
    
    def test_EnvironmentCreate(self):
        response=self.client.put('/environments',headers={'Content-Type': 'application/json'},payload='{"name":"test"}')
        self.failUnlessEqual(200, self.client.status)
        
    def test_EnvironmenstRead(self):
        self.client.get('/environments',headers={'Content-Type': 'application/json'})
        self.failUnlessEqual(200, self.client.status)
        try:
            self.client.get('/environments',headers={'Content-Type': 'application/xml'})
        except:
            pass
        self.failUnlessEqual(500, self.client.status)
        
        self.client.put('/environments',headers={'Content-Type': 'application/json'},payload='{"name":"test"}')
        response=self.client.get('/environments',headers={'Content-Type': 'application/json'})
        self.failUnlessEqual('{"Environments":["test"]}',response)
        
    def test_EnvironmentUpdate(self):
        pass
    def test_EnvironmentsDelete(self):
        self.client.delete('/environments',headers={'Content-Type': 'application/json'})
        self.failUnlessEqual(200, self.client.status)
        
    def tearDown(self):
        self.client.delete('/environments',headers={'Content-Type': 'application/json'})
class TestEnvironments(unittest.TestCase):
    def setUp(self):
        self.client = Resource("http://127.0.0.1:8000")

    def test_EnvironmentCreate(self):
        response = self.client.put(
            "/environments", headers={"Content-Type": "application/json"}, payload='{"name":"test"}'
        )
        self.failUnlessEqual(200, self.client.status)

    def test_EnvironmenstRead(self):
        self.client.get("/environments", headers={"Content-Type": "application/json"})
        self.failUnlessEqual(200, self.client.status)
        try:
            self.client.get("/environments", headers={"Content-Type": "application/xml"})
        except:
            pass
        self.failUnlessEqual(500, self.client.status)

        self.client.put("/environments", headers={"Content-Type": "application/json"}, payload='{"name":"test"}')
        response = self.client.get("/environments", headers={"Content-Type": "application/json"})
        self.failUnlessEqual('{"Environments":["test"]}', response)

    def test_EnvironmentUpdate(self):
        pass

    def test_EnvironmentsDelete(self):
        self.client.delete("/environments", headers={"Content-Type": "application/json"})
        self.failUnlessEqual(200, self.client.status)

    def tearDown(self):
        self.client.delete("/environments", headers={"Content-Type": "application/json"})
Exemple #5
0
class TestNodes(unittest.TestCase):
    def setUp(self):
       self.client=Resource('http://127.0.0.1:8000')
       response=self.client.put('/environments',headers={'Content-Type': 'application/json'},payload='{"name":"test"}')
       self.failUnlessEqual(200, self.client.status)
    
    def test_NodeCreate(self):    
        response=self.client.post('/environments/0/nodes',headers={'Content-Type': 'application/json'},payload='{"name":"testNode","type":"reprap"}')
        self.failUnlessEqual(200, self.client.status)
        
    def test_NodesRead(self):
        self.client.get('/environments/0/nodes',headers={'Content-Type': 'application/json'})
        self.failUnlessEqual(200, self.client.status)
        
    def test_NodeUpdate(self):
        pass
    def test_NodesDelete(self):
        self.client.delete('/environments/0/nodes',headers={'Content-Type': 'application/json'})
        self.failUnlessEqual(200, self.client.status)
            
    def tearDown(self):
        self.client.delete('/environments',headers={'Content-Type': 'application/json'})
Exemple #6
0
class DeleteTokens(unittest.TestCase):
    def setUp(self):
        self.res = Resource("http://"+utils.sso_server)
        # set logging level
        # Need to be moved to somewhere else for global configuration
        debug = logging.DEBUG
        logging.basicConfig(level = debug, stream = sys.stderr, format = '%(levelname)s %(asctime)s [%(message)s]')
        logging.info("")
        self.token = utils.retrieve_token()

    def test_positive_delete_tokens_check_keys(self):
        """
        Check the response contains correct keys.
        """
        r = self.res.delete('/tokens/'+self.token['access_token'], headers=utils.headers)
        logging.info("Return response is '%s'" % r)
        # convert string to dictionary
        rd = ast.literal_eval(r)
        logging.info("Return response in dictionary format is '%s'" % rd)
        self.assertEqual(self.res.response.status, 200)
        keys = ['revoked_token_num']
        self.assertTrue(utils.is_same_array(keys, rd.keys()), "Keys are not correct!")

    def test_positive_delete_tokens_exist(self):
        """
        Delete tokens exist and check the 'revoked_token_num' is '1'
        """
        token = utils.retrieve_token(another=True)
        r = self.res.delete('/tokens/'+token['access_token'], headers=utils.headers)
        logging.info("Return response is '%s'" % r)
        self.assertEqual(self.res.response.status, 200)
        # convert string to dictionary
        rd = ast.literal_eval(r)
        logging.info("Return response in dictionary format is '%s'" % rd)
        # assert 'revoked_token_num' is 1
        self.assertEqual(rd['revoked_token_num'], 1, "The 'revoked_token_num' is not equal to 1")

    def test_negative_delete_tokens_not_exist(self):
        """
        Delete tokens not exist and check the 'revoked_token_num' is '0'
        """
        r = self.res.delete('/tokens/'+utils.random_str(), headers=utils.headers)
        logging.info("Return response is '%s'" % r)
        self.assertEqual(self.res.response.status, 200)
        # convert string to dictionary
        rd = ast.literal_eval(r)
        logging.info("Return response in dictionary format is '%s'" % rd)
        # assert 'revoked_token_num' is 1
        self.assertEqual(rd['revoked_token_num'], 0, "The 'revoked_token_num' is not equal to 0")

    def test_negative_delete_tokens_parameter_missing(self):
        """
        Check exception raised while deleting tokens without giving parameter, and verify the exception contains correct error messages.
        """
        malpayloads = ['']
        for mp in malpayloads:
            logging.info("The malpayload acting unauthorized client is '%s'" % mp)
            with self.assertRaises(rest.RequestFailed) as e:
                self.res.delete('/tokens/'+mp, headers=utils.headers)
            self.assertEqual(self.res.response.status, 400)
            # verify the retrieved exception is expected
            utils.verify_rest_requetfailed_exception(e, utils.get_exception('ParameterMissing', 'DeleteTokensExceptions'), self)
            
    def test_positive_delete_tokens_condition_exist(self):
        """
        Delete tokens with existing user_id and check the 'revoked_token_num' is >= '1'
        """
        token = utils.retrieve_token(another=True)
        r = self.res.get('/tokens/'+token['access_token'], headers=utils.headers)
        token = ast.literal_eval(r)
        r = self.res.delete('/tokens/?user_id='+str(token['user_id']), headers=utils.headers)
        logging.info("Return response is '%s'" % r)
        self.assertEqual(self.res.response.status, 200)
        # convert string to dictionary
        rd = ast.literal_eval(r)
        logging.info("Return response in dictionary format is '%s'" % rd)
        # assert 'revoked_token_num' is >= 1
        self.assertTrue((rd['revoked_token_num'] >= 1), "The 'revoked_token_num' is not >= 1")
        
    def test_negative_delete_tokens_condition_user_not_exist(self):
        """
        Delete tokens with not existing user_id and check the 'revoked_token_num' '0'
        """
        malpayloads = [str(random.randint(0,99)), utils.random_str()]
        for mp in malpayloads:
            logging.info("The malpayload acting not existent user_id is '%s'" % mp)
            r = self.res.delete('/tokens/?user_id='+mp, headers=utils.headers)
            self.assertEqual(self.res.response.status, 200)
            # convert string to dictionary
            rd = ast.literal_eval(r)
            logging.info("Return response in dictionary format is '%s'" % rd)
            # assert 'revoked_token_num' is 0
            self.assertEqual(rd['revoked_token_num'], 0, "The 'revoked_token_num' is not 0")
    
    def test_negative_delete_tokens_condition_parameter_missing(self):
        """
        Check exception raised while deleting tokens without giving client_id, and verify the exception contains correct error messages.
        """
        malpayloads = ['', 'client_id=']
        for mp in malpayloads:
            logging.info("The malpayload acting unauthorized client is '%s'" % mp)
            with self.assertRaises(rest.RequestFailed) as e:
                self.res.delete('/tokens/?'+mp, headers=utils.headers)
            self.assertEqual(self.res.response.status, 400)
            # verify the retrieved exception is expected
            utils.verify_rest_requetfailed_exception(e, utils.get_exception('ParameterMissing', 'DeleteTokensExceptions'), self)
            
    def test_negative_delete_tokens_condition_invalid_user(self):
        """
        Check exception raised while deleting tokens with invalid user_id, and verify the exception contains correct error messages.
        """
        malpayloads = ['', ' ']
        for mp in malpayloads:
            logging.info("The malpayload acting invalid user_id is '%s'" % mp)
            with self.assertRaises(rest.RequestFailed) as e:
                url = '/tokens/?user_id='+mp
                logging.debug("The requested url is '%s'" % url)
                self.res.delete(url, headers=utils.headers)
            # verify the retrieved exception is expected
            self.assertEqual(self.res.response.status, 400)
Exemple #7
0
from restclient import Resource
import random
import json

s = 'http://localhost:8089/'
u0 = str(random.randint(0, 10000))
u1 = str(random.randint(0, 10000))
print(u0, u1)
res = Resource(s)
print res.post('api/%s/' % u0)
print res.post('api/%s/msg' % u0, payload='Immmmm')
msg2_id = json.loads(res.post('api/%s/msg' % u0, payload='sailing'))['msg_id']
print res.post('api/%s/msg' % u0, payload='away')
print res.get('api/%s/' % u0)
print res.delete('api/%s/msg/%s/' % (u0, msg2_id))
print res.post('api/%s/' % u1)
r = res.get()
print(r)
print res.delete('api/%s/' % u0)
r = res.get()
print(r)
Exemple #8
0
from restclient import Resource
import random
import json

s = 'http://localhost:8089/'
u0 = str(random.randint(0, 10000))
u1 = str(random.randint(0, 10000))
print (u0, u1)
res = Resource(s)
print res.post('api/%s/' % u0)
print res.post('api/%s/msg' % u0, payload='Immmmm')
msg2_id = json.loads(res.post('api/%s/msg' % u0, payload='sailing'))['msg_id']
print res.post('api/%s/msg' % u0, payload='away')
print res.get('api/%s/' % u0)
print res.delete('api/%s/msg/%s/' % (u0, msg2_id))
print res.post('api/%s/' % u1)
r = res.get()
print(r)
print res.delete('api/%s/' % u0)
r = res.get()
print(r)