コード例 #1
0
 def test_activity_store_create_activity(self):
     """Test activity creation."""
     Activity.init(sample_file_url)
     activity = Activity.create("Activity", "Activities", "Activity Status")
     rc = 0
     try:
         activity_id = activity.id
     except:
         rc = 1
         raise ActivityError(errno.EINVAL,
                             "Error: While fetching Activity ID")
     self.assertEqual(rc, 0)
     with self.assertRaises(ActivityError):
         Activity.create("Activity", "Activities", None)
     try:
         activities = load_data(sample_file)
         activity_data = json.loads(activities.get(activity_id))
     except:
         rc = 1
         raise ActivityError(errno.EINVAL,
                             "Error: While fetching Activity data")
     self.assertEqual(rc, 0)
     self.assertEqual(activity_data.get('resource_path'), "Activities")
     self.assertNotEqual(activity_data.get('resource_path'), "")
     self.assertEqual(activity_data.get('description'), "Activity Status")
     self.assertNotEqual(activity_data.get('description'), "")
     self.assertEqual(activity_data.get('pct_progress'), 0)
     self.assertEqual(activity_data.get('status'), "NEW")
コード例 #2
0
 def test_activity_store_update_activity(self):
     """Test Update Activity."""
     Activity.init(sample_file_url)
     activity = Activity.create("Activity", "Activities", "Activity Status")
     rc = 0
     try:
         activity_id = activity.id
     except:
         rc = 1
         raise ActivityError(errno.EINVAL,
                             "Error: While fetching Activity ID")
     self.assertEqual(rc, 0)
     pct_progress = 30
     status_desc = "Activity is in progress."
     Activity.update(activity, pct_progress, status_desc)
     try:
         activities = load_data(sample_file)
         activity_data = json.loads(activities.get(activity_id))
     except:
         rc = 1
         raise ActivityError(errno.EINVAL,
                             "Error: While fetching Activity data")
     self.assertEqual(rc, 0)
     self.assertEqual(activity_data.get('pct_progress'), pct_progress)
     self.assertIsNotNone(activity_data.get('pct_progress'),
                          "pct_progress key is not present")
     self.assertEqual(activity_data.get('status'), "IN_PROGRESS")
     self.assertIsNotNone(activity_data.get('status'),
                          "status key is not present")
     self.assertEqual(activity_data.get('status_description'), status_desc)
     self.assertIsNotNone(activity_data.get('status_description'),
                          "status_description key is not present")
コード例 #3
0
 def update(args) -> str:
     """Updates value for the given keys."""
     activity_id = args.args[0]
     pct_complete = args.args[1]
     status = args.args[2]
     activity = Activity.get(activity_id)
     Activity.update(activity, pct_complete, status)
コード例 #4
0
 def test_activity_store_get_activity(self):
     """Test get activity details."""
     Activity.init(sample_file_url)
     activity = Activity.create("Activity", "Activities", "Activity Status")
     activity_details = Activity.get(activity.id)
     activity_data = json.loads(activity_details.payload.json)
     self.assertEqual(activity_data.get('name'), 'Activity')
     self.assertEqual(activity_data.get('resource_path'), 'Activities')
     self.assertEqual(activity_data.get('description'), 'Activity Status')
コード例 #5
0
 def test_activity_store_suspend_after_finish(self):
     """Test Finish activity."""
     Activity.init(sample_file_url)
     activity = Activity.create("Activity", "Activities", "Activity Status")
     rc = 0
     try:
         activity_id = activity.id
     except:
         rc = 1
         raise ActivityError(errno.EINVAL,
                             "Error: While fetching Activity ID")
     self.assertEqual(rc, 0)
     pct_progress = 40
     Activity.update(activity, pct_progress)
     Activity.finish(activity, 0, "activity completed successfully")
     with self.assertRaises(ActivityError):
         pct_progress = 50
         Activity.suspend(activity)
     try:
         activities = load_data(sample_file)
         activity_data = json.loads(activities.get(activity_id))
     except:
         rc = 1
         raise ActivityError(errno.EINVAL,
                             "Error: While fetching Activity data")
     self.assertEqual(activity_data.get('pct_progress'), 100)
     self.assertEqual(activity_data.get('status'), "COMPLETED")
コード例 #6
0
 def test_activity_store_suspend_activity(self):
     """Test Finish activity."""
     Activity.init(sample_file_url)
     activity = Activity.create("Activity", "Activities", "Activity Status")
     activity1 = "activity"
     rc = 0
     try:
         activity_id = activity.id
     except:
         rc = 1
         raise ActivityError(errno.EINVAL,
                             "Error: While fetching Activity ID")
     self.assertEqual(rc, 0)
     pct_progress = 40
     Activity.update(activity, pct_progress)
     Activity.suspend(activity, "activity suspended ..")
     with self.assertRaises(ActivityError):
         Activity.finish(activity1, 0)
     try:
         activities = load_data(sample_file)
         activity_data = json.loads(activities.get(activity_id))
     except:
         rc = 1
         raise ActivityError(errno.EINVAL,
                             "Error: While fetching Activity data")
     self.assertIsNotNone(activity_data.get('updated_time'),
                          "updated_time key is not present")
     self.assertEqual(activity_data.get('pct_progress'), pct_progress)
     self.assertEqual(activity_data.get('status'), "SUSPENDED")
コード例 #7
0
 def create(args):
     """Set Key Value."""
     if len(args.args) < 2:
         raise ActivityError(errno.EINVAL, "Insufficient args for create")
     resource = args.args[0]
     description = args.args[1]
     activity = Activity.create(resource, description)
     return activity.id
コード例 #8
0
 def test_activity_store_finish_activity(self):
     """Test Finish activity."""
     Activity.init(sample_file_url)
     activity = Activity.create("Activity", "Activities", "Activity Status")
     activity1 = "activity"
     rc = 0
     try:
         activity_id = activity.id
     except:
         rc = 1
         raise ActivityError(errno.EINVAL,
                             "Error: While fetching Activity ID")
     self.assertEqual(rc, 0)
     Activity.finish(activity, 0, "activity completed successfully.")
     with self.assertRaises(ActivityError):
         Activity.finish(activity1, 0)
     try:
         activities = load_data(sample_file)
         activity_data = json.loads(activities.get(activity_id))
     except:
         rc = 1
         raise ActivityError(errno.EINVAL,
                             "Error: While fetching Activity data")
     self.assertIsNotNone(activity_data.get('updated_time'),
                          "updated_time key is not present")
     self.assertEqual(activity_data.get('pct_progress'), 100)
     self.assertEqual(activity_data.get('rc'), 0)
     self.assertNotEqual(activity_data.get('rc'), "0")
     self.assertEqual(activity_data.get('status'), "COMPLETED")
コード例 #9
0
 def finish(args):
     """Completes the Activity."""
     activity_id = args.args[0]
     activity = Activity.get(activity_id)
     Activity.finish(activity)
コード例 #10
0
 def search(args):
     """Searches for a activity as per given criteria."""
     resource_path = args.args[0]
     filters = args.args[1].split(',')
     activity_list = Activity.search(resource_path, filters)
     return activity_list
コード例 #11
0
 def show(args):
     """Returns activity details present in store."""
     activity_id = args.args[0]
     activity = Activity.get(activity_id)
     return activity.payload.json
コード例 #12
0
 def start(args):
     """Starts the Activity."""
     activity_id = args.args[0]
     activity = Activity.get(activity_id)
     Activity.start(activity)
コード例 #13
0
 def init(url: str):
     """Load ActivityStore URL."""
     Activity.init(url)