fix bugs in delete_test_by_id

- Was incorrectly using `test_id` in predicate for deleting test.
- Was incorrectly trying to delete test before deleting test_module
  mappings.