Пример #1
0
    def test_action_03_send_email(self):
        # Login
        self.login('*****@*****.**')

        # GO TO THE WORKFLOW PAGE
        self.access_workflow_from_home_page(self.wflow_name)

        # Goto the action page
        self.go_to_actions()

        # Click in the page to send email
        self.open_action_run(self.action_name)
        self.wait_for_datatable('email-action-request-data')

        # Set the subject of the email
        self.selenium.find_element_by_id('id_subject').send_keys('Subject TXT')

        # Set the email column
        select = Select(self.selenium.find_element_by_id('id_item_column'))
        select.select_by_value('email')

        # Tick the track email
        self.selenium.find_element_by_id('id_track_read').click()

        # Click the send button
        self.selenium.find_element_by_xpath(
            "//button[normalize-space()='Send']").click()
        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.XPATH, "//body/div/h1"),
                                             'Action scheduled for execution'))
        WebDriverWait(self.selenium, 10).until_not(
            EC.visibility_of_element_located((By.ID, 'div-spinner')))

        # There should be a message on that page
        self.assertTrue(
            self.selenium.find_element_by_xpath(
                "//div[@id='action-run-done']/div/a").text.startswith(
                    'You may check the status in log number'))

        # Check that the email has been properly stored
        assert len(mail.outbox) == 3

        # Go to the table page
        self.go_to_table()

        # There should be a column for the email tracking
        # This column is now added by Celery which needs to be running
        # with the same DB configuration (which is not).
        # self.assertIn('EmailRead_1', self.selenium.page_source)

        # Make sure the workflow is consistent
        check_wf_df(Workflow.objects.get(name=self.wflow_name))

        # End of session
        self.logout()
Пример #2
0
    def test_table_pandas_create(self):
        # Create a second workflow
        response = self.client.post(
            reverse('workflow:api_workflows'),
            {'name': test.wflow_name + '2', 'attributes': {'one': 'two'}},
            format='json')

        # Get the only workflow in the fixture
        workflow = Workflow.objects.get(id=response.data['id'])

        # Transform new table into a data frame
        r_df = pd.DataFrame(self.new_table)
        r_df = detect_datetime_columns(r_df)

        # Upload the table
        response = self.client.post(
            reverse('table:api_pops', kwargs={'wid': workflow.id}),
            {'data_frame': df_to_string(r_df)},
            format='json')

        # Refresh wflow (has been updated)
        workflow = Workflow.objects.get(id=workflow.id)

        # Load the df from the db
        df = load_table(workflow.get_data_frame_table_name())

        # Compare both elements
        self.compare_tables(r_df, df)

        # Check that the rest of the
        # information is correct
        self.assertTrue(check_wf_df(workflow))
