Example #1
0
 def test_can_iterate_found_links(self):
     expected = [{
         "name": "link5name1",
         "href": "/link5path1",
     }, {
         "name": "link5name2",
         "href": "/link5path2",
     }]
     h = HALEasy('http://api.test_domain/api_root')
     l = list(h.links(rel='other:link5'))
     self.assertEqual(len(l), 2)
     for i, d in enumerate(expected):
         self.assertDictEqual(d, l[i].as_object())
Example #2
0
 def test_can_iterate_unfound_links(self):
     h = HALEasy('http://api.test_domain/api_root')
     for l in h.links(rel='nonexistentrel'
                      ):  # we can iterate over the empty generator
         raise Exception('We should not reach this part of the loop')
Example #3
0
 def test_unfound_links_make_zero_length_list(self):
     h = HALEasy('http://api.test_domain/api_root')
     self.assertEqual(len(list(h.links(rel='nonexistentrel'))),
                      0)  # we get a generator yielding nothing
Example #4
0
 def test_link_count_includes_embedded_and_explicit_links(self):
     h = HALEasy('http://api.test_domain/api_root')
     expected_count = 5  # 1 self link, 1 direct link, 3 embedded resources
     self.assertEqual(len(list(h.links())), expected_count)
Example #5
0
 def test_embedded_rel_with_multiple_objects(self):
     h = HALEasy('http://api.test_domain/api_root')
     links = list(h.links(rel="sample_hal_rel2"))
     self.assertEqual(len(links), 2)
     h2 = h.link(rel="sample_hal_rel2").follow()
     self.assertEqual(h2['e'], 'f')
Example #6
0
 def test_embedded_objects_with_same_rel_exist(self):
     h = HALEasy('http://api.test_domain/api_root')
     self.assertEqual(len(list(h.links(rel='sample_hal_rel2'))), 2)