|
|
|
@ -7,20 +7,21 @@ from knox.models import AuthToken
|
|
|
|
|
|
|
|
|
|
from authentication.models import ExtendedUser
|
|
|
|
|
from files.models import File
|
|
|
|
|
from inventory.models import Event, Container, Item, Comment, ItemPlacement
|
|
|
|
|
from inventory.models import Event, Container, Item, Comment
|
|
|
|
|
|
|
|
|
|
from base64 import b64encode
|
|
|
|
|
|
|
|
|
|
from tickets.models import IssueThread, ItemRelation
|
|
|
|
|
|
|
|
|
|
from base64 import b64encode
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ItemTestCase(TestCase):
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
super().setUp()
|
|
|
|
|
self.event = Event.objects.create(slug='EVENT', name='Event')
|
|
|
|
|
self.box1 = Container.objects.create(name='BOX1')
|
|
|
|
|
self.box2 = Container.objects.create(name='BOX2')
|
|
|
|
|
self.box = Container.objects.create(name='BOX')
|
|
|
|
|
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
|
|
|
|
self.user.user_permissions.add(*Permission.objects.all())
|
|
|
|
|
self.token = AuthToken.objects.create(user=self.user)
|
|
|
|
@ -37,7 +38,7 @@ class ItemTestCase(TestCase):
|
|
|
|
|
|
|
|
|
|
def test_members_and_timeline(self):
|
|
|
|
|
now = datetime.now()
|
|
|
|
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
|
|
|
|
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
|
|
|
|
comment = Comment.objects.create(
|
|
|
|
|
item=item,
|
|
|
|
|
comment="test",
|
|
|
|
@ -45,12 +46,7 @@ class ItemTestCase(TestCase):
|
|
|
|
|
)
|
|
|
|
|
match = ItemRelation.objects.create(
|
|
|
|
|
issue_thread=self.issue,
|
|
|
|
|
item=item,
|
|
|
|
|
timestamp=now + timedelta(seconds=4),
|
|
|
|
|
)
|
|
|
|
|
placement = ItemPlacement.objects.create(
|
|
|
|
|
container=self.box2,
|
|
|
|
|
item=item,
|
|
|
|
|
item = item,
|
|
|
|
|
timestamp=now + timedelta(seconds=5),
|
|
|
|
|
)
|
|
|
|
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
|
|
|
@ -58,34 +54,25 @@ class ItemTestCase(TestCase):
|
|
|
|
|
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'], 'BOX2')
|
|
|
|
|
self.assertEqual(response.json()[0]['cid'], self.box2.id)
|
|
|
|
|
self.assertEqual(response.json()[0]['box'], 'BOX')
|
|
|
|
|
self.assertEqual(response.json()[0]['cid'], self.box.id)
|
|
|
|
|
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']), 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'],
|
|
|
|
|
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'][2]['status'], 'possible')
|
|
|
|
|
self.assertEqual(response.json()[0]['timeline'][2]['timestamp'],
|
|
|
|
|
self.assertEqual(response.json()[0]['timeline'][1]['status'], 'possible')
|
|
|
|
|
self.assertEqual(response.json()[0]['timeline'][1]['timestamp'],
|
|
|
|
|
match.timestamp.strftime('%Y-%m-%dT%H:%M:%S.%fZ'))
|
|
|
|
|
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(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(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")
|
|
|
|
@ -93,15 +80,15 @@ class ItemTestCase(TestCase):
|
|
|
|
|
|
|
|
|
|
def test_members_with_file(self):
|
|
|
|
|
import base64
|
|
|
|
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
|
|
|
|
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
|
|
|
|
file = File.objects.create(item=item, data="data:text/plain;base64," + base64.b64encode(b"foo").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'], 'BOX1')
|
|
|
|
|
self.assertEqual(response.json()[0]['cid'], self.box1.id)
|
|
|
|
|
self.assertEqual(response.json()[0]['box'], 'BOX')
|
|
|
|
|
self.assertEqual(response.json()[0]['cid'], self.box.id)
|
|
|
|
|
self.assertEqual(response.json()[0]['file'], file.hash)
|
|
|
|
|
self.assertEqual(response.json()[0]['returned'], False)
|
|
|
|
|
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
|
|
|
@ -109,38 +96,36 @@ class ItemTestCase(TestCase):
|
|
|
|
|
|
|
|
|
|
def test_members_with_two_file(self):
|
|
|
|
|
import base64
|
|
|
|
|
item = Item.objects.create(container=self.box1, 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'))
|
|
|
|
|
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'], 'BOX1')
|
|
|
|
|
self.assertEqual(response.json()[0]['cid'], self.box1.id)
|
|
|
|
|
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.box1, event=self.event, description='1')
|
|
|
|
|
Item.objects.create(container=self.box1, event=self.event, description='2')
|
|
|
|
|
Item.objects.create(container=self.box1, event=self.event, description='3')
|
|
|
|
|
Item.objects.create(container=self.box, event=self.event, description='1')
|
|
|
|
|
Item.objects.create(container=self.box, event=self.event, description='2')
|
|
|
|
|
Item.objects.create(container=self.box, event=self.event, description='3')
|
|
|
|
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(len(response.json()), 3)
|
|
|
|
|
|
|
|
|
|
def test_create_item(self):
|
|
|
|
|
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'cid': self.box1.id, 'description': '1'})
|
|
|
|
|
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'cid': self.box.id, 'description': '1'})
|
|
|
|
|
self.assertEqual(response.status_code, 201)
|
|
|
|
|
self.assertEqual(response.json()['id'], 1)
|
|
|
|
|
self.assertEqual(response.json()['description'], '1')
|
|
|
|
|
self.assertEqual(response.json()['box'], 'BOX1')
|
|
|
|
|
self.assertEqual(response.json()['cid'], self.box1.id)
|
|
|
|
|
self.assertEqual(response.json()['box'], 'BOX')
|
|
|
|
|
self.assertEqual(response.json()['cid'], self.box.id)
|
|
|
|
|
self.assertEqual(response.json()['file'], None)
|
|
|
|
|
self.assertEqual(response.json()['returned'], False)
|
|
|
|
|
self.assertEqual(response.json()['event'], self.event.slug)
|
|
|
|
@ -148,43 +133,43 @@ class ItemTestCase(TestCase):
|
|
|
|
|
self.assertEqual(len(Item.objects.all()), 1)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].id, 1)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].description, '1')
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].container.id, self.box1.id)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].container.id, self.box.id)
|
|
|
|
|
|
|
|
|
|
def test_create_item_without_container(self):
|
|
|
|
|
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'description': '1'})
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
|
|
def test_create_item_without_description(self):
|
|
|
|
|
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'cid': self.box1.id})
|
|
|
|
|
response = self.client.post(f'/api/2/{self.event.slug}/item/', {'cid': self.box.id})
|
|
|
|
|
self.assertEqual(response.status_code, 400)
|
|
|
|
|
|
|
|
|
|
def test_create_item_with_file(self):
|
|
|
|
|
import base64
|
|
|
|
|
response = self.client.post(f'/api/2/{self.event.slug}/item/',
|
|
|
|
|
{'cid': self.box1.id, 'description': '1',
|
|
|
|
|
{'cid': self.box.id, 'description': '1',
|
|
|
|
|
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode(
|
|
|
|
|
'utf-8')}, content_type='application/json')
|
|
|
|
|
self.assertEqual(response.status_code, 201)
|
|
|
|
|
self.assertEqual(response.json()['id'], 1)
|
|
|
|
|
self.assertEqual(response.json()['description'], '1')
|
|
|
|
|
self.assertEqual(response.json()['box'], 'BOX1')
|
|
|
|
|
self.assertEqual(response.json()['id'], self.box1.id)
|
|
|
|
|
self.assertEqual(response.json()['box'], 'BOX')
|
|
|
|
|
self.assertEqual(response.json()['id'], self.box.id)
|
|
|
|
|
self.assertEqual(len(response.json()['file']), 64)
|
|
|
|
|
self.assertEqual(len(Item.objects.all()), 1)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].id, 1)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].description, '1')
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].container.id, self.box1.id)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].container.id, self.box.id)
|
|
|
|
|
self.assertEqual(len(File.objects.all()), 1)
|
|
|
|
|
|
|
|
|
|
def test_update_item(self):
|
|
|
|
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
|
|
|
|
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
|
|
|
|
response = self.client.patch(f'/api/2/{self.event.slug}/item/{item.id}/', {'description': '2'},
|
|
|
|
|
content_type='application/json')
|
|
|
|
|
content_type='application/json')
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json()['id'], item.id)
|
|
|
|
|
self.assertEqual(response.json()['description'], '2')
|
|
|
|
|
self.assertEqual(response.json()['box'], 'BOX1')
|
|
|
|
|
self.assertEqual(response.json()['cid'], self.box1.id)
|
|
|
|
|
self.assertEqual(response.json()['box'], 'BOX')
|
|
|
|
|
self.assertEqual(response.json()['cid'], self.box.id)
|
|
|
|
|
self.assertEqual(response.json()['file'], None)
|
|
|
|
|
self.assertEqual(response.json()['returned'], False)
|
|
|
|
|
self.assertEqual(response.json()['event'], self.event.slug)
|
|
|
|
@ -192,62 +177,60 @@ class ItemTestCase(TestCase):
|
|
|
|
|
self.assertEqual(len(Item.objects.all()), 1)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].id, 1)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].description, '2')
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].container.id, self.box1.id)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].container.id, self.box.id)
|
|
|
|
|
|
|
|
|
|
def test_update_item_with_file(self):
|
|
|
|
|
import base64
|
|
|
|
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
|
|
|
|
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
|
|
|
|
response = self.client.patch(f'/api/2/{self.event.slug}/item/{item.id}/',
|
|
|
|
|
{'description': '2',
|
|
|
|
|
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode(
|
|
|
|
|
'utf-8')},
|
|
|
|
|
content_type='application/json')
|
|
|
|
|
{'description': '2',
|
|
|
|
|
'dataImage': "data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8')},
|
|
|
|
|
content_type='application/json')
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(response.json()['id'], 1)
|
|
|
|
|
self.assertEqual(response.json()['description'], '2')
|
|
|
|
|
self.assertEqual(response.json()['box'], 'BOX1')
|
|
|
|
|
self.assertEqual(response.json()['id'], self.box1.id)
|
|
|
|
|
self.assertEqual(response.json()['box'], 'BOX')
|
|
|
|
|
self.assertEqual(response.json()['id'], self.box.id)
|
|
|
|
|
self.assertEqual(len(response.json()['file']), 64)
|
|
|
|
|
self.assertEqual(len(Item.objects.all()), 1)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].id, 1)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].description, '2')
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].container.id, self.box1.id)
|
|
|
|
|
self.assertEqual(Item.objects.all()[0].container.id, self.box.id)
|
|
|
|
|
self.assertEqual(len(File.objects.all()), 1)
|
|
|
|
|
|
|
|
|
|
def test_delete_item(self):
|
|
|
|
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
|
|
|
|
Item.objects.create(container=self.box1, event=self.event, description='2')
|
|
|
|
|
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
|
|
|
|
Item.objects.create(container=self.box, event=self.event, description='2')
|
|
|
|
|
self.assertEqual(len(Item.objects.all()), 2)
|
|
|
|
|
response = self.client.delete(f'/api/2/{self.event.slug}/item/{item.id}/')
|
|
|
|
|
self.assertEqual(response.status_code, 204)
|
|
|
|
|
self.assertEqual(len(Item.objects.all()), 1)
|
|
|
|
|
|
|
|
|
|
def test_delete_item2(self):
|
|
|
|
|
Item.objects.create(container=self.box1, event=self.event, description='1')
|
|
|
|
|
item2 = Item.objects.create(container=self.box1, event=self.event, description='2')
|
|
|
|
|
Item.objects.create(container=self.box, event=self.event, description='1')
|
|
|
|
|
item2 = Item.objects.create(container=self.box, event=self.event, description='2')
|
|
|
|
|
self.assertEqual(len(Item.objects.all()), 2)
|
|
|
|
|
response = self.client.delete(f'/api/2/{self.event.slug}/item/{item2.id}/')
|
|
|
|
|
self.assertEqual(response.status_code, 204)
|
|
|
|
|
self.assertEqual(len(Item.objects.all()), 1)
|
|
|
|
|
item3 = Item.objects.create(container=self.box1, event=self.event, description='3')
|
|
|
|
|
item3 = Item.objects.create(container=self.box, event=self.event, description='3')
|
|
|
|
|
self.assertEqual(item3.id, 3)
|
|
|
|
|
self.assertEqual(len(Item.objects.all()), 2)
|
|
|
|
|
|
|
|
|
|
def test_item_count(self):
|
|
|
|
|
Item.objects.create(container=self.box1, event=self.event, description='1')
|
|
|
|
|
Item.objects.create(container=self.box1, event=self.event, description='2')
|
|
|
|
|
Item.objects.create(container=self.box, event=self.event, description='1')
|
|
|
|
|
Item.objects.create(container=self.box, event=self.event, description='2')
|
|
|
|
|
response = self.client.get('/api/2/boxes/')
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(len(response.json()), 2)
|
|
|
|
|
self.assertEqual(len(response.json()), 1)
|
|
|
|
|
self.assertEqual(response.json()[0]['itemCount'], 2)
|
|
|
|
|
self.assertEqual(response.json()[1]['itemCount'], 0)
|
|
|
|
|
|
|
|
|
|
def test_item_nonexistent(self):
|
|
|
|
|
response = self.client.get(f'/api/2/NOEVENT/item/')
|
|
|
|
|
self.assertEqual(response.status_code, 404)
|
|
|
|
|
|
|
|
|
|
def test_item_return(self):
|
|
|
|
|
item = Item.objects.create(container=self.box1, event=self.event, description='1')
|
|
|
|
|
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
|
|
|
|
self.assertEqual(item.returned_at, None)
|
|
|
|
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
@ -262,8 +245,8 @@ class ItemTestCase(TestCase):
|
|
|
|
|
self.assertEqual(len(response.json()), 0)
|
|
|
|
|
|
|
|
|
|
def test_item_show_not_returned(self):
|
|
|
|
|
item1 = Item.objects.create(container=self.box1, event=self.event, description='1')
|
|
|
|
|
item2 = Item.objects.create(container=self.box1, event=self.event, description='2')
|
|
|
|
|
item1 = Item.objects.create(container=self.box, event=self.event, description='1')
|
|
|
|
|
item2 = Item.objects.create(container=self.box, event=self.event, description='2')
|
|
|
|
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
|
|
|
self.assertEqual(len(response.json()), 2)
|
|
|
|
@ -280,15 +263,15 @@ class ItemSearchTestCase(TestCase):
|
|
|
|
|
def setUp(self):
|
|
|
|
|
super().setUp()
|
|
|
|
|
self.event = Event.objects.create(slug='EVENT', name='Event')
|
|
|
|
|
self.box1 = Container.objects.create(name='BOX1')
|
|
|
|
|
self.box = Container.objects.create(name='BOX')
|
|
|
|
|
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
|
|
|
|
self.user.user_permissions.add(*Permission.objects.all())
|
|
|
|
|
self.token = AuthToken.objects.create(user=self.user)
|
|
|
|
|
self.client = Client(headers={'Authorization': 'Token ' + self.token[1]})
|
|
|
|
|
self.item1 = Item.objects.create(container=self.box1, event=self.event, description='abc def')
|
|
|
|
|
self.item2 = Item.objects.create(container=self.box1, event=self.event, description='def ghi')
|
|
|
|
|
self.item3 = Item.objects.create(container=self.box1, event=self.event, description='jkl mno pqr')
|
|
|
|
|
self.item4 = Item.objects.create(container=self.box1, event=self.event, description='stu vwx')
|
|
|
|
|
self.item1 = Item.objects.create(container=self.box, event=self.event, description='abc def')
|
|
|
|
|
self.item2 = Item.objects.create(container=self.box, event=self.event, description='def ghi')
|
|
|
|
|
self.item3 = Item.objects.create(container=self.box, event=self.event, description='jkl mno pqr')
|
|
|
|
|
self.item4 = Item.objects.create(container=self.box, event=self.event, description='stu vwx')
|
|
|
|
|
|
|
|
|
|
def test_search(self):
|
|
|
|
|
search_query = b64encode(b'abc').decode('utf-8')
|
|
|
|
@ -297,8 +280,8 @@ class ItemSearchTestCase(TestCase):
|
|
|
|
|
self.assertEqual(1, len(response.json()))
|
|
|
|
|
self.assertEqual(self.item1.id, response.json()[0]['id'])
|
|
|
|
|
self.assertEqual('abc def', response.json()[0]['description'])
|
|
|
|
|
self.assertEqual('BOX1', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box1.id, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box.id, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual(1, response.json()[0]['search_score'])
|
|
|
|
|
|
|
|
|
|
def test_search2(self):
|
|
|
|
@ -308,13 +291,13 @@ class ItemSearchTestCase(TestCase):
|
|
|
|
|
self.assertEqual(2, len(response.json()))
|
|
|
|
|
self.assertEqual(self.item1.id, response.json()[0]['id'])
|
|
|
|
|
self.assertEqual('abc def', response.json()[0]['description'])
|
|
|
|
|
self.assertEqual('BOX1', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box1.id, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box.id, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual(1, response.json()[0]['search_score'])
|
|
|
|
|
self.assertEqual(self.item2.id, response.json()[1]['id'])
|
|
|
|
|
self.assertEqual('def ghi', response.json()[1]['description'])
|
|
|
|
|
self.assertEqual('BOX1', response.json()[1]['box'])
|
|
|
|
|
self.assertEqual(self.box1.id, response.json()[1]['cid'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[1]['box'])
|
|
|
|
|
self.assertEqual(self.box.id, response.json()[1]['cid'])
|
|
|
|
|
self.assertEqual(1, response.json()[0]['search_score'])
|
|
|
|
|
|
|
|
|
|
def test_search3(self):
|
|
|
|
@ -324,8 +307,8 @@ class ItemSearchTestCase(TestCase):
|
|
|
|
|
self.assertEqual(1, len(response.json()))
|
|
|
|
|
self.assertEqual(self.item3.id, response.json()[0]['id'])
|
|
|
|
|
self.assertEqual('jkl mno pqr', response.json()[0]['description'])
|
|
|
|
|
self.assertEqual('BOX1', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box1.id, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box.id, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual(1, response.json()[0]['search_score'])
|
|
|
|
|
|
|
|
|
|
def test_search4(self):
|
|
|
|
@ -335,11 +318,83 @@ class ItemSearchTestCase(TestCase):
|
|
|
|
|
self.assertEqual(2, len(response.json()))
|
|
|
|
|
self.assertEqual(self.item1.id, response.json()[0]['id'])
|
|
|
|
|
self.assertEqual('abc def', response.json()[0]['description'])
|
|
|
|
|
self.assertEqual('BOX1', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box1.id, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box.id, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual(2, response.json()[0]['search_score'])
|
|
|
|
|
self.assertEqual(self.item2.id, response.json()[1]['id'])
|
|
|
|
|
self.assertEqual('def ghi', response.json()[1]['description'])
|
|
|
|
|
self.assertEqual('BOX1', response.json()[1]['box'])
|
|
|
|
|
self.assertEqual(self.box1.id, response.json()[1]['cid'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[1]['box'])
|
|
|
|
|
self.assertEqual(self.box.id, response.json()[1]['cid'])
|
|
|
|
|
self.assertEqual(1, response.json()[1]['search_score'])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ItemSearchTestCase(TestCase):
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
super().setUp()
|
|
|
|
|
self.event = Event.objects.create(slug='EVENT', name='Event')
|
|
|
|
|
self.box = Container.objects.create(name='BOX')
|
|
|
|
|
self.user = ExtendedUser.objects.create_user('testuser', 'test', 'test')
|
|
|
|
|
self.user.user_permissions.add(*Permission.objects.all())
|
|
|
|
|
self.token = AuthToken.objects.create(user=self.user)
|
|
|
|
|
self.client = Client(headers={'Authorization': 'Token ' + self.token[1]})
|
|
|
|
|
self.item1 = Item.objects.create(container=self.box, event=self.event, description='abc def')
|
|
|
|
|
self.item2 = Item.objects.create(container=self.box, event=self.event, description='def ghi')
|
|
|
|
|
self.item3 = Item.objects.create(container=self.box, event=self.event, description='jkl mno pqr')
|
|
|
|
|
self.item4 = Item.objects.create(container=self.box, event=self.event, description='stu vwx')
|
|
|
|
|
|
|
|
|
|
def test_search(self):
|
|
|
|
|
search_query = b64encode(b'abc').decode('utf-8')
|
|
|
|
|
response = self.client.get(f'/api/2/{self.event.slug}/items/{search_query}/')
|
|
|
|
|
self.assertEqual(200, response.status_code)
|
|
|
|
|
self.assertEqual(1, len(response.json()))
|
|
|
|
|
self.assertEqual(self.item1.uid, response.json()[0]['uid'])
|
|
|
|
|
self.assertEqual('abc def', response.json()[0]['description'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box.cid, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual(1, response.json()[0]['search_score'])
|
|
|
|
|
|
|
|
|
|
def test_search2(self):
|
|
|
|
|
search_query = b64encode(b'def').decode('utf-8')
|
|
|
|
|
response = self.client.get(f'/api/2/{self.event.slug}/items/{search_query}/')
|
|
|
|
|
self.assertEqual(200, response.status_code)
|
|
|
|
|
self.assertEqual(2, len(response.json()))
|
|
|
|
|
self.assertEqual(self.item1.uid, response.json()[0]['uid'])
|
|
|
|
|
self.assertEqual('abc def', response.json()[0]['description'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box.cid, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual(1, response.json()[0]['search_score'])
|
|
|
|
|
self.assertEqual(self.item2.uid, response.json()[1]['uid'])
|
|
|
|
|
self.assertEqual('def ghi', response.json()[1]['description'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[1]['box'])
|
|
|
|
|
self.assertEqual(self.box.cid, response.json()[1]['cid'])
|
|
|
|
|
self.assertEqual(1, response.json()[0]['search_score'])
|
|
|
|
|
|
|
|
|
|
def test_search3(self):
|
|
|
|
|
search_query = b64encode(b'jkl').decode('utf-8')
|
|
|
|
|
response = self.client.get(f'/api/2/{self.event.slug}/items/{search_query}/')
|
|
|
|
|
self.assertEqual(200, response.status_code)
|
|
|
|
|
self.assertEqual(1, len(response.json()))
|
|
|
|
|
self.assertEqual(self.item3.uid, response.json()[0]['uid'])
|
|
|
|
|
self.assertEqual('jkl mno pqr', response.json()[0]['description'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box.cid, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual(1, response.json()[0]['search_score'])
|
|
|
|
|
|
|
|
|
|
def test_search4(self):
|
|
|
|
|
search_query = b64encode(b'abc def').decode('utf-8')
|
|
|
|
|
response = self.client.get(f'/api/2/{self.event.slug}/items/{search_query}/')
|
|
|
|
|
self.assertEqual(200, response.status_code)
|
|
|
|
|
self.assertEqual(2, len(response.json()))
|
|
|
|
|
self.assertEqual(self.item1.uid, response.json()[0]['uid'])
|
|
|
|
|
self.assertEqual('abc def', response.json()[0]['description'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[0]['box'])
|
|
|
|
|
self.assertEqual(self.box.cid, response.json()[0]['cid'])
|
|
|
|
|
self.assertEqual(2, response.json()[0]['search_score'])
|
|
|
|
|
self.assertEqual(self.item2.uid, response.json()[1]['uid'])
|
|
|
|
|
self.assertEqual('def ghi', response.json()[1]['description'])
|
|
|
|
|
self.assertEqual('BOX', response.json()[1]['box'])
|
|
|
|
|
self.assertEqual(self.box.cid, response.json()[1]['cid'])
|
|
|
|
|
self.assertEqual(1, response.json()[1]['search_score'])
|
|
|
|
|
|
|
|
|
|