ooici/coi-services — pull request #400 by ifreecarve (2012-12-11 06:34:41+00:00)
Title: stress test and specific test for find_related_resources... WORKING

This commit includes a test that verifies the functionality of a "find related resources" function (and several tweaks to make it run properly in cases where there are several hundred resources).

Finding related resources is done using a simple crawler function, i.e. ```function(input_resource_id, recursion_limit=1024)```. This crawler function must be generated; each resource type will have different resources that are considered "related", and these criteria are plugged into the generator function (along with the resource registry client).

```python
r = RelatedResourcesCrawler()

# test a nontrivial lookup, in which we extract resources related to an instrument device
rw = []
pd = {}

# we want things related to an instrument device
rw.append(RT.PlatformModel)
rw.append(RT.InstrumentModel)
rw.append(RT.PlatformDevice)
rw.append(RT.InstrumentSite)
rw.append(RT.PlatformSite)
rw.append(RT.Subsite)
rw.append(RT.Observatory)
rw.append(RT.InstrumentDevice)
pd[PRED.hasModel] = (True, True)
pd[PRED.hasDevice] = (False, True)
pd[PRED.hasSite] = (False, True)

crawler_fn = r.generate_get_related_resources_fn(self.RR, resource_whitelist=rw, predicate_dictionary=pd)
related = crawler_fn(some_instrument_id)

```

```rw``` and ```pd``` represent the input criteria to the generator function -- the resource whitelist and the predicate dictionary, respectively. The resource whitelist indicates which resource types will be crawled. The predicate dictionary is keyed on predicate types, and its values are a tuple of booleans: (crawl subject to object, crawl object to subject). This is necessary to avoid matching ALL resources in a tree (such as observatory-subsite-platformsite-instrumentsite).