Skip to content

Search stopgap #1014

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 1, 2015
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
merge upstream/master
  • Loading branch information
squirrelo committed Mar 27, 2015
commit 5a4af3baafe946b790f2fc16cc3c8b2b63cdd838
37 changes: 37 additions & 0 deletions qiita_db/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -1330,3 +1330,40 @@ def samples(self):
# Get samples from dynamic table
sql = "SELECT sample_id FROM qiita.prep_%d" % prep_id
return set(s[0] for s in conn_handler.execute_fetchall(sql))

@property
def status(self):
conn_handler = SQLConnectionHandler()
sql = """SELECT pds.processed_data_status
FROM qiita.processed_data_status pds
JOIN qiita.processed_data pd
USING (processed_data_status_id)
WHERE pd.processed_data_id=%s"""
return conn_handler.execute_fetchone(sql, (self._id,))[0]

@status.setter
def status(self, status):
"""Set the status value

Parameters
----------
status : str
The new status

Raises
------
QiitaDBStatusError
If the processed data status is public
"""
if self.status == 'public':
raise QiitaDBStatusError(
"Illegal operation on public processed data")

conn_handler = SQLConnectionHandler()

status_id = convert_to_id(status, 'processed_data_status',
conn_handler=conn_handler)

sql = """UPDATE qiita.{0} SET processed_data_status_id = %s
WHERE processed_data_id=%s""".format(self._table)
conn_handler.execute(sql, (status_id, self._id))
59 changes: 59 additions & 0 deletions qiita_db/test/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,5 +945,64 @@ def test_samples(self):
'1.SKM5.640177', '1.SKM7.640188', '1.SKD7.640191'}
self.assertEqual(obs, exp)

def test_status(self):
pd = ProcessedData(1)
self.assertEqual(pd.status, 'private')

pd = ProcessedData.create(self.params_table, self.params_id,
self.filepaths,
preprocessed_data=self.preprocessed_data)
self.assertEqual(pd.status, 'sandbox')

def test_status_setter(self):
pd = ProcessedData(1)
self.assertEqual(pd.status, 'private')

pd.status = 'sandbox'
self.assertEqual(pd.status, 'sandbox')

def test_status_setter_error(self):
pd = ProcessedData(1)
pd.status = 'public'
self.assertEqual(pd.status, 'public')

with self.assertRaises(QiitaDBStatusError):
pd.status = 'sandbox'

def test_status_setter_error_not_existant(self):
pd = ProcessedData(1)
with self.assertRaises(IncompetentQiitaDeveloperError):
pd.status = 'does-not-exist'

def test_get_by_status(self):
pds = ProcessedData.get_by_status('sandbox')
self.assertEqual(pds, set())

pds = ProcessedData.get_by_status('private')
self.assertEqual(pds, set([1]))

ProcessedData.create(self.params_table, self.params_id,
self.filepaths,
preprocessed_data=self.preprocessed_data)
pds = ProcessedData.get_by_status('sandbox')
self.assertEqual(pds, set([2]))

pds = ProcessedData.get_by_status('private')
self.assertEqual(pds, set([1]))

def test_get_by_status_grouped_by_study(self):
obs = ProcessedData.get_by_status_grouped_by_study('sandbox')
self.assertEqual(obs, dict())

obs = ProcessedData.get_by_status_grouped_by_study('private')
self.assertEqual(obs, {1: [1]})

ProcessedData.create(self.params_table, self.params_id,
self.filepaths,
preprocessed_data=self.preprocessed_data)
obs = ProcessedData.get_by_status_grouped_by_study('sandbox')
self.assertEqual(obs, {1: [2]})


if __name__ == '__main__':
main()
You are viewing a condensed version of this merge commit. You can view the full changes here.