stash
This commit is contained in:
parent
0eaff2266c
commit
83f1069f84
2 changed files with 41 additions and 0 deletions
24
core/files/migrations/0003_ensure_creation_date.py
Normal file
24
core/files/migrations/0003_ensure_creation_date.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
# Generated by Django 4.2.7 on 2024-11-21 22:40
|
||||
|
||||
from django.db import migrations
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
dependencies = [
|
||||
('files', '0002_alter_file_file'),
|
||||
]
|
||||
|
||||
def set_creation_date(apps, schema_editor):
|
||||
File = apps.get_model('files', 'File')
|
||||
for file in File.objects.all():
|
||||
if file.created_at is None:
|
||||
if not file.item.created_at is None:
|
||||
file.created_at = file.item.created_at
|
||||
else:
|
||||
file.created_at = max(File.objects.filter(
|
||||
id__lt=file.id, created_at__isnull=False).values_list('created_at', flat=True))
|
||||
file.save()
|
||||
|
||||
operations = [
|
||||
migrations.RunPython(set_creation_date),
|
||||
]
|
|
@ -56,6 +56,23 @@ class ItemTestCase(TestCase):
|
|||
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
||||
self.assertEqual(len(response.json()[0]['related_issues']), 0)
|
||||
|
||||
def test_members_with_two_file(self):
|
||||
import base64
|
||||
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||
file1 = File.objects.create(item=item, data="data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8'))
|
||||
file2 = File.objects.create(item=item, data="data:text/plain;base64," + base64.b64encode(b"bar").decode('utf-8'))
|
||||
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertEqual(len(response.json()), 1)
|
||||
self.assertEqual(response.json()[0]['id'], item.id)
|
||||
self.assertEqual(response.json()[0]['description'], '1')
|
||||
self.assertEqual(response.json()[0]['box'], 'BOX')
|
||||
self.assertEqual(response.json()[0]['cid'], self.box.id)
|
||||
self.assertEqual(response.json()[0]['file'], file2.hash)
|
||||
self.assertEqual(response.json()[0]['returned'], False)
|
||||
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
||||
self.assertEqual(len(response.json()[0]['related_issues']), 0)
|
||||
|
||||
def test_multi_members(self):
|
||||
Item.objects.create(container=self.box, event=self.event, description='1')
|
||||
Item.objects.create(container=self.box, event=self.event, description='2')
|
||||
|
|
Loading…
Reference in a new issue