Пример #3
0
    def test_table_JSON_merge_to_left(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

        age = workflow.columns.filter(name='age')[0]
        age.is_key = False
        age.save()

        email = workflow.columns.filter(name='email')[0]
        email.is_key = False
        email.save()

        # Get the data through the API
        response = self.client.put(
            reverse('table:api_merge', kwargs={'wid': workflow.id}),
            {
                "src_df": self.src_df,
                "how": "left",
                "left_on": "sid",
                "right_on": "sid"
            },
            format='json')

        # Get the new workflow
        workflow = Workflow.objects.all()[0]

        # Result should have three rows as the initial DF
        self.assertEqual(workflow.nrows, 3)

        df = load_table(workflow.get_data_frame_table_name())
        self.assertEqual(df[df['sid'] == 1]['newcol'].values[0],
                         self.src_df['newcol'][0])

        # Check for df/wf consistency
        self.assertTrue(check_wf_df(workflow))
Пример #4
0
    def test_table_pandas_merge_to_left(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

        # Transform new table into string
        r_df = pd.DataFrame(self.src_df)

        # Get the data through the API
        response = self.client.put(
            reverse('table:api_pmerge', kwargs={'wid': workflow.id}),
            {
                "src_df": df_to_string(r_df),
                "how": "left",
                "left_on": "sid",
                "right_on": "sid"
            },
            format='json')

        # Get the new workflow
        workflow = Workflow.objects.all()[0]

        # Result should have three rows as the initial DF
        self.assertEqual(workflow.nrows, 3)

        df = load_table(workflow.get_data_frame_table_name())
        self.assertEqual(df[df['sid'] == 1]['newcol'].values[0],
                         self.src_df['newcol'][0])

        # Check for df/wf consistency
        self.assertTrue(check_wf_df(workflow))
Пример #5
0
    def test_table_JSON_merge_to_outer(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

        age = workflow.columns.filter(name='age')[0]
        age.is_key = False
        age.save()

        email = workflow.columns.filter(name='email')[0]
        email.is_key = False
        email.save()

        # Get the data through the API
        response = self.client.put(
            reverse('table:api_merge', kwargs={'wid': workflow.id}),
            {
                "src_df": self.src_df,
                "how": "outer",
                "left_on": "sid",
                "right_on": "sid"
            },
            format='json')

        # No anomaly should be detected
        self.assertEqual(None, response.data.get('detail'))

        # Get the new workflow
        workflow = Workflow.objects.all()[0]

        # Result should have three rows as the initial DF
        self.assertEqual(workflow.nrows, 4)

        # Check for df/wf consistency
        self.assertTrue(check_wf_df(workflow))
Пример #6
0
    def test_table_pandas_merge_to_inner(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

        # Transform new table into string
        r_df = pd.DataFrame(self.src_df)

        # Get the data through the API
        response = self.client.put(
            reverse('table:api_pmerge', kwargs={'wid': workflow.id}),
            {
                "src_df": df_to_string(r_df),
                "how": "inner",
                "left_on": "sid",
                "right_on": "sid"
            },
            format='json')

        # Get the updated object
        workflow = Workflow.objects.all()[0]

        # Result should have two rows
        self.assertEqual(workflow.nrows, 2)

        # Check for df/wf consistency
        self.assertTrue(check_wf_df(workflow))
Пример #7
0
    def test_table_pandas_merge_to_empty(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

        # Transform new table into string
        r_df = pd.DataFrame(self.new_table)

        # Get the data through the API
        response = self.client.put(
            reverse('table:api_pmerge', kwargs={'wid': workflow.id}),
            {
                "src_df": df_to_string(r_df),
                "how": "inner",
                "left_on": "sid",
                "right_on": "sid"
            },
            format='json')

        self.assertEqual(response.data['detail'],
                         'Unable to perform merge operation: '
                         + 'Merge operation produced a result with no rows')

        # Check for df/wf consistency
        workflow = Workflow.objects.all()[0]
        self.assertTrue(check_wf_df(workflow))
Пример #8
0
    def test_table_pandas_update(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

        # Transform new table into string
        r_df = pd.DataFrame(self.new_table)
        r_df = detect_datetime_columns(r_df)

        # Upload a new table
        response = self.client.put(
            reverse(
                'table:api_pops',
                kwargs={'wid': workflow.id}),
            {'data_frame': df_to_string(r_df)},
            format='json')

        # Refresh wflow (has been updated)
        workflow = Workflow.objects.get(id=workflow.id)

        # Load the df from the db
        df = load_table(workflow.get_data_frame_table_name())

        # Compare both elements
        self.compare_tables(r_df, df)

        # Check that the rest of the
        # information is correct
        workflow = Workflow.objects.get(id=workflow.id)
        self.assertTrue(check_wf_df(workflow))
Пример #9
0
    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 = Workflow.objects.all()[0]
        self.assertEqual(wflow.nrows, 19)
        self.assertEqual(wflow.ncols, 14)

        assert check_wf_df(Workflow.objects.get(name='wflow1'))

        # End of session
        self.logout()
Пример #10
0
    def test_02_second_plugin(self):
        # Login
        self.login('*****@*****.**')

        # GO TO THE WORKFLOW PAGE
        self.access_workflow_from_home_page('Plugin test')

        # Open the transform page
        self.go_to_transform()

        # Click in the second plugin
        element = self.search_table_row_by_string('transform-table', 1,
                                                  'Test Plugin 2 Name')
        element.find_element_by_link_text('Test Plugin 2 Name').click()
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.NAME, 'csrfmiddlewaretoken')))

        # Provide the execution data (input columns and merge key
        self.selenium.find_element_by_id(
            "id____ontask___upload_input_0").click()
        Select(
            self.selenium.find_element_by_id(
                "id____ontask___upload_input_0")).select_by_visible_text('A1')
        self.selenium.find_element_by_id(
            "id____ontask___upload_input_1").click()
        Select(
            self.selenium.find_element_by_id(
                "id____ontask___upload_input_1")).select_by_visible_text('A2')
        # merge key
        self.select_plugin_output_tab()
        self.selenium.find_element_by_id("id_merge_key").click()
        Select(self.selenium.find_element_by_id(
            "id_merge_key")).select_by_visible_text("email")
        # Submit the execution
        self.selenium.find_element_by_name("Submit").click()

        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.XPATH, "//body/div/h1"),
                                             'Plugin scheduled for execution'))

        # There should be a message on that page
        self.assertTrue(
            self.selenium.find_element_by_xpath(
                "//div[@id='plugin-run-done']/div/a").text.startswith(
                    'You may check the status in log number'))

        # Assert the content of the dataframe
        wflow = Workflow.objects.get(name='Plugin test')
        df = load_table(wflow.get_data_frame_table_name())
        self.assertTrue('RESULT 3' in set(df.columns))
        self.assertTrue('RESULT 4' in set(df.columns))
        self.assertTrue(df['RESULT 3'].equals(df['A1'] + df['A2']))
        self.assertTrue(df['RESULT 4'].equals(df['A1'] - df['A2']))

        assert check_wf_df(Workflow.objects.get(name='Plugin test'))

        # End of session
        self.logout()
