Beispiel #1
0
    def test_table_JSON_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_ops', kwargs={'pk': workflow.id}))

        workflow = Workflow.objects.all()[0]
        self.assertTrue(pandas_db.check_wf_df(workflow))
Beispiel #2
0
def do_import_workflow(user, name, file_item):
    """
    Receives a name and a file item (submitted through a form) and creates
    the structure of workflow, conditions, actions and data table.

    :param user: User record to use for the import (own all created items)
    :param name: Workflow name (it has been checked that it does not exist)
    :param file_item: File item obtained through a form
    :return:
    """

    try:
        data_in = gzip.GzipFile(fileobj=file_item)
        data = JSONParser().parse(data_in)
    except IOError:
        return _('Incorrect file. Expecting a GZIP file (exported workflow).')

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

    # If anything went wrong, return the string to show to the form.
    workflow = None
    try:
        if not workflow_data.is_valid():
            return 'Unable to import the workflow' + ' (' + \
                   workflow_data.errors + ')'

        # Save the new workflow
        workflow = workflow_data.save(user=user, name=name)
    except (TypeError, NotImplementedError) as e:
        return _('Unable to import workflow (Exception: {0})').format(
            e.message)
    except serializers.ValidationError as e:
        return _('Unable to import workflow due to a validation error')
    except Exception as e:
        return _('Unable to import workflow (Exception: {0})').format(
            e.message)

    if not pandas_db.check_wf_df(workflow):
        # Something went wrong.
        workflow.delete()
        return _('Workflow data with incorrect structure.')

    # Success
    # Log the event
    logs.ops.put(user, 'workflow_import', workflow, {
        'id': workflow.id,
        'name': workflow.name
    })
    return None
Beispiel #3
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, Column.objects.get(workflow=workflow, name='registered'))

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

        # Load the df from the db
        df = pandas_db.load_from_db(workflow.id)
        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={'pk': workflow.id}), {
                "src_df": serializers.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 = pandas_db.load_from_db(workflow.id)

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

        # Check for df/wf consistency
        self.assertTrue(pandas_db.check_wf_df(workflow))
Beispiel #4
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={'pk': workflow.id}))

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

        # Load the df from the db
        df = pandas_db.load_from_db(workflow.id)

        # Compare both elements and check wf df consistency
        self.compare_tables(r_df, df)
        workflow = Workflow.objects.all()[0]
        self.assertTrue(pandas_db.check_wf_df(workflow))
