Fixed SQL query to avoid duplicate images or spectra
Updated tests for new API and add new tests
Removed unused imports
PEP8 cleanup