Beispiel #1
0
 def testCreateEntryWithAttachments(self):
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(testLogbook);
     text = 'test python log entry with attachments ' + datetime.now().isoformat(' ')
     testImageAttachment = Attachment(open('Desert.jpg', 'rb'))
     testTextAttachment = Attachment(open('debug.log', 'rb'))
     testLog = LogEntry(text=text,
                        owner='testOwner',
                        logbooks=[testLogbook],
                        attachments=[testImageAttachment, testTextAttachment]
                        )
     client.log(testLog)
     logEntries = client.find(search=text)
     self.assertEqual(len(logEntries), 1, 'Failed to create log entry with attachment')
     attachments = client.listAttachments(logEntryId=logEntries[0].getId())
     self.assertEqual(len(attachments), 2, 'Failed to create log entry with attachment');
     for attachment in attachments:
         if attachment.getFile().name.endswith('.log'):
             print attachment.getFile().readline()
             print attachment.getFile().fileno(), open('debug.log', 'rb').fileno()      
     client.delete(logEntryId=logEntries[0].getId()) 
     self.assertEqual(len(client.find(search=text)), 0, 'Failed to cleanup log entry with attachment')      
     client.delete(logbookName=testLogbook.getName())
     self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the testLogbook')
     pass
 def createTextEntry():
     lb = Logbook(name='CODAC')
     print('Creating a text entry in the logbook ' + lb.getName())
     text = 'This is a demo python log entry created on ' + datetime.now().isoformat(' ')
     '''owner doesn't play any role here but it is required'''
     testLog = LogEntry(text=text, owner='owner', logbooks=[lb])
     client.log(logEntry=testLog)
Beispiel #3
0
 def createTextEntry():
     lb = Logbook(name='CODAC')
     print('Creating a text entry in the logbook ' + lb.getName())
     text = 'This is a demo python log entry created on ' + datetime.now(
     ).isoformat(' ')
     '''owner doesn't play any role here but it is required'''
     testLog = LogEntry(text=text, owner='owner', logbooks=[lb])
     client.log(logEntry=testLog)
 def createEntryWithAttachment():
     lb = Logbook(name='CODAC')
     print('Creating a text entry with an attached image in the logbook ' + lb.getName())
     text = 'This is a demo python log entry  wtih image attachment created on ' + datetime.now().isoformat(' ')
     pp = os.path.dirname(os.path.abspath(__file__))
     path = os.path.relpath('Desert.png', pp)
     image = Attachment(open(path,'rb'))
     testLog = LogEntry(text=text, owner='owner', logbooks=[lb], attachments=[image])
     client.log(logEntry=testLog)
    def updateLogEntry():
        lb = Logbook(name='CODAC')
        print('Creating a log entry which will be updated in logbook ' + lb.getName())
        text = 'This is a demo python log entry which will be updated, created on ' + datetime.now().isoformat(' ')
        testLog = LogEntry(text=text, owner='owner', logbooks=[lb])
        log = client.log(logEntry=testLog)

        textupdate = '<br>And this is update text to python log entry ' + datetime.now().isoformat(' ')
        updatedLogEntry = LogEntry(text=text + textupdate, owner='owner', logbooks=[lb])
        updatedLog = client.update(log.getId(), updatedLogEntry)
        logEntries = client.find(search=text)
Beispiel #6
0
 def createEntryWithTags():
     lb = Logbook(name='CODAC')
     tags = client.listTags()
     print('Creating a text entry with a tag ' + tags[0].getName() +
           ' in the logbook ' + lb.getName())
     text = 'This is a demo python log entry created on ' + datetime.now(
     ).isoformat(' ')
     testLog = LogEntry(text=text,
                        owner='owner',
                        logbooks=[lb],
                        tags=[tags[0]])
     client.log(logEntry=testLog)
Beispiel #7
0
 def createEntryWithAttachment():
     lb = Logbook(name='CODAC')
     print('Creating a text entry with an attached image in the logbook ' +
           lb.getName())
     text = 'This is a demo python log entry  wtih image attachment created on ' + datetime.now(
     ).isoformat(' ')
     pp = os.path.dirname(os.path.abspath(__file__))
     path = os.path.relpath('Desert.png', pp)
     image = Attachment(open(path, 'rb'))
     testLog = LogEntry(text=text,
                        owner='owner',
                        logbooks=[lb],
                        attachments=[image])
     client.log(logEntry=testLog)
