Various changes to support further high-level automation efforts.

* added a RESTful interface for TKO.  right now there's only a single, simple resource for accessing test attributes.
* extended the REST server library in a few ways, most notably to support
* querying on keyvals, with something like ?has_keyval=mykey=myvalue&...
* operators, delimited by a colon, like ?hostname:in=host1,host2,host3
* loading relationships over many items efficiently (see InstanceEntry.prepare_for_full_representation()).  this is used to fill in keyvals when requesting a job listing, but it can (and should) be used in other places, such as listing labels for a host collection.
* loading a collection with inlined full representations, by passing full_representations=true
* added various features to the AFE RESTful interface as necessary.
* various fixes to the rest_client library, most notably
* changed HTTP client in rest_client.py to use DI rather than singleton, easing testability.  the same should be done for _get_request_headers(), to be honest.
* better support for query params, including accepting a MultiValueDict and supporting URIs that already have query args
* basic support for redirects
* builtin support for requesting a full collection (get_full()), when clients explicitly expect the result not to be paged.  i'm still considering alternative approaches to this -- it may make sense to have something like this be the default, and have clients set a default page size limit rather than passing it every time.
* minor change to mock.py to provide better debugging output.

Signed-off-by: Steve Howard <showard@google.com>



git-svn-id: http://test.kernel.org/svn/autotest/trunk@4438 592f7852-d20e-0410-864c-8624ca9c26a4
diff --git a/frontend/tko/resources_test.py b/frontend/tko/resources_test.py
new file mode 100644
index 0000000..0f8deae
--- /dev/null
+++ b/frontend/tko/resources_test.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+
+import common
+import unittest
+from autotest_lib.frontend import setup_django_environment
+from autotest_lib.frontend import setup_test_environment
+from autotest_lib.client.common_lib.test_utils import mock
+from autotest_lib.frontend.shared import resource_test_utils
+from autotest_lib.frontend.tko import models, rpc_interface_unittest
+
+
+class TkoResourceTestCase(resource_test_utils.ResourceTestCase,
+                          rpc_interface_unittest.TkoTestMixin):
+    URI_PREFIX = 'http://testserver/new_tko/server/resources'
+
+    def setUp(self):
+        super(TkoResourceTestCase, self).setUp()
+        self.god = mock.mock_god()
+        self._patch_sqlite_stuff()
+        self._create_initial_data()
+
+
+    def tearDown(self):
+        super(TkoResourceTestCase, self).tearDown()
+        self.god.unstub_all()
+
+
+class TestResultTest(TkoResourceTestCase):
+    def test_collection(self):
+        response = self.request('get', 'test_results')
+        self.check_collection(response, 'test_name',
+                              ['kernbench', 'mytest1', 'mytest2'])
+
+
+    def test_filter_afe_job_id(self):
+        response = self.request('get', 'test_results?afe_job_id=1')
+        self.check_collection(response, 'test_name', ['mytest1', 'mytest2'])
+
+
+    def test_entry(self):
+        response = self.request('get', 'test_results/1')
+        self.assertEquals(response['test_name'], 'mytest1')
+        self.assertEquals(response['status'], 'GOOD')
+        self.assertEquals(response['reason'], '')
+
+
+if __name__ == '__main__':
+    unittest.main()