Esempio n. 1
0
    def test_create(self):
        """Creates a new PrepTemplate"""
        pt = PrepTemplate.create(self.metadata, self.new_raw_data)
        # The returned object has the correct id
        self.assertEqual(pt.id, 3)

        # The relevant rows to common_prep_info have been added.
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.common_prep_info WHERE raw_data_id=3")
        # raw_data_id, sample_id, center_name, center_project_name,
        # ebi_submission_accession, ebi_study_accession, emp_status_id,
        # data_type_id
        exp = [[3, 'SKB8.640193', 'ANL', 'Test Project', None, None, 1, 2],
               [3, 'SKD8.640184', 'ANL', 'Test Project', None, None, 1, 2],
               [3, 'SKB7.640196', 'ANL', 'Test Project', None, None, 1, 2]]
        self.assertEqual(sorted(obs), sorted(exp))

        # The relevant rows have been added to the raw_data_prep_columns
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.raw_data_prep_columns WHERE raw_data_id=3")
        # raw_data_id, column_name, column_type
        exp = [[3, "str_column", "varchar"]]
        self.assertEqual(obs, exp)

        # The new table exists
        self.assertTrue(exists_table("prep_3", self.conn_handler))

        # The new table hosts the correct values
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.prep_3")
        # sample_id, str_column
        exp = [['SKB8.640193', "Value for sample 1"],
               ['SKD8.640184', "Value for sample 2"],
               ['SKB7.640196', "Value for sample 3"]]
        self.assertEqual(sorted(obs), sorted(exp))
Esempio n. 2
0
    def test_create(self):
        """Creates a new PrepTemplate"""
        pt = PrepTemplate.create(self.metadata, self.new_raw_data)
        # The returned object has the correct id
        self.assertEqual(pt.id, 3)

        # The relevant rows to common_prep_info have been added.
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.common_prep_info WHERE raw_data_id=3")
        # raw_data_id, sample_id, center_name, center_project_name,
        # ebi_submission_accession, ebi_study_accession, emp_status_id,
        # data_type_id
        exp = [[3, 'SKB8.640193', 'ANL', 'Test Project', 1, 2],
               [3, 'SKD8.640184', 'ANL', 'Test Project', 1, 2],
               [3, 'SKB7.640196', 'ANL', 'Test Project', 1, 2]]
        self.assertEqual(sorted(obs), sorted(exp))

        # The relevant rows have been added to the raw_data_prep_columns
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.raw_data_prep_columns WHERE raw_data_id=3")
        # raw_data_id, column_name, column_type
        exp = [[3, 'str_column', 'varchar'],
               [3, 'ebi_submission_accession', 'varchar']]
        self.assertEqual(obs, exp)

        # The new table exists
        self.assertTrue(exists_table("prep_3", self.conn_handler))

        # The new table hosts the correct values
        obs = self.conn_handler.execute_fetchall("SELECT * FROM qiita.prep_3")
        # sample_id, str_column
        exp = [['SKB8.640193', "Value for sample 1", None],
               ['SKD8.640184', "Value for sample 2", None],
               ['SKB7.640196', "Value for sample 3", None]]
        self.assertEqual(sorted(obs), sorted(exp))
Esempio n. 3
0
 def test_exists_table(self):
     """Correctly checks if a table exists"""
     # True cases
     self.assertTrue(exists_table("filepath", self.conn_handler))
     self.assertTrue(exists_table("qiita_user", self.conn_handler))
     self.assertTrue(exists_table("analysis", self.conn_handler))
     self.assertTrue(exists_table("prep_1", self.conn_handler))
     self.assertTrue(exists_table("sample_1", self.conn_handler))
     # False cases
     self.assertFalse(exists_table("sample_2", self.conn_handler))
     self.assertFalse(exists_table("prep_2", self.conn_handler))
     self.assertFalse(exists_table("foo_table", self.conn_handler))
     self.assertFalse(exists_table("bar_table", self.conn_handler))
