add tests
This commit is contained in:
parent
6b173de5a8
commit
ce09de4133
|
@ -86,12 +86,18 @@ DEVICES = {
|
||||||
"Smartphone",
|
"Smartphone",
|
||||||
"Cellphone",
|
"Cellphone",
|
||||||
],
|
],
|
||||||
|
"Drives & Storage": [
|
||||||
|
"All DataStorage",
|
||||||
|
"HardDrives",
|
||||||
|
"SolidStageDrive",
|
||||||
|
],
|
||||||
}
|
}
|
||||||
|
|
||||||
COMPUTERS = ['Desktop', 'Laptop', 'Server', 'Computer']
|
COMPUTERS = ['Desktop', 'Laptop', 'Server', 'Computer']
|
||||||
|
|
||||||
MONITORS = ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"]
|
MONITORS = ["ComputerMonitor", "Monitor", "TelevisionSet", "Projector"]
|
||||||
MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"]
|
MOBILE = ["Mobile", "Tablet", "Smartphone", "Cellphone"]
|
||||||
|
STORAGE = ["HardDrive", "SolidStateDrive"]
|
||||||
|
|
||||||
|
|
||||||
class AdvancedSearchForm(FlaskForm):
|
class AdvancedSearchForm(FlaskForm):
|
||||||
|
@ -175,9 +181,16 @@ class FilterForm(FlaskForm):
|
||||||
elif "All Mobile" == self.device_type:
|
elif "All Mobile" == self.device_type:
|
||||||
filter_type = MOBILE
|
filter_type = MOBILE
|
||||||
|
|
||||||
|
elif "All DataStorage" == self.device_type:
|
||||||
|
filter_type = STORAGE
|
||||||
|
|
||||||
if filter_type:
|
if filter_type:
|
||||||
self.devices = self.devices.filter(Device.type.in_(filter_type))
|
self.devices = self.devices.filter(Device.type.in_(filter_type))
|
||||||
|
|
||||||
|
# if self.device_type in STORAGE + ["All DataStorage"]:
|
||||||
|
# import pdb; pdb.set_trace()
|
||||||
|
# self.devices = self.devices.filter(Component.parent_id.is_(None))
|
||||||
|
|
||||||
return self.devices.order_by(Device.updated.desc())
|
return self.devices.order_by(Device.updated.desc())
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -357,6 +357,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
{% for dev in devices %}
|
{% for dev in devices %}
|
||||||
|
{% if not dev.parent_id or dev.parent.placeholder.kangaroo %}
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<input type="checkbox" class="deviceSelect" data="{{ dev.id }}"
|
<input type="checkbox" class="deviceSelect" data="{{ dev.id }}"
|
||||||
|
@ -410,6 +411,7 @@
|
||||||
</a>
|
</a>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% endif %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
|
@ -105,6 +105,7 @@ def test_api_docs(client: Client):
|
||||||
'/users/logout/',
|
'/users/logout/',
|
||||||
'/versions/',
|
'/versions/',
|
||||||
'/workbench/',
|
'/workbench/',
|
||||||
|
'/workbench/erasure_host/{id}/',
|
||||||
}
|
}
|
||||||
assert docs['info'] == {'title': 'Devicehub', 'version': '0.2'}
|
assert docs['info'] == {'title': 'Devicehub', 'version': '0.2'}
|
||||||
assert docs['components']['securitySchemes']['bearerAuth'] == {
|
assert docs['components']['securitySchemes']['bearerAuth'] == {
|
||||||
|
|
|
@ -2438,3 +2438,99 @@ def test_bug_3831_documents(user3: UserClientFlask):
|
||||||
uri = f'/inventory/lot/{lot_id}/trade-document/add/'
|
uri = f'/inventory/lot/{lot_id}/trade-document/add/'
|
||||||
# body, status = user3.post(uri, data=data, content_type="multipart/form-data")
|
# body, status = user3.post(uri, data=data, content_type="multipart/form-data")
|
||||||
# assert status == '200 OK'
|
# assert status == '200 OK'
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.mvp
|
||||||
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||||
|
def test_hdd_filter(user3: UserClientFlask):
|
||||||
|
create_device(user3, 'real-eee-1001pxd.snapshot.12.json')
|
||||||
|
|
||||||
|
hdds = Device.query.filter_by(type='HardDrive').all()
|
||||||
|
for hdd in hdds:
|
||||||
|
hdd.parent = None
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
csrf = generate_csrf()
|
||||||
|
uri = f'/inventory/device/?filter=All+DataStorage&csrf_token={csrf}'
|
||||||
|
body, status = user3.get(uri)
|
||||||
|
|
||||||
|
assert status == '200 OK'
|
||||||
|
for hdd in hdds:
|
||||||
|
assert hdd.dhid in body
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.mvp
|
||||||
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||||
|
def test_add_kangaroo(user3: UserClientFlask):
|
||||||
|
create_device(user3, 'real-eee-1001pxd.snapshot.12.json')
|
||||||
|
|
||||||
|
body, status = user3.get('/workbench/')
|
||||||
|
|
||||||
|
assert status == '200 OK'
|
||||||
|
|
||||||
|
pc = Device.query.filter_by(type='Laptop').first()
|
||||||
|
data = {
|
||||||
|
'csrf_token': generate_csrf(),
|
||||||
|
'phid': pc.phid(),
|
||||||
|
}
|
||||||
|
|
||||||
|
body, status = user3.post('/workbench/', data=data)
|
||||||
|
assert status == '200 OK'
|
||||||
|
assert pc.phid() in body
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.mvp
|
||||||
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||||
|
def test_drop_kangaroo(user3: UserClientFlask):
|
||||||
|
create_device(user3, 'real-eee-1001pxd.snapshot.12.json')
|
||||||
|
pc = Device.query.filter_by(type='Laptop').first()
|
||||||
|
phid = 'AAA'
|
||||||
|
pc.placeholder.phid = phid
|
||||||
|
db.session.commit()
|
||||||
|
|
||||||
|
body, status = user3.get('/workbench/')
|
||||||
|
assert phid not in body
|
||||||
|
|
||||||
|
data = {
|
||||||
|
'csrf_token': generate_csrf(),
|
||||||
|
'phid': phid,
|
||||||
|
}
|
||||||
|
|
||||||
|
body, status = user3.post('/workbench/', data=data)
|
||||||
|
assert status == '200 OK'
|
||||||
|
assert phid in body
|
||||||
|
|
||||||
|
placeholder_id = pc.placeholder.id
|
||||||
|
uri = f'/workbench/erasure_host/{placeholder_id}/'
|
||||||
|
body, status = user3.get(uri)
|
||||||
|
assert status == '200 OK'
|
||||||
|
assert phid not in body
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.mvp
|
||||||
|
@pytest.mark.usefixtures(conftest.app_context.__name__)
|
||||||
|
def test_filter_hdd_in_kangaroo(user3: UserClientFlask):
|
||||||
|
create_device(user3, 'real-eee-1001pxd.snapshot.12.json')
|
||||||
|
csrf = generate_csrf()
|
||||||
|
uri = f'/inventory/device/?filter=All+DataStorage&csrf_token={csrf}'
|
||||||
|
body, status = user3.get(uri)
|
||||||
|
|
||||||
|
assert status == '200 OK'
|
||||||
|
for hdd in Device.query.filter_by(type='HardDrive').all():
|
||||||
|
assert hdd.dhid not in body
|
||||||
|
|
||||||
|
user3.get('/workbench/')
|
||||||
|
pc = Device.query.filter_by(type='Laptop').first()
|
||||||
|
data = {
|
||||||
|
'csrf_token': generate_csrf(),
|
||||||
|
'phid': pc.phid(),
|
||||||
|
}
|
||||||
|
user3.post('/workbench/', data=data)
|
||||||
|
|
||||||
|
csrf = generate_csrf()
|
||||||
|
uri = f'/inventory/device/?filter=All+DataStorage&csrf_token={csrf}'
|
||||||
|
body, status = user3.get(uri)
|
||||||
|
|
||||||
|
assert status == '200 OK'
|
||||||
|
for hdd in Device.query.filter_by(type='HardDrive').all():
|
||||||
|
assert hdd.dhid in body
|
||||||
|
|
Reference in New Issue