Beispiel #5
0
    def test_04_merge_right(self):
        self.template_merge('right')

        # Assert the content of the dataframe
        wflow = Workflow.objects.get(name=self.wf_name)
        df = pandas_db.load_from_db(wflow.id)

        self.assertTrue('key' in set(df.columns))
        self.assertTrue('key2' 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 pandas_db.check_wf_df(
            Workflow.objects.get(name='Testing Merge'))

        # End of session
        self.logout()
Beispiel #6
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')
        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
        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()
        self.wait_for_page(element_id='plugin-execution-report')

        # Done. Click continue.
        self.selenium.find_element_by_link_text('Continue').click()
        self.wait_for_datatable('table-data_previous')

        # Assert the content of the dataframe
        wflow = Workflow.objects.get(name='Plugin test')
        df = pandas_db.load_from_db(wflow.id)
        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 pandas_db.check_wf_df(Workflow.objects.get(name='Plugin test'))

        # End of session
        self.logout()
Beispiel #7
0
    def get_context_data(self, **kwargs):

        context = super(WorkflowDetailView, self).get_context_data(**kwargs)

        workflow_id = self.request.session.get('ontask_workflow_id', None)
        if not workflow_id:
            return context

        # Get the table information (if it exist)
        context['table_info'] = None
        if ops.workflow_id_has_table(self.object.id):
            context['table_info'] = {
                'num_rows': self.object.nrows,
                'num_cols': self.object.ncols,
                'num_actions': self.object.actions.all().count(),
                'num_attributes': len(self.object.attributes)
            }

        # Get the key columns
        columns = Column.objects.filter(workflow__id=workflow_id, is_key=True)

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

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

        # Safety check for consistency (only in development)
        if settings.DEBUG:
            assert pandas_db.check_wf_df(self.object)

            # Columns are properly numbered
            cpos = Column.objects.filter(workflow__id=workflow_id).values_list(
                'position', flat=True)
            assert sorted(cpos) == range(1, len(cpos) + 1)

        return context
Beispiel #8
0
    def test_table_JSON_merge_to_empty(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

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

        self.assertEqual(response.data['detail'],
                         'Merge operation produced a result with no rows')

        # Check for df/wf consistency
        workflow = Workflow.objects.all()[0]
        self.assertTrue(pandas_db.check_wf_df(workflow))
Beispiel #9
0
    def test_table_JSON_merge_to_inner(self):
        # Get the only workflow in the fixture
        workflow = Workflow.objects.all()[0]

        # Get the data through the API
        response = self.client.put(reverse('table:api_merge',
                                           kwargs={'pk': workflow.id}), {
                                               "src_df": self.src_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(pandas_db.check_wf_df(workflow))
Beispiel #10
0
    def test_table_pandas_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()

        # 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={'pk': workflow.id}), {
                "src_df": serializers.df_to_string(r_df),
                "how": "outer",
                "left_on": "sid",
                "right_on": "sid"
            },
                                   format='json')

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

        # 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(pandas_db.check_wf_df(workflow))
Beispiel #11
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 = ops.detect_datetime_columns(r_df)

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

        # Load the df from the db
        df = pandas_db.load_from_db(workflow.id)

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

        # Refresh wflow (has been updated) and check that the rest of the
        # information is correct
        workflow = Workflow.objects.get(pk=workflow.id)
        self.assertTrue(pandas_db.check_wf_df(workflow))
Beispiel #12
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 = pandas_db.load_from_db(wflow.id)

        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 pandas_db.check_wf_df(
            Workflow.objects.get(name='Testing Merge'))

        # End of session
        self.logout()
Beispiel #13
0
    def test_action_03_send_email(self):
        # Login
        self.login('*****@*****.**')

        self.open(reverse('workflow:index'))

        # GO TO THE WORKFLOW PAGE
        WebDriverWait(self.selenium,
                      10).until(EC.title_is('OnTask :: Workflows'))
        self.assertIn('New Workflow', self.selenium.page_source)
        self.assertIn('Import Workflow', self.selenium.page_source)

        # Open the workflow
        wf_link = self.selenium.find_element_by_link_text(self.wflow_name)
        wf_link.click()
        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.CLASS_NAME, 'page-header'),
                                             'Workflow Details'))
        WebDriverWait(self.selenium, 10).until(
            EC.element_to_be_clickable((By.CLASS_NAME, 'success')))

        # Goto the action page
        self.selenium.find_element_by_link_text('Actions').click()
        self.assertIn('New Action', self.selenium.page_source)

        # Click in the page to send email
        self.selenium.find_element_by_link_text('Email').click()

        # Set the subject of the email
        self.selenium.find_element_by_id('id_subject').send_keys('Subject TXT')
        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.CLASS_NAME, 'page-header'),
                                             'Send emails'))

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

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

        # Tick add column
        self.selenium.find_element_by_id('id_add_column').click()

        # Click the send button
        self.selenium.find_element_by_class_name('btn-success').click()
        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.CLASS_NAME, 'page-header'),
                                             'Email action'))

        # There should be a message on that page
        self.assertIn('Emails successfully sent', self.selenium.page_source)

        # Go to the table page
        self.open(reverse('table:display'))
        # Wait for
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.ID, 'table-data_previous')))

        # There should be a column for the email tracking
        self.assertIn('EmailRead_1', self.selenium.page_source)

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

        # End of session
        self.logout()
Beispiel #14
0
    def test_02_workflow_column_create_delete(self):
        new_cols = [
            ('newc1', 'string', 'male,female', ''),
            ('newc2', 'boolean', '', 'True'),
            ('newc3', 'integer', '0, 10, 20, 30', '0'),
            ('newc4', 'integer', '0, 0.5, 1, 1.5, 2', '0'),
            ('newc5', 'datetime', '', '2017-10-11 00:00:00.000+11:00'),
        ]

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

        # Go to the details page
        self.access_workflow_from_home_page(test.wflow_name)

        # Go to column details
        self.go_to_details()

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

        # Untick the is_key option
        is_key = self.selenium.find_element_by_id('id_is_key')
        self.assertTrue(is_key.is_selected())
        is_key.click()
        # Click on the Submit button
        self.selenium.find_element_by_xpath(
            "//div[@id='modal-item']/div/div/form/div/button[@type='submit']"
        ).click()
        self.wait_close_modal_refresh_table('column-table_previous')

        # First column must be age, number
        self.assert_column_name_type('age', 'Number', 1)

        # ADD COLUMNS
        idx = 6
        for cname, ctype, clist, cinit in new_cols:
            # ADD A NEW COLUMN
            self.add_column(cname, ctype, clist, cinit, idx)
            pandas_db.check_wf_df(Workflow.objects.get(pk=1))
            idx += 1

        # CHECK THAT THE COLUMNS HAVE BEEN CREATED (starting in the sixth)
        idx = 6
        for cname, ctype, _, _ in new_cols:
            if ctype == 'integer' or ctype == 'double':
                ctype = 'Number'
            elif ctype == 'string':
                ctype = 'Text'
            elif ctype == 'boolean':
                ctype = 'True/False'
            elif ctype == 'datetime':
                ctype = 'Date/Time'

            self.assert_column_name_type(cname, ctype, idx)
            idx += 1

        # DELETE THE COLUMNS
        for cname, _, _, _ in new_cols:
            self.delete_column(cname)

        # Sixth column must be one string
        self.assert_column_name_type('one', 'Text', 6)

        # End of session
        self.logout()
