def test_flowdetail_save(self):
        # Create a generic flowdetail to save
        fd_id = uuidutils.generate_uuid()
        fd_name = 'fd-%s' % (fd_id)
        wf = self.wfs[0]
        fd = flowdetail.FlowDetail(fd_name, wf, fd_id)

        # Save the generic flowdetail to the backend and record its uuid/name
        b_api.flowdetail_save(fd)
        self.fd_names.append(fd_name)
        self.fd_ids.append(fd_id)

        # Check that the saved flowdetail is in the backend
        actual = b_api.flowdetail_get(fd_id)

        self.assertIsNotNone(actual)
        # Check that the saved flowdetail has no taskdetails
        self.assertEquals(len(actual), 0)

        # Add a generic taskdetail to the flowdetail
        td = b_api.taskdetail_get(self.td_ids[0])
        fd.add_task_detail(td)

        # Save the updated flowdetail
        b_api.flowdetail_save(fd)

        # Check that the saved flowdetail is still there
        actual = b_api.flowdetail_get(fd_id)

        self.assertIsNotNone(actual)
        # Check that the addition of a taskdetail was recorded
        self.assertEquals(len(actual), 1)
    def test_flowdetail_add_task_detail(self):
        # Get the first flowdetail
        actual = b_api.flowdetail_get(self.fd_ids[0])

        # Make sure it has no taskdetails
        self.assertEquals(len(actual), 0)

        # Add a taskdetail to the flowdetail
        b_api.flowdetail_add_task_detail(self.fd_ids[0], self.td_ids[0])

        # Get the flowdetail again
        actual = b_api.flowdetail_get(self.fd_ids[0])

        # Check that the flowdetail has one taskdetail
        self.assertEquals(len(actual), 1)
    def test_logbook_save(self):
        # Create a generic logbook to save
        lb_id = uuidutils.generate_uuid()
        lb_name = 'lb-%s' % (lb_id)
        lb = logbook.LogBook(lb_name, lb_id)

        # Save the logbook and record its uuid and name
        b_api.logbook_save(lb)
        self.lb_names.append(lb_name)
        self.lb_ids.append(lb_id)

        # Check that the saved logbook exists in the backend
        actual = b_api.logbook_get(lb_id)

        self.assertIsNotNone(actual)
        # Check that the saved logbook has no flowdetails
        self.assertEquals(len(actual), 0)

        # Add a flowdetail to the logbook
        fd = b_api.flowdetail_get(self.fd_ids[0])
        lb.add_flow_detail(fd)

        # Save the updated logbook
        b_api.logbook_save(lb)

        # Check that the updated logbook is still in the backend
        actual = b_api.logbook_get(lb_id)

        self.assertIsNotNone(actual)
        # Check that the added flowdetail was recorded
        self.assertEquals(len(actual), 1)
    def test_flowdetail_get(self):
        # Get the first flowdetail
        actual = b_api.flowdetail_get(self.fd_ids[0])

        # Check that it is a flowdetail
        self.assertIsInstance(actual, flowdetail.FlowDetail)
        # Check that its name matches what is expected
        self.assertEquals(actual.name, self.fd_names[0])
    def test_flowdetail_remove_taskdetail(self):
        # Add a taskdetail to the first flowdetail
        b_api.flowdetail_add_task_detail(self.fd_ids[0], self.td_ids[0])

        # Get the first flowdetail
        actual = b_api.flowdetail_get(self.fd_ids[0])

        # Check that the first flowdetail has exactly one taskdetail
        self.assertEquals(len(actual), 1)

        # Remove the taskdetail from the first flowdetail
        b_api.flowdetail_remove_taskdetail(self.fd_ids[0], self.td_ids[0])

        # Get the first flowdetail
        actual = b_api.flowdetail_get(self.fd_ids[0])

        # Check that the first flowdetail no longer has any taskdetails
        self.assertEquals(len(actual), 0)
    def test_flowdetail_delete(self):
        # Get the flowdetail to delete
        id = self.fd_ids.pop()
        fd = b_api.flowdetail_get(id)
        # Delete the flowdetail
        b_api.flowdetail_delete(fd)
        self.fd_names.pop()

        # Make sure it is not there anymore
        self.assertRaises(exception.NotFound, b_api.flowdetail_get,
                          id)
    def test_flowdetail_create(self):
        # Create a flowdetail and record its uuid and name
        fd_id = uuidutils.generate_uuid()
        fd_name = 'fd-%s' % (fd_id)

        b_api.flowdetail_create(fd_name, self.wfs[0], fd_id)
        self.fd_names.append(fd_name)
        self.fd_ids.append(fd_id)

        # Check to see that the created flowdetail is there
        actual = b_api.flowdetail_get(fd_id)

        self.assertIsNotNone(actual)