-
Notifications
You must be signed in to change notification settings - Fork 27
Update subject priority for sequential selection #339
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,10 @@ | ||
| import io | ||
| import mimetypes | ||
|
yuenmichelle1 marked this conversation as resolved.
|
||
| import unittest | ||
| from unittest.mock import patch, mock_open | ||
| from unittest.mock import patch, mock_open, MagicMock | ||
|
|
||
| from panoptes_client.panoptes import ObjectNotSavedException | ||
| from panoptes_client.subject import Subject, UnknownMediaException | ||
| import mimetypes | ||
|
|
||
|
|
||
| class TestSubject(unittest.TestCase): | ||
|
|
@@ -39,7 +40,7 @@ def test_add_location_magic_detection(self, mock_magic): | |
| self.assertIn("locations", self.subject.modified_attributes) | ||
| mock_magic.from_buffer.assert_called_with(data, mime=True) | ||
|
|
||
| @patch.object(mimetypes, 'guess_type', return_value=("image/jpeg", None)) | ||
| @patch("panoptes_client.subject.mimetypes.guess_type", return_value=("image/jpeg", None)) | ||
| def test_add_location_mimetypes_detection(self, mock_guess_type): | ||
| import panoptes_client.subject as subject_module | ||
| subject_module.MEDIA_TYPE_DETECTION = 'mimetypes' | ||
|
|
@@ -56,4 +57,75 @@ def test_add_location_invalid_manual_mimetype(self): | |
| data = b"fake data" | ||
| fake_file = io.BytesIO(data) | ||
| with self.assertRaises(UnknownMediaException): | ||
| self.subject.add_location(fake_file, manual_mimetype="application/javascript") | ||
| self.subject.add_location(fake_file, manual_mimetype="application/javascript") | ||
|
|
||
| def test_update_priority_requires_saved_subject(self): | ||
| with self.assertRaises(ObjectNotSavedException): | ||
| self.subject.update_priority(1) | ||
|
|
||
| def test_update_priority_updates_priority_for_saved_subject(self): | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. trailing whitespace |
||
| self.subject.id = 123 | ||
| set_member_subject_mock = MagicMock() | ||
|
|
||
| with patch.object(self.subject, "save") as mock_save: | ||
| with patch( | ||
| "panoptes_client.subject.SetMemberSubject.where", | ||
| return_value=iter([set_member_subject_mock]), | ||
| ) as mock_where: | ||
| self.subject.update_priority( | ||
| 5, | ||
| subject_set_id=456, | ||
| ) | ||
|
|
||
| self.assertEqual(self.subject.metadata["priority"], 5) | ||
|
|
||
| mock_save.assert_called_once_with() | ||
| mock_where.assert_called_once_with( | ||
| subject_set_id=456, | ||
| subject_id=123, | ||
| ) | ||
|
|
||
| self.assertEqual(set_member_subject_mock.priority, 5) | ||
| set_member_subject_mock.save.assert_called_once_with() | ||
|
|
||
| def test_update_priority_updates_all_subject_sets(self): | ||
| self.subject.id = 123 | ||
|
|
||
| subject_set_1 = MagicMock(id=456) | ||
| subject_set_2 = MagicMock(id=789) | ||
| set_member_subject_1 = MagicMock() | ||
| set_member_subject_2 = MagicMock() | ||
|
|
||
| with patch.object(self.subject, "save") as mock_save, \ | ||
| patch( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. continuation line over-indented for hanging indent |
||
| "panoptes_client.panoptes.LinkResolver.__getattr__", | ||
| return_value=[subject_set_1, subject_set_2], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. continuation line under-indented for hanging indent |
||
| ), \ | ||
| patch( | ||
| "panoptes_client.subject.SetMemberSubject.where", | ||
| side_effect=[ | ||
| iter([set_member_subject_1]), | ||
| iter([set_member_subject_2]), | ||
| ], | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. closing bracket does not match indentation of opening bracket's line |
||
| ) as mock_where: | ||
| self.subject.update_priority(5) | ||
|
|
||
| self.assertEqual(self.subject.metadata["priority"], 5) | ||
|
|
||
| mock_save.assert_called_once_with() | ||
|
|
||
| self.assertEqual(mock_where.call_count, 2) | ||
| mock_where.assert_any_call( | ||
| subject_set_id=456, | ||
| subject_id=123, | ||
| ) | ||
| mock_where.assert_any_call( | ||
| subject_set_id=789, | ||
| subject_id=123, | ||
| ) | ||
|
|
||
| self.assertEqual(set_member_subject_1.priority, 5) | ||
| set_member_subject_1.save.assert_called_once_with() | ||
|
|
||
| self.assertEqual(set_member_subject_2.priority, 5) | ||
| set_member_subject_2.save.assert_called_once_with() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blank line contains whitespace