Пример #11
0
def do_import_workflow_parse(
    user,
    name: str,
    file_item,
) -> Workflow:
    """Read gzip file, create serializer and parse the data.

    Check for validity and create the workflow

    :param user: User used for the operation

    :param name: Workflow name

    :param file_item: File item previously opened

    :return: workflow object or raise exception
    """
    data_in = gzip.GzipFile(fileobj=file_item)
    json_data = JSONParser().parse(data_in)

    _run_compatibility_patches(json_data)

    # Serialize content
    workflow_data = WorkflowImportSerializer(data=json_data,
                                             context={
                                                 'user': user,
                                                 'name': name
                                             })

    # If anything went wrong, return the string to show to the form.
    if not workflow_data.is_valid():
        raise serializers.ValidationError(workflow_data.errors)

    # Save the new workflow
    workflow = workflow_data.save()

    try:
        check_wf_df(workflow)
    except AssertionError:
        # Something went wrong.
        if workflow:
            workflow.delete()
        raise

    return workflow
Пример #12
0
    def test_table_pandas_flush(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

        # Flush the data in the table
        response = self.client.delete(
            reverse('table:api_pops', kwargs={'wid': workflow.id}))

        workflow = Workflow.objects.all()[0]
        self.assertTrue(check_wf_df(workflow))
Пример #13
0
def detail(
    request: HttpRequest,
    workflow: Optional[Workflow],
) -> HttpResponse:
    """Http request to serve the details page for the workflow.

    :param request: HTTP Request

    :return:
    """
    context = {}
    # Get the table information (if it exist)
    context['workflow'] = workflow
    context['table_info'] = None
    if workflow.has_table():
        context['table_info'] = {
            'num_rows': workflow.nrows,
            'num_cols': workflow.ncols,
            'num_actions': workflow.actions.count(),
            'num_attributes': len(workflow.attributes)
        }

    # put the number of key columns in the context
    context['num_key_columns'] = workflow.columns.filter(is_key=True, ).count()

    # Guarantee that column position is set for backward compatibility
    columns = workflow.columns.all()
    if any(col.position == 0 for col in columns):
        # At least a column has index equal to zero, so reset all of them
        for idx, col in enumerate(columns):
            col.position = idx + 1
            col.save()

    # Safety check for consistency (only in development)
    if settings.DEBUG:
        check_wf_df(workflow)

        # Columns are properly numbered
        cpos = workflow.columns.values_list('position', flat=True)
        rng = range(1, len(cpos) + 1)
        assert sorted(cpos) == list(rng)

    return render(request, 'workflow/detail.html', context)
Пример #14
0
    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))
