Пример #1
0
    def handle(self, *args, **options):
        # make sure file option is present
        if options['extract_event_number'] is None:
            extract_event_number = 100
        else:
            extract_event_number = int(options['extract_event_number'])

        evt_list = TrackingLog.objects \
                              .filter(tincan_error='WRONG_VERB_OBJECT') \
                              .order_by('dtcreated')[:extract_event_number]
        for evt in evt_list:
            statement_json = json.loads(evt.statement)
            statement = {
                'actor': Agent.from_json(json.dumps(statement_json['actor'])),
                'verb': Verb.from_json(json.dumps(statement_json['verb'])),
                'object': Activity.from_json(json.dumps(statement_json['object'])),
                'timestamp': statement_json['timestamp'],
                'context': Context.from_json(json.dumps(statement_json['context'])),
            }
            evt.statement = json.dumps(statement)
            evt.tincan_error = "CONVERTED"
            evt.save()
Пример #2
0
 def test_FromJSONExceptionPartiallyMalformedJSON(self):
     with self.assertRaises(AttributeError):
         Verb.from_json('{"test": "invalid property", "id": \
         "valid property"}')
Пример #3
0
 def test_FromJSONExceptionBadJSON(self):
     with self.assertRaises(ValueError):
         Verb.from_json('{"bad JSON"}')
Пример #4
0
 def test_ToJSONFromJSON(self):
     json_str = '{"id": "test", "display": {"en-US": "test"}}'
     verb = Verb.from_json(json_str)
     self.assertEqual(verb.id, 'test')
     self.displayVerificationHelper(verb.display)
     self.assertEqual(json.loads(verb.to_json()), json.loads(json_str))
Пример #5
0
 def test_FromJSON(self):
     verb = Verb.from_json('{"id": "test", "display": {"en-US": "test"}}')
     self.assertEqual(verb.id, 'test')
     self.displayVerificationHelper(verb.display)
Пример #6
0
 def test_FromJSONExceptionFlatDisplay(self):
     with self.assertRaises(ValueError):
         Verb.from_json('{"id": "test", "display": "flatdisplay"}')
Пример #7
0
 def test_FromJSONId(self):
     verb = Verb.from_json('{"id": "test"}')
     self.assertEqual(verb.id, 'test')
Пример #8
0
 def test_FromJSONExceptionEmpty(self):
     with self.assertRaises(ValueError):
         Verb.from_json('')
Пример #9
0
 def test_FromJSONExceptionEmptyId(self):
     with self.assertRaises(ValueError):
         Verb.from_json('{"id":"''"}')
Пример #10
0
 def test_FromJSONEmptyObject(self):
     verb = Verb.from_json('{}')
     self.assertIsNone(verb.id)
Пример #11
0
 def test_FromJSONExceptionPartiallyMalformedJSON(self):
     with self.assertRaises(AttributeError):
         Verb.from_json('{"test": "invalid property", "id": \
         "valid property"}')
Пример #12
0
 def test_FromJSONExceptionBadJSON(self):
     with self.assertRaises(ValueError):
         Verb.from_json('{"bad JSON"}')
Пример #13
0
 def test_ToJSONFromJSON(self):
     json_str = '{"id": "test", "display": {"en-US": "test"}}'
     verb = Verb.from_json(json_str)
     self.assertEqual(verb.id, 'test')
     self.displayVerificationHelper(verb.display)
     self.assertEqual(verb.to_json(), json_str)
Пример #14
0
 def test_FromJSON(self):
     verb = Verb.from_json('{"id": "test", "display": {"en-US": "test"}}')
     self.assertEqual(verb.id, 'test')
     self.displayVerificationHelper(verb.display)
Пример #15
0
 def test_FromJSONExceptionFlatDisplay(self):
     with self.assertRaises(ValueError):
         Verb.from_json('{"id": "test", "display": "flatdisplay"}')
Пример #16
0
 def test_FromJSONEmptyObject(self):
     verb = Verb.from_json('{}')
     self.assertIsNone(verb.id)
Пример #17
0
 def test_FromJSONExceptionEmptyId(self):
     with self.assertRaises(ValueError):
         Verb.from_json('{"id":"''"}')
Пример #18
0
 def test_FromJSONExceptionEmpty(self):
     with self.assertRaises(ValueError):
         Verb.from_json('')
Пример #19
0
 def test_FromJSONId(self):
     verb = Verb.from_json('{"id": "test"}')
     self.assertEqual(verb.id, 'test')
Пример #20
0
 def test_FromJSONExceptionMalformedJSON(self):
     with self.assertRaises(AttributeError):
         verb = Verb.from_json('{"test": "invalid property"}')