Beispiel #15
0
    def test_02_workflow_column_create_delete(self):
        new_cols = [
            ('newc1', 'string', 'male,female', ''),
            ('newc2', 'boolean', '', 'True'),
            ('newc3', 'integer', '0, 10, 20, 30', '0'),
            ('newc4', 'integer', '0, 0.5, 1, 1.5, 2', '0'),
            ('newc5', 'datetime', '', '2017-10-11 00:00:00.000+11:00'),
        ]

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

        self.open(reverse('workflow:index'))

        # GO TO THE WORKFLOW PAGE
        WebDriverWait(self.selenium,
                      10).until(EC.title_is('OnTask :: Workflows'))
        self.assertIn('New workflow', self.selenium.page_source)
        self.assertIn('Import workflow', self.selenium.page_source)

        # Open the workflow
        wf_link = self.selenium.find_element_by_link_text(test.wflow_name)
        wf_link.click()
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.CLASS_NAME, 'success')))

        # Edit the age column
        self.selenium.find_element_by_xpath(
            "//table[@id='column-table']/tbody/tr[1]/td[5]/div/button[1]"
        ).click()
        self.selenium.find_element_by_class_name(
            'js-workflow-column-edit').click()
        WebDriverWait(self.selenium, 10).until(
            EC.text_to_be_present_in_element((By.CLASS_NAME, 'modal-title'),
                                             'Edit column'))
        # Untick the is_key option
        is_key = self.selenium.find_element_by_id('id_is_key')
        self.assertTrue(is_key.is_selected())
        is_key.click()
        # Click on the Submit button
        self.selenium.find_element_by_xpath(
            "//div[@id='modal-item']/div/div/form/div/button[@type='submit']"
        ).click()
        self.wait_close_modal_refresh_table('column-table_previous')

        # First column must be age, number
        self.assertEqual(
            self.selenium.find_element_by_xpath(
                "//table[@id='column-table']/tbody/tr[1]/td[2]").text, 'age')
        self.assertEqual(
            self.selenium.find_element_by_xpath(
                "//table[@id='column-table']/tbody/tr[1]/td[3]").text,
            'number')

        # ADD COLUMNS
        idx = 6
        for cname, ctype, clist, cinit in new_cols:
            # ADD A NEW COLUMN
            WebDriverWait(self.selenium, 10).until(
                EC.element_to_be_clickable(
                    (By.CLASS_NAME, 'js-workflow-column-add')))
            self.selenium.find_element_by_class_name(
                'js-workflow-column-add').click()
            WebDriverWait(self.selenium, 10).until(
                EC.element_to_be_clickable((By.ID, 'id_name')))
            # Set the fields
            self.selenium.find_element_by_id('id_name').send_keys(cname)
            select = Select(self.selenium.find_element_by_id('id_data_type'))
            select.select_by_value(ctype)
            if clist:
                self.selenium.find_element_by_id(
                    'id_raw_categories').send_keys(clist)
            if cinit:
                self.selenium.find_element_by_id('id_initial_value').send_keys(
                    cinit)
            self.selenium.find_element_by_id('id_position').send_keys(str(idx))

            # Click on the Submit button
            self.selenium.find_element_by_xpath(
                "//div[@id='modal-item']/div/div/form/div[@class='modal-footer']/button[@type='submit']"
            ).click()
            self.wait_close_modal_refresh_table('column-table_previous')
            pandas_db.check_wf_df(Workflow.objects.get(pk=1))

            idx += 1

        # CHECK THAT THE COLUMNS HAVE BEEN CREATED (starting in the sixth)
        idx = 6
        for cname, ctype, _, _ in new_cols:
            if ctype == 'integer':
                ctype = 'number'
            row_path1 = "//table[@id='column-table']/tbody/tr[{0}]/td[2]"
            row_path2 = "//table[@id='column-table']/tbody/tr[{0}]/td[3]"

            # Third column must be age, double
            self.assertEqual(
                self.selenium.find_element_by_xpath(
                    row_path1.format(idx)).text, cname)
            self.assertEqual(
                self.selenium.find_element_by_xpath(
                    row_path2.format(idx)).text, ctype)
            idx += 1

        # DELETE THE COLUMNS
        for cname, ctype, _, _ in new_cols:
            row_prefix = "//table[@id='column-table']/tbody/tr[6]/td[5]"
            self.selenium.find_element_by_xpath(row_prefix +
                                                "/div/button[1]").click()
            self.selenium.find_element_by_xpath(
                row_prefix + "/div/ul/li[3]/button").click()
            WebDriverWait(self.selenium, 10).until(
                EC.text_to_be_present_in_element(
                    (By.CLASS_NAME, 'modal-title'), 'Confirm column deletion'))
            self.selenium.find_element_by_xpath(
                "//div[@id='modal-item']//button[@type='submit']").click()
            # Wait for modal to close
            WebDriverWait(self.selenium, 10).until_not(
                EC.presence_of_element_located((By.CLASS_NAME, 'modal-open')))
            # Wait for the details page to reload.
            WebDriverWait(self.selenium, 10).until(
                EC.element_to_be_clickable((By.CLASS_NAME, 'success')))

        # Sixth column must be one string
        self.assertEqual(
            self.selenium.find_element_by_xpath(
                "//table[@id='column-table']/tbody/tr[6]/td[2]").text, 'one')
        self.assertEqual(
            self.selenium.find_element_by_xpath(
                "//table[@id='column-table']/tbody/tr[6]/td[3]").text,
            'string')

        # End of session
        self.logout()
