return connected_files inside /inventory_items endpoint
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
e819700bb0
commit
e447f389d8
2 changed files with 20 additions and 1 deletions
|
@ -69,11 +69,12 @@ class InventoryItemSerializer(serializers.ModelSerializer):
|
||||||
tags = serializers.SlugRelatedField(many=True, required=False, queryset=Tag.objects.all(), slug_field='name')
|
tags = serializers.SlugRelatedField(many=True, required=False, queryset=Tag.objects.all(), slug_field='name')
|
||||||
properties = ItemPropertySerializer(many=True, required=False, source='itemproperty_set')
|
properties = ItemPropertySerializer(many=True, required=False, source='itemproperty_set')
|
||||||
category = CategorySerializer(required=False, allow_null=True)
|
category = CategorySerializer(required=False, allow_null=True)
|
||||||
|
files = FileSerializer(many=True, read_only=True)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = InventoryItem
|
model = InventoryItem
|
||||||
fields = ['id', 'name', 'description', 'owner', 'category', 'availability_policy', 'owned_quantity', 'owner',
|
fields = ['id', 'name', 'description', 'owner', 'category', 'availability_policy', 'owned_quantity', 'owner',
|
||||||
'tags', 'properties']
|
'tags', 'properties', 'files']
|
||||||
|
|
||||||
def to_internal_value(self, data):
|
def to_internal_value(self, data):
|
||||||
files = data.pop('files', [])
|
files = data.pop('files', [])
|
||||||
|
|
|
@ -138,3 +138,21 @@ class FileApiTestCase(UserTestMixin, FilesTestMixin, InventoryTestMixin, Toolshe
|
||||||
self.assertEqual(response.status_code, 403)
|
self.assertEqual(response.status_code, 403)
|
||||||
self.assertEqual(File.objects.count(), 3)
|
self.assertEqual(File.objects.count(), 3)
|
||||||
self.assertEqual(self.f['item1'].files.count(), 2)
|
self.assertEqual(self.f['item1'].files.count(), 2)
|
||||||
|
|
||||||
|
def test_get_inventory(self):
|
||||||
|
reply = client.get('/api/inventory_items/', self.f['local_user1'])
|
||||||
|
self.assertEqual(reply.status_code, 200)
|
||||||
|
self.assertEqual(len(reply.json()), 2)
|
||||||
|
self.assertEqual(reply.json()[0]['name'], 'test1')
|
||||||
|
self.assertEqual(reply.json()[1]['name'], 'test2')
|
||||||
|
self.assertEqual(len(reply.json()[0]['files']), 2)
|
||||||
|
self.assertEqual(len(reply.json()[1]['files']), 1)
|
||||||
|
self.assertEqual(reply.json()[0]['files'][0]['name'],
|
||||||
|
f"/media/{self.f['hash1'][:2]}/{self.f['hash1'][2:4]}/{self.f['hash1'][4:6]}/{self.f['hash1'][6:]}")
|
||||||
|
self.assertEqual(reply.json()[0]['files'][1]['name'],
|
||||||
|
f"/media/{self.f['hash2'][:2]}/{self.f['hash2'][2:4]}/{self.f['hash2'][4:6]}/{self.f['hash2'][6:]}")
|
||||||
|
self.assertEqual(reply.json()[1]['files'][0]['name'],
|
||||||
|
f"/media/{self.f['hash1'][:2]}/{self.f['hash1'][2:4]}/{self.f['hash1'][4:6]}/{self.f['hash1'][6:]}")
|
||||||
|
self.assertEqual(reply.json()[0]['files'][0]['mime_type'], 'text/plain')
|
||||||
|
self.assertEqual(reply.json()[0]['files'][1]['mime_type'], 'text/plain')
|
||||||
|
self.assertEqual(reply.json()[1]['files'][0]['mime_type'], 'text/plain')
|
||||||
|
|
Loading…
Reference in a new issue