Пример #15
0
    def test_table_pandas_merge_to_outer_NaN(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

        age = workflow.columns.filter(name='age')[0]
        age.is_key = False
        age.save()

        email = workflow.columns.filter(name='email')[0]
        email.is_key = False
        email.save()

        # Drop the column with booleans because the data type is lost
        workflow_delete_column(
            workflow,
            workflow.columns.get(name='registered')
        )

        # Transform new table into string
        r_df = pd.DataFrame(self.src_df2)

        # Load the df from the db
        df = load_table(workflow.get_data_frame_table_name())
        new_df = pd.merge(df, r_df, how="outer", left_on="sid", right_on="sid")

        # Get the data through the API
        response = self.client.put(
            reverse('table:api_pmerge', kwargs={'wid': workflow.id}),
            {
                "src_df": df_to_string(r_df),
                "how": "outer",
                "left_on": "sid",
                "right_on": "sid"
            },
            format='json')

        # Get the new workflow
        workflow = Workflow.objects.all()[0]

        # Result should have three rows as the initial DF
        self.assertEqual(workflow.nrows, 4)
        self.assertEqual(workflow.ncols, 8)

        # Load the df from the db
        df = load_table(workflow.get_data_frame_table_name())

        # Compare both elements and check wf df consistency
        self.compare_tables(df, new_df)

        # Check for df/wf consistency
        self.assertTrue(check_wf_df(workflow))
Пример #16
0
    def test_04_merge_right(self):
        self.template_merge('right', rename=False)

        # Assert the content of the dataframe
        wflow = Workflow.objects.get(name=self.wf_name)
        df = load_table(wflow.get_data_frame_table_name())

        self.assertTrue('key' in set(df.columns))
        self.assertTrue('text3' in set(df.columns))
        self.assertTrue('double3' in set(df.columns))
        self.assertTrue('bool3' in set(df.columns))
        self.assertTrue('date3' in set(df.columns))

        assert check_wf_df(Workflow.objects.get(name='Testing Merge'))

        # End of session
        self.logout()
Пример #17
0
    def test_table_pandas_merge_get(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

        # Get the data through the API
        response = self.client.get(
            reverse('table:api_pmerge', kwargs={'wid': workflow.id}))

        workflow = Workflow.objects.all()[0]

        # Transform new table into string
        r_df = string_to_df(response.data['src_df'])

        # Load the df from the db
        df = load_table(workflow.get_data_frame_table_name())

        # Compare both elements and check wf df consistency
        self.compare_tables(r_df, df)
        self.assertTrue(check_wf_df(workflow))
Пример #18
0
    def test_05_merge_outer_fail(self):
        self.template_merge('outer')

        # Assert that the error is at the top of the page
        self.assertIn(
            'Merge operation produced a result without any key columns.',
            self.selenium.page_source)

        # Assert the content of the dataframe
        wflow = Workflow.objects.get(name=self.wf_name)
        df = load_table(wflow.get_data_frame_table_name())

        self.assertTrue('key' in set(df.columns))
        self.assertTrue('key2' not in set(df.columns))
        self.assertTrue('text3' not in set(df.columns))
        self.assertTrue('double3' not in set(df.columns))
        self.assertTrue('bool3' not in set(df.columns))
        self.assertTrue('date3' not in set(df.columns))

        assert check_wf_df(Workflow.objects.get(name='Testing Merge'))

        # End of session
        self.logout()
Пример #19
0
    def test_01_symbols(self):
        symbols = '!#$%&()*+,-./\\:;<=>?@[]^_`{|}~'

        # Login
        self.login('*****@*****.**')

        # Open the workflow
        self.access_workflow_from_home_page('sss')

        # Go to the column details
        self.go_to_details()

        # Edit the name column
        self.open_column_edit('name')

        # Replace name by symbols
        self.selenium.find_element_by_id("id_name").click()
        self.selenium.find_element_by_id("id_name").clear()
        self.selenium.find_element_by_id("id_name").send_keys(symbols)

        # Click in the submit/save button
        self.selenium.find_element_by_xpath("//button[@type='submit']").click()
        # MODAL WAITING
        self.wait_close_modal_refresh_table('column-table_previous')

        # Click on the Add Column button
        self.open_add_regular_column()

        # Set name to symbols (new column) and type to string
        self.selenium.find_element_by_id("id_name").click()
        self.selenium.find_element_by_id("id_name").clear()
        self.selenium.find_element_by_id("id_name").send_keys(symbols)
        self.selenium.find_element_by_id("id_data_type").click()
        Select(self.selenium.find_element_by_id(
            "id_data_type")).select_by_visible_text("string")

        # Save the new column
        self.selenium.find_element_by_xpath("//button[@type='submit']").click()
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.ID, 'error_1_id_name')))

        # There should be a message saying that the name of this column already
        # exists
        self.assertIn('There is a column already with this name',
                      self.selenium.page_source)

        # Click again in the name and introduce something different
        self.selenium.find_element_by_id("id_name").click()
        self.selenium.find_element_by_id("id_name").clear()
        self.selenium.find_element_by_id("id_name").send_keys(symbols + '2')

        # Save the new column
        self.selenium.find_element_by_xpath("//button[@type='submit']").click()
        self.wait_close_modal_refresh_table('column-table_previous')

        # Click in the attributes section
        self.go_to_attribute_page()

        # Delete the existing one and confirm deletion
        # click the delete button in the second row
        self.selenium.find_element_by_xpath(
            '//table[@id="attribute-table"]'
            '//tr[1]/td[3]//button[contains(@class, "js-attribute-delete")]'
        ).click()
        # Click in the delete confirm button
        self.selenium.find_element_by_xpath(
            "//div[@id = 'modal-item']//div[@class = 'modal-footer']/button"
        ).click()
        # MODAL WAITING
        self.wait_for_page(element_id='workflow-detail')

        # Add a new attribute and insert key (symbols) and value
        self.create_attribute(symbols + '3', 'vvv')

        # Click in the TABLE link
        self.go_to_table()

        # Verify that everything appears normally
        self.assertIn(escape(symbols), self.selenium.page_source)
        self.assertIn(escape(symbols + '2'), self.selenium.page_source)

        # Click in the Actions navigation menu
        self.go_to_actions()

        # Edit the action-in
        self.open_action_edit('action in')

        # Go to questions
        self.select_questions_tab()

        # Set the right columns to process
        self.click_dropdown_option("//div[@id='column-selector']",
                                   '!#$%&()*+,-./\\:;<=>?@[]^_`{|}~2')
        self.wait_for_datatable('column-selected-table_previous')
        # Wait for the table to be refreshed
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located(
                (By.ID, 'column-selected-table_previous')))

        # Set some parameters
        self.select_parameters_tab()
        self.click_dropdown_option("//div[@id='select-key-column-name']",
                                   'sid')
        WebDriverWait(self.selenium, 10).until_not(
            EC.visibility_of_element_located((By.ID, 'div-spinner')))
        self.select_parameters_tab()
        self.click_dropdown_option("//div[@id='select-key-column-name']",
                                   'email')
        WebDriverWait(self.selenium, 10).until_not(
            EC.visibility_of_element_located((By.ID, 'div-spinner')))

        # Save action-in
        self.select_questions_tab()
        self.selenium.find_element_by_link_text('Done').click()
        self.wait_for_datatable('action-table_previous')

        # Click in the RUN link of the action in
        element = self.search_action('action in')
        element.find_element_by_link_text("Run").click()
        # Wait for paging widget
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located(
                (By.ID, 'actioninrun-data_previous')))

        # Enter data using the RUN menu. Select one entry to populate
        self.selenium.find_element_by_link_text("*****@*****.**").click()
        self.wait_for_page(element_id='action-row-datainput')
        self.selenium.find_element_by_id("id____ontask___select_1").click()
        self.selenium.find_element_by_id("id____ontask___select_1").clear()
        self.selenium.find_element_by_id("id____ontask___select_1").send_keys(
            "17")
        self.selenium.find_element_by_id("id____ontask___select_2").click()
        self.selenium.find_element_by_id("id____ontask___select_2").clear()
        self.selenium.find_element_by_id("id____ontask___select_2").send_keys(
            "Carmelo Coton2")
        self.selenium.find_element_by_id("id____ontask___select_3").click()
        self.selenium.find_element_by_id("id____ontask___select_3").clear()
        self.selenium.find_element_by_id("id____ontask___select_3").send_keys(
            "xxx")

        # Submit the data for one entry
        self.selenium.find_element_by_xpath(
            "//div[@id='action-row-datainput']//form//button").click()
        # Wait for paging widget
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located(
                (By.ID, 'actioninrun-data_previous')))

        # Go Back to the action table
        self.go_to_actions()

        # Edit the action out
        self.open_action_edit('action_out')

        # Click in the editor
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable((By.CLASS_NAME, 'note-editable')))
        self.selenium.find_element_by_class_name('note-editable').click()

        # Insert attribute
        self.click_dropdown_option("//div[@id='attribute-selector']",
                                   symbols + '3')

        # Insert column name
        self.click_dropdown_option("//div[@id='column-selector']", symbols)

        # Insert second column name
        self.click_dropdown_option("//div[@id='column-selector']",
                                   symbols + '2')

        # Create new condition
        self.create_condition(symbols + "4", '',
                              [(symbols, "begins with", "C")])

        # Create the filter
        self.create_filter('', [(symbols + "2", "doesn't begin with", "x")])

        # Click the preview button
        self.select_text_tab()
        self.selenium.find_element_by_class_name('js-action-preview').click()
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable(
                (By.CLASS_NAME, 'js-action-preview-nxt')))

        # Certain name should be in the page now.
        self.assertIn('Carmelo Coton', self.selenium.page_source)

        # Click in the "Close" button
        self.selenium.find_element_by_xpath(
            "//div[@id='modal-item']/div/div/div/div[2]/button[2]").click()

        assert check_wf_df(Workflow.objects.get(name='sss'))

        # End of session
        self.logout()
