Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@tempdir()
def test_get_modified_notebooks_empty(self, d):
os.chdir(os.path.join(d.path))
hglib.init()
adapter = HgAdapter()
result = adapter.get_modified_notebooks()
self.assertTrue(result == [])
@tempdir()
def test_get_modified_notebooks(self, d):
os.chdir(d.path)
client = hglib.init()
client.open()
d.makedir('first')
d.makedir('first/second')
path = d.write('first/second/1.ipynb', 'initial')
self.assertEqual(d.read('first/second/1.ipynb'), 'initial')
client.add('first/second/1.ipynb')
client.commit("message")
file = open(path, 'w')
file.write("modified")
file.close()
self.assertEqual(d.read('first/second/1.ipynb'), 'modified')
os.chdir(os.path.join(d.path, 'first'))
@tempdir()
def test_get_unmerged_notebooks_empty(self, d):
os.chdir(os.path.join(d.path))
hglib.init()
adapter = HgAdapter()
result = adapter.get_unmerged_notebooks()
self.assertTrue(result == [])
@tempdir()
@data(
(3, False, [
['3', '1', 'Author', 'One', 'Contributing Author', ' ', 'author01@example.com'],
['3', '2', 'Author', 'Two', 'Contributing Author', ' ', 'author02@example.org'],
['3', '3', 'Author', 'Three', 'Corresponding Author', ' ', 'author03@example.com']
]),
(3, True, [
['3', '3', 'Author', 'Three', 'Corresponding Author', ' ', 'author03@example.com']
]),
(13, False, [
['13', '1', 'Author', 'Uno', 'Contributing Author', ' ', 'author13-01@example.com'],
['13', '2', 'Author', 'Dos', 'Contributing Author', ' ', 'author13-02@example.com'],
['13', '3', u'Authoré', u'Trés', 'Contributing Author', '1', 'author13-03@example.com'],
['13', '4', 'Author', 'Cuatro', 'Corresponding Author', ' ', 'author13-04@example.com']
]),
("00003", True, [
@tempdir()
@patch('provider.ejp.EJP.ejp_bucket_file_list')
@data(
('author', 'ejp_query_tool_query_id_152_15a)_Accepted_Paper_Details_2013_10_31_eLife.csv'),
('editor', 'ejp_query_tool_query_id_158_15b)_Accepted_Paper_Details_2013_10_31_eLife.csv'),
('poa_manuscript', 'ejp_query_tool_query_id_176_POA_Manuscript_2014_03_19_eLife.csv'),
('poa_author', 'ejp_query_tool_query_id_177_POA_Author_2014_03_19_eLife.csv'),
('poa_license', 'ejp_query_tool_query_id_178_POA_License_2014_03_19_eLife.csv'),
('poa_subject_area', 'ejp_query_tool_query_id_179_POA_Subject_Area_2014_03_19_eLife.csv'),
('poa_received', 'ejp_query_tool_query_id_180_POA_Received_2014_03_19_eLife.csv'),
('poa_research_organism',
'ejp_query_tool_query_id_182_POA_Research_Organism_2014_03_19_eLife.csv'),
)
@unpack
def test_find_latest_s3_file_name(self, file_type, expected_s3_key_name,
fake_ejp_bucket_file_list):
bucket_list_file = os.path.join("tests", "test_data", "ejp_bucket_list.json")
@tempdir()
@data(
(None, '', 'wb', TypeError, None),
('read_mode_failure.txt', '', 'r', IOError, None),
('good.txt', 'good', 'wb', None, 'good.txt'),
)
@unpack
def test_write_content_to_file(self, filename, content, mode, exception_raised, expected_document):
# if we expect a document, for comparison we need to add the tmp_dir path to it
if expected_document:
expected_document = os.path.join(self.directory.path, expected_document)
try:
document = self.ejp.write_content_to_file(filename, content, mode)
# check the returned value
self.assertEqual(document, expected_document)
except:
# check the exception
@tempdir()
@patch.object(activity_ConvertJATS, 'add_update_date_to_json')
@patch.object(activity_ConvertJATS, 'get_article_xml_key')
@patch('activity.activity_ConvertJATS.Key')
@patch('activity.activity_ConvertJATS.S3Connection')
@patch('activity.activity_ConvertJATS.Session')
def test_do_activity(self, fake_session_mock, fake_s3_mock, fake_key_mock, fake_get_article_xml_key, fake_add_update_date_to_json):
directory = TempDirectory()
#preparing Mocks
fake_session_mock.return_value = FakeSession(data.session_example)
fake_s3_mock.return_value = FakeS3Connection()
fake_key_mock.return_value = FakeKey(directory, data.bucket_dest_file_name)
fake_get_article_xml_key.return_value = FakeKey(directory), data.bucket_origin_file_name
fake_add_update_date_to_json.return_value = data.json_output_return_example_string
self.jats.emit_monitor_event = mock.MagicMock()
self.jats.set_dashboard_properties = mock.MagicMock()
@tempdir()
@patch.object(activity_SendDashboardProperties, 'emit_monitor_event')
@patch('activity.activity_SendDashboardProperties.get_article_xml_key')
@patch('activity.activity_SendDashboardProperties.S3Connection')
@patch('activity.activity_SendDashboardProperties.get_session')
@patch.object(activity_SendDashboardProperties, 'set_monitor_property')
def test_do_activity_failure_invalid_xml(self, fake_emit_monitor_property, fake_session, fake_s3_mock, fake_get_article_xml_key,
fake_emit_monitor_event):
"test if XML fails to parse, here an incorrect pub_date, will fail"
fake_session.return_value = FakeSession(test_data.session_example)
fake_s3_mock.return_value = FakeS3Connection()
with open(os.path.join('tests', 'files_source', 'elife-00353-v1_bad_pub_date.xml'), 'rb') as open_file:
fake_key = FakeKey(self.directory, 'elife-00353-v1.xml', open_file.read())
fake_get_article_xml_key.return_value = fake_key, test_data.bucket_origin_file_name
result = self.send_dashboard_properties.do_activity(test_data.dashboard_data)
@tempdir()
@patch.object(activity_SendDashboardProperties, 'emit_monitor_event')
@patch('activity.activity_SendDashboardProperties.get_article_xml_key')
@patch('activity.activity_SendDashboardProperties.S3Connection')
@patch('activity.activity_SendDashboardProperties.get_session')
@patch.object(activity_SendDashboardProperties, 'set_monitor_property')
def test_do_activity_failure_no_xml(self, fake_emit_monitor_property, fake_session, fake_s3_mock, fake_get_article_xml_key,
fake_emit_monitor_event):
"test if no XML file is supplied, will fail"
fake_session.return_value = FakeSession(test_data.session_example)
fake_s3_mock.return_value = FakeS3Connection()
fake_get_article_xml_key.return_value = None, None
result = self.send_dashboard_properties.do_activity(test_data.dashboard_data)
self.assertEqual(result, self.send_dashboard_properties.ACTIVITY_PERMANENT_FAILURE)
@tempdir()
@patch.object(activity_SendDashboardProperties, 'emit_monitor_event')
@patch('activity.activity_SendDashboardProperties.get_article_xml_key')
@patch('activity.activity_SendDashboardProperties.S3Connection')
@patch('activity.activity_SendDashboardProperties.get_session')
@patch.object(activity_SendDashboardProperties, 'set_monitor_property')
def test_do_activity(self, fake_emit_monitor_property, fake_session, fake_s3_mock, fake_get_article_xml_key,
fake_emit_monitor_event):
fake_session.return_value = FakeSession(test_data.session_example)
fake_s3_mock.return_value = FakeS3Connection()
fake_get_article_xml_key.return_value = FakeKey(self.directory), test_data.bucket_origin_file_name
result = self.send_dashboard_properties.do_activity(test_data.dashboard_data)
self.assertEqual(result, True)