# Path: newsApp/workerJob.py
# class WorkerJob:
#     """
#     Represents a job which can be processed by one of the worker roles.
#     """
# 
#     def __init__(self, jobName, jobParams, jobId = None):
#         """
#         Instantiates a new worker job object.
#         Requires 'jobName': a string representing name of the job
#         Requires 'jobParams': a dictionary where keys represnt job parameter
#             names, and corresponding values the job parameter values.
#         Optional 'jobId': a identier for this job. If not provided a
#             randomly generated alphanumeric string is used.
#         """
# 
#         if (jobId is None):
#             self.jobId = _generateRandomJobId()
#         else :
#             self.jobId = jobId
# 
#         self.jobName = jobName
#         self.jobParams = jobParams
# 
#     def deserializeFromString(self, serializedJob):
#         """
#         Sets this worker job object to the specified serialized string
#         representation.
#         """
# 
#         tempDict = json.loads(serializedJob)
#         jobName = tempDict.pop('jobName', None)
#         jobId = tempDict.pop('jobId', None)
#         self.__init__(jobName, tempDict, jobId)
# 
#     def serializeToString(self):
#         """
#         Serialize to a human-readable string representation of this object
#         """
# 
#         tempDict = dict(self.jobParams)
#         tempDict['jobName'] = self.jobName
#         tempDict['jobId'] = self.jobId
#         return json.dumps(tempDict)
# 
# Path: newsApp/jobManager.py
# class JobManager:
#     """
#     Helper class to enqueue and dequeue jobs to the job queue.
#     """
# 
#     def __init__(self, connectionStringKey):
#         """
#         Instantiates the job manager.
# 
#         'connectionStringKey' : name of environment variable containing the
#         connection string to use.
#         """
# 
#         self.queue = getQueue(os.environ[connectionStringKey])
# 
#     def enqueueJob(self, job):
#         """
#         Enqueue the job into the jobs queue.
#         """
# 
#         enqueueMessage(self.queue, job.serializeToString())
# 
#     def convertDequeuedMessageToJob(self, dequeuedMessage):
#         if dequeuedMessage is None:
#             return None
#         dequeuedJob = WorkerJob(None, None)
#         dequeuedJob.deserializeFromString(dequeuedMessage)
#         return dequeuedJob
# 
#     def dequeueJob(self):
#         """
#         Dequeue a job from the job queue.
#         """
# 
#         dequeuedMessage = dequeueMessage(self.queue)
#         return self.convertDequeuedMessageToJob(dequeuedMessage)
# 
#     def count(self):
#         """
#         Return the count of messages in queue.
#         """
# 
#         return self.queue.count()


import unittest
import time
from newsApp.workerJob import WorkerJob
from newsApp.jobManager import JobManager


class JobManagerTests(unittest.TestCase):

    def __compareJobs(self, job1, job2):
        self.assertTrue(job1.jobId, job2.jobId)
        self.assertTrue(job1.jobName, job2.jobName)
        self.assertTrue(job1.jobParams, job2.jobParams)

    def testEnqueueDequeueJobs(self):

# Path: newsApp/workerJob.py
# class WorkerJob:
#     """
#     Represents a job which can be processed by one of the worker roles.
#     """
# 
#     def __init__(self, jobName, jobParams, jobId = None):
#         """
#         Instantiates a new worker job object.
#         Requires 'jobName': a string representing name of the job
#         Requires 'jobParams': a dictionary where keys represnt job parameter
#             names, and corresponding values the job parameter values.
#         Optional 'jobId': a identier for this job. If not provided a
#             randomly generated alphanumeric string is used.
#         """
# 
#         if (jobId is None):
#             self.jobId = _generateRandomJobId()
#         else :
#             self.jobId = jobId
# 
#         self.jobName = jobName
#         self.jobParams = jobParams
# 
#     def deserializeFromString(self, serializedJob):
#         """
#         Sets this worker job object to the specified serialized string
#         representation.
#         """
# 
#         tempDict = json.loads(serializedJob)
#         jobName = tempDict.pop('jobName', None)
#         jobId = tempDict.pop('jobId', None)
#         self.__init__(jobName, tempDict, jobId)
# 
#     def serializeToString(self):
#         """
#         Serialize to a human-readable string representation of this object
#         """
# 
#         tempDict = dict(self.jobParams)
#         tempDict['jobName'] = self.jobName
#         tempDict['jobId'] = self.jobId
#         return json.dumps(tempDict)
# 
# Path: newsApp/jobManager.py
# class JobManager:
#     """
#     Helper class to enqueue and dequeue jobs to the job queue.
#     """
# 
#     def __init__(self, connectionStringKey):
#         """
#         Instantiates the job manager.
# 
#         'connectionStringKey' : name of environment variable containing the
#         connection string to use.
#         """
# 
#         self.queue = getQueue(os.environ[connectionStringKey])
# 
#     def enqueueJob(self, job):
#         """
#         Enqueue the job into the jobs queue.
#         """
# 
#         enqueueMessage(self.queue, job.serializeToString())
# 
#     def convertDequeuedMessageToJob(self, dequeuedMessage):
#         if dequeuedMessage is None:
#             return None
#         dequeuedJob = WorkerJob(None, None)
#         dequeuedJob.deserializeFromString(dequeuedMessage)
#         return dequeuedJob
# 
#     def dequeueJob(self):
#         """
#         Dequeue a job from the job queue.
#         """
# 
#         dequeuedMessage = dequeueMessage(self.queue)
#         return self.convertDequeuedMessageToJob(dequeuedMessage)
# 
#     def count(self):
#         """
#         Return the count of messages in queue.
#         """
# 
#         return self.queue.count()


# Path: tests/jobManager_test.py
import unittest
import time
from newsApp.workerJob import WorkerJob
from newsApp.jobManager import JobManager



class JobManagerTests(unittest.TestCase):

    def __compareJobs(self, job1, job2):
        self.assertTrue(job1.jobId, job2.jobId)
        self.assertTrue(job1.jobName, job2.jobName)
        self.assertTrue(job1.jobParams, job2.jobParams)

    def testEnqueueDequeueJobs(self):

        testJob1 = WorkerJob(