Beispiel #8
0
 def testCmp(self):
     tags = [ Tag(name='Timing'), Tag(name='Magnets') ]
     logbooks = [ Logbook(name='experiment', owner='controls') ]
     logEntry1 = LogEntry(text='Turning on LINAC', owner='controls', logbooks=logbooks, tags=tags, id=1234)
     logEntry2 = LogEntry(text='Turning on LINAC', owner='controls', logbooks=logbooks, tags=tags, id=1234)
     self.assertEqual(logEntry1, logEntry2, 'Failed LogEntry equality')
     self.assertIn(logEntry1, [logEntry2])
Beispiel #9
0
 def setUpClass(cls):
     cls.client = client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     cls.text = 'test python log entry with attachment ' + datetime.now().isoformat(' ')
     cls.testAttachment = Attachment(open('debug.log', 'rb'))
     cls.testLogbook = Logbook(name='testLogbook', owner='testOwner')
     cls.client.createLogbook(cls.testLogbook);
     cls.testTag = Tag(name='testTag') 
     cls.client.createTag(cls.testTag)               
     cls.testProperty = Property(name='testLogProperty', attributes={'id':'testSearchId', 'url':'www.bnl.gov'})
     cls.client.createProperty(cls.testProperty)
     cls.t1 = str(time.time()).split('.')[0]
     client.log(LogEntry(text=cls.text,
                        owner='testOwner',
                        logbooks=[cls.testLogbook],
                        tags=[cls.testTag],
                        attachments=[cls.testAttachment],
                        properties=[cls.testProperty]))
     cls.t2 = str(time.time()).split('.')[0]
     client.log(LogEntry(text=cls.text + ' - entry2',
                        owner='testOwner',
                        logbooks=[cls.testLogbook]))
     cls.t3 = str(time.time()).split('.')[0]
     cls.testLogEntry1 = client.find(search=cls.text)[0]
     cls.testLogEntry2 = client.find(search=cls.text + ' - entry2')[0]
     pass
 def createEntryWithTags():
     lb = Logbook(name='CODAC')
     tags = client.listTags()
     print('Creating a text entry with a tag ' + tags[0].getName() + ' in the logbook ' + lb.getName())
     text = 'This is a demo python log entry created on ' + datetime.now().isoformat(' ')
     testLog = LogEntry(text=text, owner='owner', logbooks=[lb], tags=[tags[0]])
     client.log(logEntry=testLog)
Beispiel #11
0
    def updateLogEntry():
        lb = Logbook(name='CODAC')
        print('Creating a log entry which will be updated in logbook ' +
              lb.getName())
        text = 'This is a demo python log entry which will be updated, created on ' + datetime.now(
        ).isoformat(' ')
        testLog = LogEntry(text=text, owner='owner', logbooks=[lb])
        log = client.log(logEntry=testLog)

        textupdate = '<br>And this is update text to python log entry ' + datetime.now(
        ).isoformat(' ')
        updatedLogEntry = LogEntry(text=text + textupdate,
                                   owner='owner',
                                   logbooks=[lb])
        updatedLog = client.update(log.getId(), updatedLogEntry)
        logEntries = client.find(search=text)
Beispiel #12
0
 def testCreateLogbook(self):
     '''
     Basic operations of creating, listing and deleting a Logbook object
     '''
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(testLogbook)
     self.assertTrue(testLogbook in client.listLogbooks(), 'failed to create the testLogbook')
     client.delete(logbookName='testLogbook')
     self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the testLogbook')
Beispiel #13
0
    def testCreateLog(self):
        '''
        '''
        tags = [ Tag(name='Timing'), Tag(name='Magnets') ]
        logbooks = [ Logbook(name='experiment', owner='controls') ]
        logEntry = LogEntry(text='Turning on LINAC', owner='controls', logbooks=logbooks, tags=tags)
        self.assertEqual(logEntry.getText(), 'Turning on LINAC', 'msg')
        self.assertEqual(logEntry.getOwner(), 'controls', 'msg')
        self.assertEqual(logEntry.getTags(), tags, 'msg')