Beispiel #16
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()
        select = Select(
            self.selenium.find_element_by_id('select-key-column-name'))
        select.select_by_visible_text('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 pandas_db.check_wf_df(Workflow.objects.get(name='sss'))

        # End of session
        self.logout()
Beispiel #17
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')
        element.find_element_by_link_text('Test Plugin 1 Name').click()
        WebDriverWait(self.selenium, 10).until(
            EC.presence_of_element_located((By.NAME, 'csrfmiddlewaretoken')))

        # 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.presence_of_element_located((By.ID, 'plugin-execution-report')))

        # Done. Click continue.
        self.selenium.find_element_by_link_text('Continue').click()
        self.wait_for_datatable('table-data_previous')

        # Assert the content of the dataframe
        wflow = Workflow.objects.get(name='Plugin test')
        df = pandas_db.load_from_db(wflow.id)
        self.assertTrue('RESULT 1' in set(df.columns))
        self.assertTrue('RESULT 2' in set(df.columns))
        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_transform()

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

        # 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.presence_of_element_located((By.ID, 'plugin-execution-report')))

        # Done. Click continue.
        self.selenium.find_element_by_link_text('Continue').click()
        self.wait_for_datatable('table-data_previous')

        # Assert the content of the dataframe
        wflow = Workflow.objects.get(name='Plugin test')
        df = pandas_db.load_from_db(wflow.id)
        self.assertTrue('RESULT 1_2' in set(df.columns))
        self.assertTrue('RESULT 2_2' in set(df.columns))
        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 pandas_db.check_wf_df(Workflow.objects.get(name='Plugin test'))

        # End of session
        self.logout()
Beispiel #18
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 "
            "Upload/Merge']").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_file").send_keys(
            os.path.join(settings.BASE_DIR(), 'dataops', '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_file").send_keys(
            os.path.join(settings.BASE_DIR(), 'dataops', '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"),
                                             'Step 2: 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"),
                'Step 3: 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"),
                                             'Step 4: 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', None, True)])
        self.create_condition("bool 2 cond", '', [('bool2', None, True)])
        self.create_condition('bool3 cond', '', [('bool3', None, True)])

        # insert the action text
        self.select_text_tab()
        self.selenium.execute_script(
            """$('#id_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 pandas_db.check_wf_df(Workflow.objects.get(name='wflow1'))

        # End of session
        self.logout()
Beispiel #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[@class='modal-footer']/button[2]").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')

        # Set the right columns to process
        select = Select(self.selenium.find_element_by_id('select-column-name'))
        select.select_by_visible_text('!#$%&()*+,-./:;<=>?@[\]^_`{|}~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()
        select = Select(
            self.selenium.find_element_by_id('select-key-column-name'))
        select.select_by_visible_text('sid')
        WebDriverWait(self.selenium, 10).until_not(
            EC.visibility_of_element_located((By.ID, 'div-spinner')))
        self.select_parameters_tab()
        select = Select(
            self.selenium.find_element_by_id('select-key-column-name'))
        select.select_by_visible_text('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')

        # Insert attribute
        self.selenium.find_element_by_id("select-attribute-name").click()
        Select(self.selenium.find_element_by_id("select-attribute-name")
               ).select_by_visible_text("- Insert Attribute -")

        # Insert column name
        self.selenium.find_element_by_id("select-column-name").click()
        Select(self.selenium.find_element_by_id(
            "select-column-name")).select_by_visible_text(symbols)

        # Insert second column name
        self.selenium.find_element_by_id("select-column-name").click()
        Select(self.selenium.find_element_by_id(
            "select-column-name")).select_by_visible_text(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 pandas_db.check_wf_df(Workflow.objects.get(name='sss'))

        # End of session
        self.logout()