diff --git a/core/inventory/serializers.py b/core/inventory/serializers.py index 79caddd..f13235c 100644 --- a/core/inventory/serializers.py +++ b/core/inventory/serializers.py @@ -105,6 +105,14 @@ class ItemSerializer(BasicItemSerializer): 'timestamp': relation.timestamp, 'issue_thread': BasicIssueSerializer(relation.issue_thread).data, }) + for placement in (obj.container_history.all()): + timeline.append({ + 'type': 'placement', + 'id': placement.id, + 'timestamp': placement.timestamp, + 'cid': placement.container.id, + 'box': placement.container.name + }) return sorted(timeline, key=lambda x: x['timestamp']) diff --git a/core/inventory/tests/v2/test_items.py b/core/inventory/tests/v2/test_items.py index 375f257..0c85eb4 100644 --- a/core/inventory/tests/v2/test_items.py +++ b/core/inventory/tests/v2/test_items.py @@ -63,20 +63,29 @@ class ItemTestCase(TestCase): self.assertEqual(response.json()[0]['file'], None) self.assertEqual(response.json()[0]['returned'], False) self.assertEqual(response.json()[0]['event'], self.event.slug) - self.assertEqual(len(response.json()[0]['timeline']), 2) - self.assertEqual(response.json()[0]['timeline'][0]['type'], 'comment') - self.assertEqual(response.json()[0]['timeline'][1]['type'], 'issue_relation') - self.assertEqual(response.json()[0]['timeline'][0]['id'], comment.id) - self.assertEqual(response.json()[0]['timeline'][1]['id'], match.id) - self.assertEqual(response.json()[0]['timeline'][0]['comment'], 'test') - self.assertEqual(response.json()[0]['timeline'][0]['timestamp'], - comment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) - self.assertEqual(response.json()[0]['timeline'][1]['status'], 'possible') + self.assertEqual(len(response.json()[0]['timeline']), 4) + self.assertEqual(response.json()[0]['timeline'][0]['type'], 'placement') + self.assertEqual(response.json()[0]['timeline'][1]['type'], 'comment') + self.assertEqual(response.json()[0]['timeline'][2]['type'], 'issue_relation') + self.assertEqual(response.json()[0]['timeline'][3]['type'], 'placement') + self.assertEqual(response.json()[0]['timeline'][1]['id'], comment.id) + self.assertEqual(response.json()[0]['timeline'][2]['id'], match.id) + self.assertEqual(response.json()[0]['timeline'][3]['id'], placement.id) + self.assertEqual(response.json()[0]['timeline'][0]['box'], 'BOX1') + self.assertEqual(response.json()[0]['timeline'][0]['cid'], self.box1.id) + self.assertEqual(response.json()[0]['timeline'][1]['comment'], 'test') self.assertEqual(response.json()[0]['timeline'][1]['timestamp'], + comment.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) + self.assertEqual(response.json()[0]['timeline'][2]['status'], 'possible') + self.assertEqual(response.json()[0]['timeline'][2]['timestamp'], match.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) - self.assertEqual(response.json()[0]['timeline'][1]['issue_thread']['name'], "test issue") - self.assertEqual(response.json()[0]['timeline'][1]['issue_thread']['event'], "EVENT") - self.assertEqual(response.json()[0]['timeline'][1]['issue_thread']['state'], "pending_new") + self.assertEqual(response.json()[0]['timeline'][2]['issue_thread']['name'], "test issue") + self.assertEqual(response.json()[0]['timeline'][2]['issue_thread']['event'], "EVENT") + self.assertEqual(response.json()[0]['timeline'][2]['issue_thread']['state'], "pending_new") + self.assertEqual(response.json()[0]['timeline'][3]['box'], 'BOX2') + self.assertEqual(response.json()[0]['timeline'][3]['cid'], self.box2.id) + self.assertEqual(response.json()[0]['timeline'][3]['timestamp'], + placement.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ')) self.assertEqual(len(response.json()[0]['related_issues']), 1) self.assertEqual(response.json()[0]['related_issues'][0]['name'], "test issue") self.assertEqual(response.json()[0]['related_issues'][0]['event'], "EVENT")