Пример #20
0
    def test_02_symbols(self):
        symbols = '!#$%&()*+,-./\\:;<=>?@[]^_`{|}~'

        # Login
        self.login('*****@*****.**')

        # GO TO THE WORKFLOW PAGE
        self.access_workflow_from_home_page('sss')

        # Go to column details
        self.go_to_details()

        # Edit the email column
        self.open_column_edit('email')

        # Append symbols to the name
        self.selenium.find_element_by_id("id_name").click()
        self.selenium.find_element_by_id("id_name").send_keys(symbols)

        # Save column information
        self.selenium.find_element_by_xpath("//button[@type='submit']").click()
        self.wait_close_modal_refresh_table('column-table_previous')

        # Select the age column and click in the edit button
        self.open_column_edit('age')

        # Append symbols to the name
        self.selenium.find_element_by_id("id_name").click()
        self.selenium.find_element_by_id("id_name").send_keys(symbols)

        # Save column information
        self.selenium.find_element_by_xpath("//button[@type='submit']").click()
        self.wait_close_modal_refresh_table('column-table_previous')

        # Go to the table link
        self.go_to_table()

        # Verify that everything appears normally
        self.assertIn(escape(symbols), self.selenium.page_source)
        self.assertIn('<td class=" dt-center">12</td>',
                      self.selenium.page_source)
        self.assertIn('<td class=" dt-center">12.1</td>',
                      self.selenium.page_source)
        self.assertIn('<td class=" dt-center">13.2</td>',
                      self.selenium.page_source)

        # Go to the actions page
        self.go_to_actions()

        # Edit the action-in at the top of the table
        self.open_action_edit('action in')

        # Set the correct values for an action-in
        # Set the right columns to process
        self.select_parameters_tab()
        self.click_dropdown_option("//div[@id='select-key-column-name']",
                                   'email' + symbols)
        # This wait is incorrect. Don't know how to wait for an AJAX call.
        WebDriverWait(self.selenium, 10).until_not(
            EC.visibility_of_element_located((By.ID, 'div-spinner')))

        # Done editing the action in
        self.select_questions_tab()
        self.selenium.find_element_by_link_text('Done').click()
        self.wait_for_datatable('action-table_previous')

        # Click in the run link
        self.open_action_run('action in', True)

        # Click on the first value
        self.selenium.find_element_by_link_text("*****@*****.**").click()

        # Modify the value of the column
        self.selenium.find_element_by_id("id____ontask___select_1").click()
        self.selenium.find_element_by_id("id____ontask___select_1").clear()
        self.selenium.find_element_by_id("id____ontask___select_1").send_keys(
            "14")
        # Submit changes to the first element
        self.selenium.find_element_by_xpath(
            "(//button[@name='submit'])[1]").click()
        self.wait_for_datatable('actioninrun-data_previous')

        # Click on the second value
        self.selenium.find_element_by_link_text("*****@*****.**").click()

        # Modify the value of the columne
        self.selenium.find_element_by_id("id____ontask___select_1").clear()
        self.selenium.find_element_by_id("id____ontask___select_1").send_keys(
            "15")
        # Submit changes to the second element
        self.selenium.find_element_by_xpath(
            "(//button[@name='submit'])[1]").click()
        self.wait_for_datatable('actioninrun-data_previous')

        # Click on the third value
        self.selenium.find_element_by_link_text("*****@*****.**").click()

        # Modify the value of the column
        self.selenium.find_element_by_id("id____ontask___select_1").click()
        self.selenium.find_element_by_id("id____ontask___select_1").clear()
        self.selenium.find_element_by_id("id____ontask___select_1").send_keys(
            "16")
        # Submit changes to the second element
        self.selenium.find_element_by_xpath(
            "(//button[@name='submit'])[1]").click()
        self.wait_for_datatable('actioninrun-data_previous')

        # Click in the back link!
        self.selenium.find_element_by_link_text('Back').click()
        self.wait_for_datatable('action-table_previous')

        # Go to the table page
        self.go_to_table()

        # Assert the new values
        self.assertIn('<td class=" dt-center">14</td>',
                      self.selenium.page_source)
        self.assertIn('<td class=" dt-center">15</td>',
                      self.selenium.page_source)
        self.assertIn('<td class=" dt-center">16</td>',
                      self.selenium.page_source)

        assert check_wf_df(Workflow.objects.get(name='sss'))

        # End of session
        self.logout()
