class DataopsEmptyKeyAfterMerge(DataopsMergeBasic): wf_name = 'Test Empty Key after Merge' fixtures = ['test_empty_key_after_merge'] filename = os.path.join( settings.BASE_DIR(), 'dataops', 'fixtures', 'test_empty_key_after_merge.sql' ) merge_file = os.path.join( settings.BASE_DIR(), 'dataops', 'fixtures', 'test_empty_key_after_merge.csv' ) def test_merge(self): self.template_merge('outer', rename=False) # Assert the presence of the error in the page self.assertIn('Merge operation failed.', self.selenium.page_source) # Assert additional properties wflow = Workflow.objects.get(name=self.wf_name) self.assertTrue(wflow.columns.get(name='key1').is_key, 'Column key1 has lost is key property') self.assertTrue(wflow.columns.get(name='key2').is_key, 'Column key2 has lost is key property') self.logout()
class ActionServe(tests.OnTaskTestCase): """Test the view to serve an action.""" fixtures = ['simple_action'] filename = os.path.join( settings.BASE_DIR(), 'ontask', 'fixtures', 'simple_action.sql', ) user_email = '*****@*****.**' user_pwd = 'boguspwd' workflow_name = 'wflow1' def test_serve_action(self): """Test the serve_action view.""" action = self.workflow.actions.get(name='simple action') action.serve_enabled = True action.save() resp = self.get_response('action:serve', {'action_id': action.id}) self.assertTrue(status.is_success(resp.status_code)) self.assertTrue('Oct. 10, 2017, 10:03 p.m.' in str(resp.content))
class ActionServeSurvey(tests.OnTaskTestCase): """Test the view to serve a survey.""" fixtures = ['simple_workflow_two_actions'] filename = os.path.join( settings.BASE_DIR(), 'ontask', 'fixtures', 'simple_workflow_two_actions.sql', ) user_email = '*****@*****.**' user_pwd = 'boguspwd' workflow_name = 'wflow2' def test_serve_survey(self): """Test the serve_action view.""" action = self.workflow.actions.get(name='Check registration') action.serve_enabled = True action.save() resp = self.get_response('action:serve', {'action_id': action.id}) self.assertTrue(status.is_success(resp.status_code)) self.assertTrue('id="action-row-datainput"' in str(resp.content)) self.assertTrue('csrfmiddlewaretoken' in str(resp.content))
class WorkflowDelete(test.OnTaskTestCase): fixtures = ['test_merge'] filename = os.path.join( settings.BASE_DIR(), 'ontask', 'fixtures', 'test_merge.sql' ) user_email = '*****@*****.**' user_pwd = 'boguspwd' def test_delete(self): """Test invokation of delete table""" # Get the workflow first self.workflow = Workflow.objects.all().first() # JSON POST request for workflow delete resp = self.get_response( 'workflow:delete', method='POST', url_params={'wid': self.workflow.id}, is_ajax=True) self.assertTrue(status.is_success(resp.status_code)) self.assertTrue(Workflow.objects.count() == 0) self.workflow = None
def __init__(self, camera_reference=None, **kwargs): file_path = settings.BASE_DIR(camera_reference) self.camera = cv2.VideoCapture(file_path) if not self.camera.isOpened(): message = 'No se puede leer el archivo ' + file_path raise RefusedConnection(message)
class EmailActionTracking(test.OntaskTestCase): fixtures = ['simple_email_action'] filename = os.path.join(settings.BASE_DIR(), 'action', 'fixtures', 'simple_email_action_df.sql') trck_tokens = [ "eyJhY3Rpb24iOjIsInRvIjoic3R1ZGVudDFAYm9ndXMuY29tIiwiY29sdW1uX2RzdCI6IkVtYWlsUmVhZF8xIiwic2VuZGVyIjoiaWRlc2lnbmVyMUBib2d1cy5jb20iLCJjb2x1bW5fdG8iOiJlbWFpbCJ9:1eBtw5:MwH1axNDQq9HpgcP6jRvp7cAFmI", "eyJhY3Rpb24iOjIsInRvIjoic3R1ZGVudDJAYm9ndXMuY29tIiwiY29sdW1uX2RzdCI6IkVtYWlsUmVhZF8xIiwic2VuZGVyIjoiaWRlc2lnbmVyMUBib2d1cy5jb20iLCJjb2x1bW5fdG8iOiJlbWFpbCJ9:1eBtw5:FFS1EXjdgJjc37ZVOcW22aIegR4", "eyJhY3Rpb24iOjIsInRvIjoic3R1ZGVudDNAYm9ndXMuY29tIiwiY29sdW1uX2RzdCI6IkVtYWlsUmVhZF8xIiwic2VuZGVyIjoiaWRlc2lnbmVyMUBib2d1cy5jb20iLCJjb2x1bW5fdG8iOiJlbWFpbCJ9:1eBtw5:V0KhNWbcY3YPTfJXRagPaeJae4M" ] wflow_name = 'wflow1' wflow_desc = 'description text for workflow 1' wflow_empty = 'The workflow does not have data' @classmethod def setUpClass(cls): super(EmailActionTracking, cls).setUpClass() pandas_db.pg_restore_table(cls.filename) def tearDown(self): pandas_db.delete_all_tables() super(EmailActionTracking, self).tearDown() # Test that tracking hits are properly stored. def test_tracking(self): # Repeat the checks two times to test if they are accumulating for idx in range(1, 3): # Iterate over the tracking items for trck in self.trck_tokens: self.client.get(reverse('trck') + '?v=' + trck)
class ActionServeLongSurvey(tests.OnTaskLiveTestCase): """Test the view to serve a survey.""" fixtures = ['long_survey'] filename = os.path.join( settings.BASE_DIR(), 'ontask', 'fixtures', 'long_survey.sql', ) user_email = '*****@*****.**' user_pwd = 'boguspwd' workflow_name = 'Test survey run pages' action_name = 'survey' def test_serve_long_survey(self): """Test the serve_action view with a long number of entries.""" # Login self.login('*****@*****.**') # GO TO THE WORKFLOW PAGE self.access_workflow_from_home_page(self.workflow_name) # Goto the action page self.go_to_actions() # Open action name self.open_action_run(self.action_name, is_action_in=True) pages = self.selenium.find_elements_by_xpath( '//li[contains(@class, "paginate_button")]') self.assertEqual(len(pages), 4) self.logout()
def test_action_import(self): """Test the import .""" # Get request resp = self.get_response('action:import') self.assertTrue(status.is_success(resp.status_code)) self.assertTrue('File containing a previously' in str(resp.content)) file_obj = open( os.path.join(settings.BASE_DIR(), 'lib', 'surveys', 'spq_survey.gz'), 'rb') # Post request req = self.factory.post( reverse('action:import'), { 'name': 'new action name', 'upload_file': file_obj }, ) req.META['HTTP_ACCEPT_ENCODING'] = 'gzip, deflate' req.FILES['upload_file'].content_type = 'application/x-gzip' req = self.add_middleware(req) resp = action_import(req) self.assertEqual(resp.status_code, status.HTTP_302_FOUND) # Fails if the action is not there self.workflow.actions.get(name='new action name')
class DataopsTransform(tests.OnTaskTestCase): """Test the transformation views.""" fixtures = ['plugin_execution'] filename = os.path.join( settings.BASE_DIR(), 'ontask', 'fixtures', 'plugin_execution.sql', ) user_email = '*****@*****.**' user_pwd = 'boguspwd' workflow_name = 'Plugin test' def test_transform_model(self): """Test the view to filter items.""" # Make sure the plugins are reloaded models.Plugin.objects.all().delete() resp = self.get_response('dataops:transform') self.assertTrue(status.is_success(resp.status_code)) resp = self.get_response('dataops:model') self.assertTrue(status.is_success(resp.status_code))
def test_csv_upload(self): """Test the CSV upload.""" # Get the regular form resp = self.get_response('dataops:csvupload_start') self.assertTrue(status.is_success(resp.status_code)) # POST the data filename = os.path.join( settings.BASE_DIR(), 'ontask', 'fixtures', 'simple.csv', ) with open(filename) as fp: resp = self.get_response('dataops:csvupload_start', method='POST', req_params={ 'data_file': fp, 'skip_lines_at_top': -1, 'skip_lines_at_bottom': 0 }) self.assertNotEqual(resp.status_code, status.HTTP_302_FOUND) resp = self.get_response('dataops:csvupload_start', method='POST', req_params={ 'data_file': fp, 'skip_lines_at_top': 0, 'skip_lines_at_bottom': -1 }) self.assertNotEqual(resp.status_code, status.HTTP_302_FOUND)
class TableTestStatView(test.OnTaskTestCase): """Test stat views.""" fixtures = ['simple_table'] filename = os.path.join( settings.BASE_DIR(), 'ontask', 'fixtures', 'simple_table.sql', ) user_email = '*****@*****.**' user_pwd = 'boguspwd' workflow_name = 'wflow1' def test_stats(self): """Test the use of forms in to schedule actions.""" # Remove is_key from column 'age' col = self.workflow.columns.get(name='age') col.is_key = False col.save() # Get the visualization for the whole table resp = self.get_response('table:stat_table') self.assertTrue(status.is_success(resp.status_code)) # GEt the visualization of the view view = self.workflow.views.get(name='simple view') resp = self.get_response('table:stat_table_view', {'pk': view.id}) self.assertTrue(status.is_success(resp.status_code)) # Get one of the rows r_val = get_table_row_by_index(self.workflow, None, 1) resp = self.get_response('table:stat_table', req_params={ 'key': 'email', 'val': r_val['email'] }) self.assertTrue(status.is_success(resp.status_code)) # Get one of the rows from one of the views resp = self.get_response('table:stat_table_view', {'pk': view.id}, req_params={ 'key': 'email', 'val': r_val['email'] }) self.assertTrue(status.is_success(resp.status_code)) # Get one of the columns col = self.workflow.columns.get(name='age') # Get the column visualization resp = self.get_response('table:stat_column', {'pk': col.id}) self.assertTrue(status.is_success(resp.status_code)) # Get the JSON column visualization for a modal col = self.workflow.columns.get(name='one') resp = self.get_response('table:stat_column_JSON', {'pk': col.id}, is_ajax=True) self.assertTrue(status.is_success(resp.status_code))
class ActionAllKeyColumns(test.OnTaskLiveTestCase): action_name = 'Test1' fixtures = ['all_key_columns'] filename = os.path.join(settings.BASE_DIR(), 'action', 'fixtures', 'all_key_columns.sql') wflow_name = 'all key columns' def setUp(self): super().setUp() test.pg_restore_table(self.filename) def tearDown(self): test.delete_all_tables() super().tearDown() # Test action rename def test_action_insert_column_value(self): # Login self.login('*****@*****.**') # GO TO THE WORKFLOW PAGE self.access_workflow_from_home_page(self.wflow_name) # Click in the page to send email self.open_action_edit(self.action_name) # There should be four elements (all key column) in the drop-down self.assertEqual( len( self.selenium.find_elements_by_xpath( '//div[@id="column-selector"]/div/div/button')), 4) # End of session self.logout()
def test_01_excelupload_sheet(self): # Login self.login('*****@*****.**') # GO TO THE WORKFLOW PAGE self.access_workflow_from_home_page('wflow1') # Go to Excel upload/merge self.go_to_excel_upload_merge_step_1() # Upload the file self.selenium.find_element_by_id("id_data_file").send_keys( os.path.join(settings.BASE_DIR(), 'ontask', 'fixtures', 'excel_upload.xlsx')) self.selenium.find_element_by_id("id_sheet").click() self.selenium.find_element_by_id("id_sheet").clear() self.selenium.find_element_by_id("id_sheet").send_keys("second sheet") self.selenium.find_element_by_name("Submit").click() WebDriverWait(self.selenium, 10).until(EC.element_to_be_clickable( (By.ID, 'checkAll'))) self.selenium.find_element_by_name("Submit").click() self.wait_for_datatable('table-data_previous') # The number of rows must be 19 wflow = models.Workflow.objects.all()[0] self.assertEqual(wflow.nrows, 19) self.assertEqual(wflow.ncols, 14) # End of session self.logout()
class ActionImport(tests.OnTaskTestCase): """Test action import.""" fixtures = ['simple_email_action'] filename = os.path.join( settings.BASE_DIR(), 'ontask', 'fixtures', 'simple_email_action.sql' ) wflow_name = 'wflow1' def test_do_import(self): """Test the do_import_action functionality.""" user = get_user_model().objects.get(email='*****@*****.**') wflow = models.Workflow.objects.get(name=self.wflow_name) with open(os.path.join( settings.BASE_DIR(), 'ontask', 'fixtures', 'survey_to_import.gz' ), 'rb') as file_obj: services.do_import_action(user, workflow=wflow, file_item=file_obj) models.Action.objects.get(name='Initial survey')
class WorkflowTestViewImportExport(test.OnTaskTestCase): """Test column views.""" fixtures = ['initial_workflow'] filename = os.path.join( settings.BASE_DIR(), '..', 'initial_workflow', 'initial_workflow.sql', ) user_email = '*****@*****.**' user_pwd = 'boguspwd' workflow_name = 'BIOL1011' def test_export(self): """Export ask followed by export request.""" resp = self.get_response( 'workflow:export_ask', {'wid': self.workflow.id}) self.assertTrue(status.is_success(resp.status_code)) req_params = { 'select_{0}'.format(idx): True for idx in range(self.workflow.actions.count())} resp = self.get_response( 'workflow:export_ask', {'wid': self.workflow.id}, method='POST', req_params=req_params, is_ajax=True) self.assertTrue(status.is_success(resp.status_code))
def test_01_excelupload(self): # Login self.login('*****@*****.**') # GO TO THE WORKFLOW PAGE self.access_workflow_from_home_page('wflow1', False) # Go to Excel upload/merge self.go_to_excel_upload_merge_step_1() # Upload file self.selenium.find_element_by_id("id_file").send_keys( os.path.join(settings.BASE_DIR(), 'dataops', 'fixtures', 'excel_upload.xlsx')) self.selenium.find_element_by_id("id_sheet").click() self.selenium.find_element_by_id("id_sheet").clear() self.selenium.find_element_by_id("id_sheet").send_keys("results") self.selenium.find_element_by_name("Submit").click() WebDriverWait(self.selenium, 10).until(EC.element_to_be_clickable( (By.ID, 'checkAll'))) WebDriverWait(self.selenium, 10).until_not( EC.visibility_of_element_located((By.ID, 'div-spinner'))) self.selenium.find_element_by_name("Submit").click() self.wait_for_datatable('column-table_previous') # The number of rows must be 29 wflow = Workflow.objects.all()[0] self.assertEqual(wflow.nrows, 29) self.assertEqual(wflow.ncols, 14) # End of session self.logout()
def test_ss_01(self): """ Create a workflow, upload data and merge :return: """ # Login self.login('*****@*****.**') # Open Import page self.selenium.find_element_by_link_text('Import workflow').click() WebDriverWait(self.selenium, 10).until( EC.text_to_be_present_in_element((By.XPATH, "//body/div/h1"), 'Import workflow')) # # Import workflow # self.selenium.find_element_by_id('id_name').send_keys( self.workflow_name) self.selenium.find_element_by_id('id_wf_file').send_keys( os.path.join(settings.BASE_DIR(), 'initial_workflow.gz')) # Picture of the body self.body_ss('workflow_import.png') # Click the import button self.selenium.find_element_by_xpath( "//form/div/button[@type='Submit']").click() self.wait_for_page(title='OnTask :: Workflows') # End of session self.logout()
class TableApiBase(test.OntaskApiTestCase): fixtures = ['simple_table'] filename = os.path.join(settings.BASE_DIR(), 'table', 'fixtures', 'simple_table_df.sql') new_table = { "email": ["*****@*****.**", "*****@*****.**", "*****@*****.**"], "sid": [4, 5, 6], "age": [122.0, 122.1, 132.2], "another": ["bbbb", "aaab", "bbbb"], "name": ["Felipe Lotas", "Aitor Tilla", "Carmelo Coton"], "one": ["aaaa", "bbbb", "aaaa"], "registered": [True, False, True], "when": [ "2017-10-12T00:33:44+11:00", "2017-10-12T00:32:44+11:00", "2017-10-12T00:32:44+11:00" ] } src_df = {"sid": [1, 2, 4], "newcol": ['v1', 'v2', 'v3']} src_df2 = {"sid": [5], "forcenas": ['value']} def setUp(self): super(TableApiBase, self).setUp() # Get the token for authentication and set credentials in client token = Token.objects.get(user__email='*****@*****.**') auth = 'Token ' + token.key self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key) pandas_db.pg_restore_table(self.filename) def tearDown(self): pandas_db.delete_all_tables() super(TableApiBase, self).tearDown()
def test_google_sheet_upload(self): """Test the Google Sheet upload.""" # Get the regular form resp = self.get_response('dataops:googlesheetupload_start') self.assertTrue(status.is_success(resp.status_code)) # POST the data filename = os.path.join( settings.BASE_DIR(), 'ontask', 'fixtures', 'simple.csv', ) resp = self.get_response('dataops:googlesheetupload_start', method='POST', req_params={ 'google_url': 'file://' + filename, 'skip_lines_at_top': -1, 'skip_lines_at_bottom': 0 }) self.assertNotEqual(resp.status_code, status.HTTP_302_FOUND) resp = self.get_response('dataops:googlesheetupload_start', method='POST', req_params={ 'google_url': 'file://' + filename, 'skip_lines_at_top': 0, 'skip_lines_at_bottom': -1 }) self.assertNotEqual(resp.status_code, status.HTTP_302_FOUND)
class WorkflowImportExport(test.OnTaskTestCase): fixtures = ['simple_workflow_export'] filename = os.path.join(settings.BASE_DIR(), 'workflow', 'fixtures', 'simple_workflow_export.sql') def test_export(self): # Get the only workflow workflow = Workflow.objects.get(name='wflow1') # Export data only response = do_export_workflow(workflow, workflow.actions.all()) self.assertEqual(response.get('Content-Type'), 'application/octet-stream') self.assertEqual(response['Content-Transfer-Encoding'], 'binary') self.assertTrue( response.get('Content-Disposition').startswith( 'attachment; filename="ontask_workflow')) # Process the file data_in = gzip.GzipFile(fileobj=BytesIO(response.content)) data = JSONParser().parse(data_in) # Compare the data with the current workflow self.assertEqual(workflow.actions.count(), len(data['actions'])) self.assertEqual(workflow.nrows, data['nrows']) self.assertEqual(workflow.ncols, data['ncols']) self.assertEqual(workflow.attributes, data['attributes']) self.assertEqual(workflow.query_builder_ops, data['query_builder_ops'])
def test(self): """ Create a workflow, upload data and merge :return: """ # Login self.login('*****@*****.**') # Open Import page self.selenium.find_element_by_link_text('Import workflow').click() WebDriverWait(self.selenium, 10).until( EC.text_to_be_present_in_element((By.XPATH, "//body/div/h1"), 'Import workflow')) # # Import workflow # self.selenium.find_element_by_id('id_name').send_keys( self.workflow_name) self.selenium.find_element_by_id('id_wf_file').send_keys( os.path.join(settings.BASE_DIR(), 'docs_src', 'Scenarios', 'scenario_01', 'scenario_01_wflow.gz')) # Click the import button self.selenium.find_element_by_xpath( "//form/div/button[@type='Submit']").click() self.wait_for_page(element_id='workflow-index') # Select the workflow self.access_workflow_from_home_page(self.workflow_name) # Open the right action self.open_action_edit('Email students in SMED') # Picture of the editor self.body_ss('scenario_01_action_SMED.png') # Edit the filter self.select_filter_tab() self.selenium.find_element_by_class_name('js-filter-edit').click() # Wait for the form to modify the filter WebDriverWait(self.selenium, 10).until( ElementHasFullOpacity((By.XPATH, "//div[@id='modal-item']"))) # Take picture of the modal self.modal_ss('scenario_01_action_filter.png') # Click in the cancel button self.cancel_modal() # Go to actions and open email self.go_to_actions() self.open_action_email('Email students in SMED') # Picture of the body self.body_ss('scenario_01_action_SMED_email.png') # End of session self.logout()
class ActionViewRunEmailReportAction(tests.OnTaskTestCase): """Test the view to run actio item filter, json and email.""" fixtures = ['initial_workflow'] filename = os.path.join( settings.BASE_DIR(), 'ontask', 'tests', 'initial_workflow', 'initial_workflow.sql', ) user_email = '*****@*****.**' user_pwd = 'boguspwd' workflow_name = 'BIOL1011' def _verify_content(self): """Verify the content of the messages received.""" self.assertTrue( mail.outbox[0].from_email == '*****@*****.**' and mail.outbox[0].subject == 'Email to instructor' and 'The emails of those students that ' in mail.outbox[0].body and '*****@*****.**' in mail.outbox[0].cc and 'Email to instructor' in mail.outbox[0].subject and '*****@*****.**' in mail.outbox[0].cc and '*****@*****.**' in mail.outbox[0].cc and '*****@*****.**' in mail.outbox[0].bcc and '*****@*****.**' in mail.outbox[0].bcc) def test_run_action_email_no_filter(self): """Run sequence of request to send email list .""" action = self.workflow.actions.get(name='Send Email with report') # Step 1 invoke the form resp = self.get_response('action:run', url_params={'pk': action.id}) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(action.id == payload['action_id']) self.assertTrue(payload['prev_url'] == reverse( 'action:run', kwargs={'pk': action.id})) self.assertTrue(payload['post_url'] == reverse('action:run_done')) self.assertTrue('post_url' in payload.keys()) self.assertTrue(status.is_success(resp.status_code)) # Step 2 send POST resp = self.get_response('action:run', url_params={'pk': action.id}, method='POST', req_params={ 'email_to': '*****@*****.**', 'cc_email': '[email protected] [email protected]', 'bcc_email': '[email protected] [email protected]', 'subject': 'Email to instructor' }) payload = SessionPayload.get_session_payload(self.last_request) self.assertTrue(payload == {}) self.assertTrue(len(mail.outbox) == 1) self.assertTrue(status.is_success(resp.status_code))
def test_s3_upload(self): """Test the S3 upload.""" # Get the regular form resp = self.get_response('dataops:s3upload_start') self.assertTrue(status.is_success(resp.status_code)) # POST the data filepath = os.path.join(settings.BASE_DIR(), 'ontask', 'fixtures', 'simple.csv') resp = self.get_response('dataops:s3upload_start', method='POST', req_params={ 'aws_bucket_name': filepath.split('/')[1], 'aws_file_key': '/'.join(filepath.split('/')[2:]), 'skip_lines_at_top': 0, 'skip_lines_at_bottom': 0, 'domain': 'file:/' }) self.assertEqual(resp.status_code, status.HTTP_302_FOUND) self.assertEqual(resp.url, reverse('dataops:upload_s2'))
class ActionViewRunZIP(test.OnTaskTestCase): """Test the view run a ZIP action.""" fixtures = ['initial_workflow'] filename = os.path.join( settings.BASE_DIR(), '..', 'initial_workflow', 'initial_workflow.sql', ) user_email = '*****@*****.**' user_pwd = 'boguspwd' workflow_name = 'BIOL1011' def test_run_zip(self): """Run the zip action.""" # Get the object first action = self.workflow.actions.get(name='Suggestions about the forum') # Request ZIP action execution resp = self.get_response('action:zip_action', {'pk': action.id}) self.assertTrue(status.is_success(resp.status_code)) # Post the execution request resp = self.get_response( 'action:zip_action', {'pk': action.id}, method='POST', req_params={ 'participant_column': 'SID', 'user_fname_column': 'email', 'confirm_items': False, 'zip_for_moodle': False, }) self.assertTrue(status.is_success(resp.status_code)) def test_run_zip_export(self): """Test the ZIP export view.""" action = self.workflow.actions.get(name='Suggestions about the forum') resp = self.get_response( 'action:zip_export', session_payload={ 'exclude_values': [], 'prev_url': reverse('action:run', kwargs={'pk': action.id}), 'post_url': reverse('action:zip_done'), 'button_label': '', 'valuerange': 0, 'step': 0, 'action_id': action.id, 'item_column': 'SID', 'user_fname_column': 'email', 'file_suffix': '', 'zip_for_moodle': False, 'confirm_items': False}) self.assertTrue(status.is_success(resp.status_code)) self.assertEqual(resp['Content-Type'], 'application/x-zip-compressed')
def test_file_upload_publish(self): response = self.google_drive_client.media_upload( name='test', file_path=str(settings.BASE_DIR('google_api/google_drive/file1.xlsx')), from_mimetype=self.google_drive_client.XLSX_MIME_TYPE, parents=[self.test_folder_id], ) file_id = response.get('id') self.assertIsNotNone(file_id) # make public read permission self.google_drive_client.set_public_permission(file_id) # update with different file self.google_drive_client.media_update(file_id=file_id, file_path=str(settings.BASE_DIR('google_api/google_drive/file2.csv')), from_mimetype='text/csv')
def __init__(self, processor_name, **kwargs): self.people_height = settings.MODEL_PEOPLE_HEIGHT network_settings = { 'weightsPath': settings.BASE_DIR(settings.MODEL_WEIGHTS_PATH), 'configPath': settings.BASE_DIR(settings.MODEL_CONFIG_PATH), 'labelsPath': settings.BASE_DIR(settings.MODEL_LABELS_PATH), 'threshold': settings.MODEL_THRESHOLD, 'confidence': settings.MODEL_CONFIDENCE, } if settings.MODEL_ENABLE_GPU: network_settings['gpu_name'] = processor_name logger.info('USANDO GPU') try: self.net = Network(**network_settings) except Exception as error: logger.error(error)
class ActionViewRunJSONAction(test.OnTaskTestCase): """Test the view to run actio item filter, json and email.""" fixtures = ['initial_workflow'] filename = os.path.join( settings.BASE_DIR(), '..', 'initial_workflow', 'initial_workflow.sql', ) user_email = '*****@*****.**' user_pwd = 'boguspwd' workflow_name = 'BIOL1011' def test_run_json_action(self): """Test JSON action execution.""" action = self.workflow.actions.get(name='Send JSON to remote server') payload = JSONPayload({ 'item_column': 'email', 'action_id': action.id, 'prev_url': reverse('action:run', kwargs={'pk': action.id}), 'post_url': reverse('action:json_done'), }) resp = self.get_response('action:run', url_params={'pk': action.id}) self.assertTrue(status.is_success(resp.status_code)) # POST -> redirect to item filter resp = self.get_response('action:run', url_params={'pk': action.id}, method='POST', req_params={ 'key_column': 'email', 'token': 'xxx', 'confirm_items': True }, session_payload=payload.get_store()) self.assertEqual(resp.status_code, status.HTTP_302_FOUND) self.assertEqual(resp.url, reverse('action:item_filter')) # POST -> done resp = self.get_response('action:run', url_params={'pk': action.id}, method='POST', req_params={ 'key_column': 'email', 'token': 'xxx' }, session_payload=payload.get_store()) self.assertTrue(status.is_success(resp.status_code))
class TableApiBase(test.OnTaskApiTestCase): fixtures = ['simple_table'] filename = os.path.join(settings.BASE_DIR(), 'table', 'fixtures', 'simple_table.sql') new_table = { "email": ["*****@*****.**", "*****@*****.**", "*****@*****.**"], "sid": [4, 5, 6], "age": [122.0, 122.1, 132.2], "another": ["bbbb", "aaab", "bbbb"], "name": ["Felipe Lotas", "Aitor Tilla", "Carmelo Coton"], "one": ["aaaa", "bbbb", "aaaa"], "registered": [True, False, True], "when": [ "2017-10-12T00:33:44+11:00", "2017-10-12T00:32:44+11:00", "2017-10-12T00:32:44+11:00" ] } incorrect_table_1 = { "email": { "0": "*****@*****.**", "1": "*****@*****.**", "2": "*****@*****.**", "3": "*****@*****.**" }, "Another column": { "0": 6.93333333333333, "1": 9.1, "2": 9.1, "3": 5.03333333333333 }, "Quiz": { "0": 1, "1": 0, "2": 3, "3": 0 } } src_df = {"sid": [1, 2, 4], "newcol": ['v1', 'v2', 'v3']} src_df2 = {"sid": [5], "forcenas": ['value']} def setUp(self): super().setUp() # Get the token for authentication and set credentials in client token = Token.objects.get(user__email='*****@*****.**') self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key) test.pg_restore_table(self.filename) def tearDown(self): test.delete_all_tables() super().tearDown()
def test_do_import(self): """Test the do_import_action functionality.""" user = get_user_model().objects.get(email='*****@*****.**') wflow = Workflow.objects.get(name=self.wflow_name) with open( os.path.join(settings.BASE_DIR(), 'ontask', 'fixtures', 'survey_to_import.gz'), 'rb') as file_obj: do_import_action(user, wflow, 'a1', file_obj) Action.objects.get(name='a1') self.assertTrue(check_wf_df(wflow))
class DecoratorAnomalies(tests.OnTaskTestCase): """Test the detection of anomalies when using decorators.""" fixtures = ['initial_workflow'] filename = os.path.join(settings.BASE_DIR(), 'ontask', 'tests', 'initial_workflow', 'initial_workflow.sql') wflow_name = 'wflow2' def test_anomalies(self): """Create various requests and verify that anomalies are detected.""" pass