Esempio n. 4
0
 def test_exists_table(self):
     """Correctly checks if a table exists"""
     # True cases
     self.assertTrue(exists_table("filepath", self.conn_handler))
     self.assertTrue(exists_table("qiita_user", self.conn_handler))
     self.assertTrue(exists_table("analysis", self.conn_handler))
     self.assertTrue(exists_table("prep_1", self.conn_handler))
     self.assertTrue(exists_table("sample_1", self.conn_handler))
     # False cases
     self.assertFalse(exists_table("sample_2", self.conn_handler))
     self.assertFalse(exists_table("prep_2", self.conn_handler))
     self.assertFalse(exists_table("foo_table", self.conn_handler))
     self.assertFalse(exists_table("bar_table", self.conn_handler))
Esempio n. 5
0
    def exists(cls, obj_id):
        r"""Checks if already exists a MetadataTemplate for the provided object

        Parameters
        ----------
        obj_id : int
            The id to test if it exists on the database

        Returns
        -------
        bool
            True if already exists. False otherwise.
        """
        cls._check_subclass()
        return exists_table(cls._table_name(obj_id), SQLConnectionHandler())
Esempio n. 6
0
    def test_create(self):
        """Creates a new SampleTemplate"""
        st = SampleTemplate.create(self.metadata, self.new_study)
        # The returned object has the correct id
        self.assertEqual(st.id, 2)

        # The relevant rows to required_sample_info have been added.
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.required_sample_info WHERE study_id=2")
        # study_id sample_id physical_location has_physical_specimen
        # has_extracted_data sample_type required_sample_info_status_id
        # collection_timestamp host_subject_id description
        exp = [[
            2, "Sample1", "location1", True, True, "type1", 1,
            datetime(2014, 5, 29, 12, 24, 51), "NotIdentified",
            "Test Sample 1", 42.42, 41.41
        ],
               [
                   2, "Sample2", "location1", True, True, "type1", 1,
                   datetime(2014, 5, 29, 12, 24, 51), "NotIdentified",
                   "Test Sample 2", 4.2, 1.1
               ],
               [
                   2, "Sample3", "location1", True, True, "type1", 1,
                   datetime(2014, 5, 29, 12, 24, 51), "NotIdentified",
                   "Test Sample 3", 4.8, 4.41
               ]]
        self.assertEqual(obs, exp)

        # The relevant rows have been added to the study_sample_columns
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.study_sample_columns WHERE study_id=2")
        # study_id, column_name, column_type
        exp = [[2, "str_column", "varchar"]]
        self.assertEqual(obs, exp)

        # The new table exists
        self.assertTrue(exists_table("sample_2", self.conn_handler))

        # The new table hosts the correct values
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.sample_2")
        # sample_id, str_column
        exp = [['Sample1', "Value for sample 1"],
               ['Sample2', "Value for sample 2"],
               ['Sample3', "Value for sample 3"]]
        self.assertEqual(obs, exp)
Esempio n. 7
0
    def test_create(self):
        """Creates a new SampleTemplate"""
        st = SampleTemplate.create(self.metadata, self.new_study)
        # The returned object has the correct id
        self.assertEqual(st.id, 2)

        # The relevant rows to required_sample_info have been added.
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.required_sample_info WHERE study_id=2")
        # study_id sample_id physical_location has_physical_specimen
        # has_extracted_data sample_type required_sample_info_status_id
        # collection_timestamp host_subject_id description
        exp = [[2, "Sample1", "location1", True, True, "type1", 1,
                datetime(2014, 5, 29, 12, 24, 51), "NotIdentified",
                "Test Sample 1"],
               [2, "Sample2", "location1", True, True, "type1", 1,
                datetime(2014, 5, 29, 12, 24, 51), "NotIdentified",
                "Test Sample 2"],
               [2, "Sample3", "location1", True, True, "type1", 1,
                datetime(2014, 5, 29, 12, 24, 51), "NotIdentified",
                "Test Sample 3"]]
        self.assertEqual(obs, exp)

        # The relevant rows have been added to the study_sample_columns
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.study_sample_columns WHERE study_id=2")
        # study_id, column_name, column_type
        exp = [[2, "str_column", "varchar"]]
        self.assertEqual(obs, exp)

        # The new table exists
        self.assertTrue(exists_table("sample_2", self.conn_handler))

        # The new table hosts the correct values
        obs = self.conn_handler.execute_fetchall(
            "SELECT * FROM qiita.sample_2")
        # sample_id, str_column
        exp = [['Sample1', "Value for sample 1"],
               ['Sample2', "Value for sample 2"],
               ['Sample3', "Value for sample 3"]]
        self.assertEqual(obs, exp)