Пример #21
0
    def test_01_first_plugin(self):
        # Login
        self.login('*****@*****.**')

        # GO TO THE WORKFLOW PAGE
        self.access_workflow_from_home_page('Plugin test')

        # Open the transform page
        self.go_to_transform()

        # Click in the first plugin
        element = self.search_table_row_by_string('transform-table', 1,
                                                  'Test Plugin 1 Name')
        element.find_element_by_link_text('Test Plugin 1 Name').click()
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.NAME, 'csrfmiddlewaretoken')))
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//input[@type='text']")))

        # Provide the execution data
        self.selenium.find_element_by_xpath("//input[@type='text']").click()
        self.selenium.find_element_by_name("columns").click()
        self.selenium.find_element_by_xpath(
            "(//input[@name='columns'])[2]").click()

        # Select the merge key
        self.select_plugin_output_tab()

        self.selenium.find_element_by_id("id_merge_key").click()
        Select(self.selenium.find_element_by_id(
            "id_merge_key")).select_by_visible_text("email")

        # Submit the execution
        self.selenium.find_element_by_name("Submit").click()
        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.XPATH, "//body/div/h1"),
                                             'Plugin scheduled for execution'))

        # There should be a message on that page
        self.assertTrue(
            self.selenium.find_element_by_xpath(
                "//div[@id='plugin-run-done']/div/a").text.startswith(
                    'You may check the status in log number'))

        # Assert the content of the dataframe
        wflow = Workflow.objects.get(name='Plugin test')
        self.assertTrue(
            is_column_in_table(wflow.get_data_frame_table_name(), 'RESULT 1'))
        self.assertTrue(
            is_column_in_table(wflow.get_data_frame_table_name(), 'RESULT 2'))
        df = load_table(wflow.get_data_frame_table_name())
        self.assertTrue(all([x == 1 for x in df['RESULT 1']]))
        self.assertTrue(all([x == 2 for x in df['RESULT 2']]))

        # Second execution, this time adding a suffix to the column
        self.go_to_actions()
        self.go_to_transform()

        # Click in the first plugin
        element = self.search_table_row_by_string('transform-table', 1,
                                                  'Test Plugin 1 Name')
        element.find_element_by_link_text('Test Plugin 1 Name').click()
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.NAME, 'csrfmiddlewaretoken')))
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable((By.XPATH, "//input[@type='text']")))

        # Provide the execution data
        self.selenium.find_element_by_xpath("//input[@type='text']").click()
        # Wait for the column eleemnt to open
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable((By.NAME, "columns"), ))
        self.selenium.find_element_by_name("columns").click()
        self.selenium.find_element_by_xpath(
            "(//input[@name='columns'])[2]").click()

        # Select the merge key
        self.select_plugin_output_tab()
        self.selenium.find_element_by_id("id_merge_key").click()
        Select(self.selenium.find_element_by_id(
            "id_merge_key")).select_by_visible_text("email")

        # Put the suffix _2
        self.selenium.find_element_by_id("id_out_column_suffix").click()
        self.selenium.find_element_by_id("id_out_column_suffix").clear()
        self.selenium.find_element_by_id("id_out_column_suffix").send_keys(
            "_2")

        # Submit the execution
        self.selenium.find_element_by_name("Submit").click()
        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.XPATH, "//body/div/h1"),
                                             'Plugin scheduled for execution'))

        # There should be a message on that page
        self.assertTrue(
            self.selenium.find_element_by_xpath(
                "//div[@id='plugin-run-done']/div/a").text.startswith(
                    'You may check the status in log number'))

        # Assert the content of the dataframe
        wflow = Workflow.objects.get(name='Plugin test')
        self.assertTrue(
            is_column_in_table(wflow.get_data_frame_table_name(),
                               'RESULT 1_2'))
        self.assertTrue(
            is_column_in_table(wflow.get_data_frame_table_name(),
                               'RESULT 2_2'))
        df = load_table(wflow.get_data_frame_table_name())
        self.assertTrue(all([x == 1 for x in df['RESULT 1_2']]))
        self.assertTrue(all([x == 2 for x in df['RESULT 2_2']]))

        assert check_wf_df(Workflow.objects.get(name='Plugin test'))

        # End of session
        self.logout()
