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(pk=response.data['id']) # Transform new table into a data frame r_df = pd.DataFrame(self.new_table) r_df = ops.detect_datetime_columns(r_df) # Upload the table response = self.client.post( 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))
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))
def to_internal_value(self, data): # POST / PUT (and then GET to refresh) try: df = pd.DataFrame(data) # Detect date/time columns df = ops.detect_datetime_columns(df) except Exception as e: raise serializers.ValidationError(e) return df
def test_table_JSON_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_ops', kwargs={'pk': workflow.id})) # Transform the response into a data frame r_df = pd.DataFrame(response.data['data_frame']) r_df = ops.detect_datetime_columns(r_df) # Load the df from the db df = pandas_db.load_from_db(workflow.id) # Compare both elements self.compare_tables(r_df, df)
def test_table_pandas_JSON_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_merge', kwargs={'pk': workflow.id})) # Transform new table into string r_df = pd.DataFrame(response.data['src_df']) r_df = ops.detect_datetime_columns(r_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))