def test_insertEvent_duplicate(self):
     event1 = models.Event.query.first()
     name=event1.name
     desc=event1.description
     start=event1.startdate
     end=event1.enddate
     orgFK=event1.organizationFK
     
     event2 = models.Event()
     event2.name = name
     event2.description = desc
     event2.startdate = start
     event2.enddate = end
     eventJSON = events.eventToJSON(event2)
     eventDict = json.loads(eventJSON)
     
     result = events.insertEvent(orgFK, eventDict, self.db)
     resultDict = json.loads(result)
     for key,value in resultDict.iteritems():
         if key == 'success':
             self.assertEqual(value, 'false')
         if key == 'msg':
             self.assertEqual(value, 'Duplicate')
         if key == 'event_pk':
             self.assertEqual(value, 'None')
 def test_insertEvent_true(self):
     name='test_insertEvent_true event'
     desc='description of test_insertEvent_true event is indescribable'
     start=datetime.datetime(2013, 7, 12, 12, 0)
     end=datetime.datetime(2013, 7, 14, 16, 0)
     orgFK=1
     
     eventJSON = '{' + '"{key}":"{val}",'.format(key=models.EVENT_NAME_KEY, val=name)
     eventJSON += '"{key}":"{val}",'.format(key=models.EVENT_DESC_KEY, val=desc)
     eventJSON += '"{key}":"{val}",'.format(key=models.EVENT_START_KEY, val=start)
     eventJSON += '"{key}":"{val}"'.format(key=models.EVENT_END_KEY, val=end)
     eventJSON += '}'
     eventDict = json.loads(eventJSON)
     
     result = events.insertEvent(orgFK, eventDict, self.db)
     self.assertIsNotNone(result)
     newKey = 0
     resultDict = json.loads(result)
     for key,value in resultDict.iteritems():
         if key == 'success':
             self.assertEqual(value, 'true')
         if key == models.EVENT_PK_KEY:
             self.assertTrue(value > 0)
             newKey = value
     
     newEvent = models.Event.query.filter_by(pk=newKey).first()
     self.assertEqual(newEvent.pk, newKey)
     self.assertEqual(newEvent.name, name)
     self.assertEqual(newEvent.description, desc)
     self.assertEqual(newEvent.startdate, start)
     self.assertEqual(newEvent.enddate, end)
     self.assertEqual(newEvent.organizationFK, orgFK)
 def test_insertEvent_badorg(self):
     name='test_insertEvent_badorg event'
     desc='description of test_insertEvent_badorg event is indescribable'
     start=datetime.datetime(2013, 7, 12, 12, 0)
     end=datetime.datetime(2013, 7, 14, 16, 0)
     orgFK=99999
     
     eventJSON = '{' + '"{key}":"{val}",'.format(key=models.EVENT_NAME_KEY, val=name)
     eventJSON += '"{key}":"{val}",'.format(key=models.EVENT_DESC_KEY, val=desc)
     eventJSON += '"{key}":"{val}",'.format(key=models.EVENT_START_KEY, val=start)
     eventJSON += '"{key}":"{val}"'.format(key=models.EVENT_END_KEY, val=end)
     eventJSON += '}'
     eventDict = json.loads(eventJSON)
     
     result = events.insertEvent(orgFK, eventDict, self.db)
     resultDict = json.loads(result)
     for key,value in resultDict.iteritems():
         if key == 'success':
             self.assertEqual(value, 'false')
         if key == 'msg':
             self.assertEqual(value, 'BadOrg')
         elif key == 'event_pk':
             self.assertEqual(value, 'None')        
Exemplo n.º 4
0
def createEventForOrg(org_id):
    try:
        result = controller_events.insertEvent(org_id, request.json, db)
        return Response(response=result, mimetype='application/json')
    except Exception, e:
        return abort(404)