Пример #22
0
    def test_01_nan_manipulation(self):
        # Login
        self.login('*****@*****.**')

        self.create_new_workflow('NaN')

        # Go to CSV Upload/Merge
        self.selenium.find_element_by_xpath(
            "//table[@id='dataops-table']//a[normalize-space()='CSV']").click(
            )
        WebDriverWait(self.selenium, 10).until(
            EC.visibility_of_element_located((By.XPATH, "//form")))

        # Select file and upload
        self.selenium.find_element_by_id("id_data_file").send_keys(
            os.path.join(settings.BASE_DIR(), 'ontask', 'fixtures',
                         'test_df_merge_update_df1.csv'))
        self.selenium.find_element_by_name("Submit").click()
        self.wait_for_page()

        # Submit
        self.selenium.find_element_by_xpath(
            "(//button[@name='Submit'])[2]").click()
        self.wait_for_datatable('table-data_previous')

        # Select again the upload/merge function
        self.go_to_csv_upload_merge_step_1()

        # Select the second file and submit
        self.selenium.find_element_by_id("id_data_file").send_keys(
            os.path.join(settings.BASE_DIR(), 'ontask', 'fixtures',
                         'test_df_merge_update_df2.csv'))
        self.selenium.find_element_by_name("Submit").click()
        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.XPATH, "//body/div/h1"),
                                             'Select Columns'))

        # Select all the columns for upload
        self.selenium.find_element_by_name("Submit").click()
        # Wait for the upload/merge
        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.XPATH, "//body/div/h1"),
                                             'Select Keys and Merge Option'))

        # Choose the default options for the merge (key and outer)
        # Select the merger function type
        select = Select(self.selenium.find_element_by_id('id_how_merge'))
        select.select_by_value('outer')
        self.selenium.find_element_by_name("Submit").click()
        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.XPATH, "//body/div/h1"),
                                             'Review and confirm'))

        # Check the merge summary and proceed
        self.selenium.find_element_by_name("Submit").click()
        # Wait for the upload/merge to finish
        self.wait_for_datatable('table-data_previous')

        # Go to the actions page
        self.go_to_actions()

        # Create a new action
        self.create_new_personalized_text_action("action out", '')

        # Create three conditions
        self.select_condition_tab()
        self.create_condition("bool1 cond", '', [('bool1', 'equal', 'true')])
        self.create_condition("bool 2 cond", '', [('bool2', 'equal', 'true')])
        self.create_condition('bool3 cond', '', [('bool3', 'equal', 'true')])

        # insert the action text
        self.select_text_tab()
        self.selenium.execute_script(
            """$('#id_text_content').summernote('editor.insertText', 
            "{0}");""".format(self.action_text))

        # Click in the preview and circle around the 12 rows
        self.open_browse_preview(11)

        assert check_wf_df(Workflow.objects.get(name='wflow1'))

        # End of session
        self.logout()