Ejemplo n.º 1
0
 def test_failed_get(self):
     """ Test GET that should fail """
     test = resttest.Test()
     test.url = self.prefix + '/api/person/500/'
     test_response = resttest.run_test(test)
     self.assertEqual(False, test_response.passed)
     self.assertEqual(404, test_response.response_code)
Ejemplo n.º 2
0
 def test_get(self):
     """ Basic local get test """
     test = resttest.Test()
     test.url = self.prefix + '/api/person/'
     test_response = resttest.run_test(test)
     self.assertTrue(test_response.passed)
     self.assertEqual(200, test_response.response_code)
Ejemplo n.º 3
0
    def test_post(self):
        """ Test POST to create an item """
        test = resttest.Test()
        test.url = self.prefix + '/api/person/'
        test.method = u'POST'
        test.expected_status = [200, 201, 204]
        test.body = '{"first_name": "Willim","last_name": "Adama","login": "******"}'
        test.headers = {u'Content-Type': u'application/json'}
        test_response = resttest.run_test(test)
        self.assertEqual(True, test_response.passed)
        self.assertEqual(201, test_response.response_code)

        # Test user was created
        test2 = resttest.Test()
        test2.url = self.prefix + '/api/person/?login=theadmiral'
        test_response2 = resttest.run_test(test2)
        self.assertTrue(test_response2.passed)
        obj = json.loads(str(test_response2.body))
        print json.dumps(obj)
Ejemplo n.º 4
0
 def test_put_inplace(self):
     """ Test PUT where item already exists """
     test = resttest.Test()
     test.url = self.prefix + '/api/person/1/'
     test.method = u'PUT'
     test.body = '{"first_name": "Gaius","id": 1,"last_name": "Baltar","login": "******"}'
     test.headers = {u'Content-Type': u'application/json'}
     test_response = resttest.run_test(test)
     self.assertEqual(True, test_response.passed)
     self.assertEqual(200, test_response.response_code)
Ejemplo n.º 5
0
    def test_put_created(self):
        """ Test PUT where item DOES NOT already exist """
        test = resttest.Test()
        test.url = self.prefix + '/api/person/100/'
        test.method = u'PUT'
        test.expected_status = [200, 201, 204]
        test.body = '{"first_name": "Willim","last_name": "Adama","login":"******", "id": 100}'
        test.headers = {u'Content-Type': u'application/json'}
        test_response = resttest.run_test(test)
        self.assertEqual(True, test_response.passed)
        self.assertEqual(201, test_response.response_code)

        # Test it was actually created
        test2 = resttest.Test()
        test2.url = test.url
        test_response2 = resttest.run_test(test2)
        self.assertTrue(test_response2.passed)
        self.assertTrue(
            u'"last_name": "Adama"' in test_response2.unicode_body())
        self.assertTrue(
            u'"login": "******"' in test_response2.unicode_body())
Ejemplo n.º 6
0
 def test_benchmark_get(self):
     """ Benchmark basic local get test """
     test = resttest.Test()
     test.url = self.prefix + '/api/person/'
     curl = resttest.configure_curl(test)
     benchmark_config = resttest.BenchmarkConfig()
     benchmark_config.add_metric('total_time').add_metric(
         'total_time', 'median')
     benchmark_result = resttest.benchmark(curl, benchmark_config)
     print "Benchmark - median request time: " + str(
         benchmark_result.aggregates[0])
     self.assertTrue(benchmark_config.benchmark_runs,
                     len(benchmark_result.results['total_time']))
Ejemplo n.º 7
0
    def test_delete(self):
        """ Try removing an item """
        test = resttest.Test()
        test.url = self.prefix + '/api/person/1/'
        test.expected_status = [200, 202, 204]
        test.method = u'DELETE'
        test_response = resttest.run_test(test)
        self.assertEqual(True, test_response.passed)
        self.assertEqual(204, test_response.response_code)

        # Verify it's really gone
        test.method = u'GET'
        test.expected_status = [404]
        test_response = resttest.run_test(test)
        self.assertEqual(True, test_response.passed)
        self.assertEqual(404, test_response.response_code)

        # Check it's gone by name
        test2 = resttest.Test()
        test2.url = self.prefix + '/api/person/?first_name__contains=Gaius'
        test_response2 = resttest.run_test(test2)
        self.assertTrue(test_response2.passed)
        self.assertTrue(u'"objects": []' in test_response2.unicode_body())
Ejemplo n.º 8
0
 def test_detailed_get(self):
     test = resttest.Test()
     test.url = self.prefix + '/api/person/1/'
     test_response = resttest.run_test(test)
     self.assertEqual(True, test_response.passed)
     self.assertEqual(200, test_response.response_code)