#        self.assertTrue(logEntry.hasTag('Timing'), 'msg')
        self.assertEqual(logEntry.getLogbooks(), logbooks, 'msg')
#        self.assertTrue(logEntry.hasLogbook('experiment'), 'msg')
        pass
Beispiel #14
0
 def testCreateEntryWithTag(self):
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(testLogbook);
     testTag = Tag(name='testTag')
     client.createTag(testTag)        
     text = 'test python log entry with tag ' + datetime.now().isoformat(' ')
     testLog = LogEntry(text=text,
                        owner='testOwner',
                        logbooks=[testLogbook],
                        tags=[testTag])
     client.log(testLog)
     logEntries = client.find(search=testLog.getText())
     self.assertTrue(len(logEntries) == 1, 'Failed to create log Entry with Tag')
     self.assertTrue(testTag in logEntries[0].getTags(), 'testTag not attached to the testLogEntry1')
     '''cleanup'''
     client.delete(logEntryId=logEntries[0].getId())
     self.assertTrue(len(client.find(search=testLog.getText())) == 0, 'Failed to delete log Entry with Tag')
     client.delete(logbookName=testLogbook.getName())
     self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the testLogbook')
     client.delete(tagName=testTag.getName())
     self.assertTrue(testTag not in client.listTags(), 'failed to cleanup the testTag')
     pass
Beispiel #15
0
    def testCreateEntryWithProperties(self):
        client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
        testLogbook = Logbook(name='testLogbook', owner='testOwner')
        client.createLogbook(testLogbook);
        testProperty = Property(name='testLogProperty', attributes={'id':None, 'url':None})
#        client.createProperty(testProperty)
        text = 'test python log entry with attachment ' + datetime.now().isoformat(' ')
        property = Property(name='testLogProperty', attributes={'id':'prop1234', 'url':'www.bnl.gov'})
        testLog = LogEntry(text=text,
                           owner='testOwner',
                           logbooks=[testLogbook],
                           properties=[property]
                           )
        client.log(testLog)
        logEntries = client.find(search=text)
        self.assertEqual(len(logEntries), 1, 'Failed to create log entry with property')
        properties = logEntries[0].getProperties()
        self.assertIn(property, properties, 'TestLogEntry does not contain property ' + property.getName())
        '''Cleanup'''
        client.delete(logEntryId=logEntries[0].getId()) 
        self.assertEqual(len(client.find(search=text)), 0, 'Failed to cleanup log entry with property') 
        client.delete(logbookName=testLogbook.getName())
        self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the ' + testLogbook.getName())
        pass
Beispiel #16
0
 def testCreateBasicEntry(self):
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(testLogbook)
     text = 'test python log entry ' + datetime.now().isoformat(' ')
     testLog = LogEntry(text=text,
                        owner='testOwner',
                        logbooks=[testLogbook])
     client.log(logEntry=testLog)
     logEntries = client.find(search=testLog.getText())
     self.assertTrue(len(logEntries) == 1, 'Failed to create test log entry')
     client.delete(logEntryId=logEntries[0].getId())
     self.assertTrue(len(client.find(search=testLog.getText())) == 0, 'Failed to delete test log entry')
     client.delete(logbookName='testLogbook')
     self.assertTrue(testLogbook not in client.listLogbooks(), 'failed to cleanup the testLogbook')
     pass
Beispiel #17
0
 def testCreateLogbook(self):
     '''
     A Logbook consists of a name(required) and an owner(required)
     '''
     logbook = Logbook(name='logbookName', owner='logbookOwner')
     self.assertEqual(logbook.getName(), 'logbookName', 'Failed to create logbook')
     self.assertEqual(logbook.getOwner(), 'logbookOwner', 'Failed to create logbook')
     '''Check equality which is based on name and owner'''
     logbookA = Logbook(name='testName', owner='logbookOwner')
     logbookB = Logbook(name='testName', owner='logbookOwner')
     self.assertEqual(logbookA, logbookB, 'Failed equality condition')
     pass
Beispiel #18
0
 def setUpClass(cls):
     client = OlogClient(url=getDefaultTestConfig('url'), username=getDefaultTestConfig('username'), password=getDefaultTestConfig('password'))
     cls.testLogbook = Logbook(name='testLogbook', owner='testOwner')
     client.createLogbook(cls.testLogbook)
     pass