def test_patch_hostname(self, client: MDMClient, session): """Patching the hostname should enqueue a Rename MDM command.""" request_json = json.dumps({ "data": { "type": "devices", "id": "1", "attributes": { "hostname": "new name" } }, "jsonapi": { "version": "1.0" } }) response: Response = client.patch( "/api/v1/devices/1", data=request_json, content_type="application/vnd.api+json") assert response.status_code == 200 try: cmd: Command = session.query(Command).filter( Command.request_type == 'Settings').one() except sqlalchemy.orm.exc.NoResultFound: assert False, "The API has created a new Settings Command to send to the device" device = json.loads(response.data) assert device['data']['attributes'][ 'hostname'] != "new name", "Device rename is still pending, API should reflect old name"
def test_patch_device_name_reverted(self, client: MDMClient, session): """Patching the device name twice (change, then back to its original name) should remove the queued Settings command.""" request_json = json.dumps({ "data": { "type": "devices", "id": "1", "attributes": { "device_name": "new name" } }, "jsonapi": { "version": "1.0" } }) request_two_json = json.dumps({ "data": { "type": "devices", "id": "1", "attributes": { "device_name": "commandment-mdmclient" } }, "jsonapi": { "version": "1.0" } }) response: Response = client.patch( "/api/v1/devices/1", data=request_json, content_type="application/vnd.api+json") assert response.status_code == 200 second_response: Response = client.patch( "/api/v1/devices/1", data=request_two_json, content_type="application/vnd.api+json") assert second_response.status_code == 200 settings_commands = session.query(Command).filter( Command.request_type == 'Settings').count() assert settings_commands == 1
def test_post_dep_profile_relationship(self, client: MDMClient, session): """Test assignment of DEP Profile to device via relationship URL: /api/v1/devices/<device_id>/relationships/dep_profiles""" request_json = json.dumps({ "data": { "type": "dep_profiles", "id": "1", }, "jsonapi": { "version": "1.0" } }) response: Response = client.patch( "/api/v1/devices/1/relationships/dep_profile", data=request_json, content_type="application/vnd.api+json") print(response.data) assert response.status_code == 200 d: Device = session.query(Device).filter(Device.id == 1).one() assert d.dep_profile_id is not None