def test_add_item_cloned(): tarallo_session = Tarallo(t_url, t_token) cpu = tarallo_session.get_item("C100TEST") assert cpu is not None cpu_to_upload = ItemToUpload(cpu) assert cpu.code == cpu_to_upload.code assert cpu.location[-1] == cpu_to_upload.parent assert len(cpu.features) == len(cpu_to_upload.features) # It comes from a computer, path will still contain that, I don't care: I want it on the Table. # Send this location to the server, not the path. cpu_to_upload.set_parent("Table") assert cpu.location[-1] != cpu_to_upload.parent # Let the server generate another code (since there's no way to delete items permanently we # can't test manually assigned codes... or rather we can, but just once) cpu_to_upload.set_code(None) assert cpu.code != cpu_to_upload.code # Add it: should succeed assert tarallo_session.add_item(cpu_to_upload) # Let's get the entire item again and check... # The generated code was added to the original dict cpu_cloned = tarallo_session.get_item(cpu_to_upload.code) assert cpu_cloned.code != cpu.code assert cpu_cloned.location[-1] == cpu_to_upload.parent assert len(cpu_cloned.features) == len(cpu_to_upload.features)
def test_add_item_cloned(): tarallo_session = Tarallo(t_url, t_token) cpu = tarallo_session.get_item("C1") assert cpu is not None # it comes from a computer, path will still contain that, I don't care: I want it on the Table. # Send this location to the server, not the path. cpu.parent = "Table" # Let the server generate another code (since there's no way to delete items permanently we # can't test manually assigned codes... or rather we can, but just once) cpu.code = None # Add it: should succeed assert tarallo_session.add_item(cpu) # This stuff should be updated assert cpu.code is not None assert not cpu.code == "C1" # Just set path to none after inserting an item. The server doesn't return the full path so you have no way to # assign the correct value to this variable. # This assert checks just that: assert cpu.path is None # Let's get the entire item again and check... cpu = tarallo_session.get_item(cpu.code) assert cpu.path[-1:] == ['Table'] assert cpu.location == 'Table' # This may seem redundant, but these are different feature types... assert cpu.features["brand"] == "AMD" assert cpu.features["type"] == "cpu" assert cpu.features["cpu-socket"] == "am3" assert cpu.features["frequency-hertz"] == 3000000000
def test_update_one_feature(): tarallo_session = Tarallo(t_url, t_token) work = tarallo_session.get_item('R777').features['working'] new_feat = 'yes' # If operation succeeds, return True assert tarallo_session.update_item_features('R777', {'working': new_feat}) freq_updated = tarallo_session.get_item('R777').features['working'] assert freq_updated == new_feat
def test_update_one_feature(): tarallo_session = Tarallo(t_url, t_token) freq = tarallo_session.get_item('R777').features['frequency-hertz'] if freq % 2 == 0: new_freq = freq + 1 else: new_freq = freq - 1 # If operation succeeds, return True assert tarallo_session.update_features('R777', {'frequency-hertz': new_freq}) freq_updated = tarallo_session.get_item('R777').features['frequency-hertz'] assert freq_updated == new_freq
def test_get_item(): tarallo_session = Tarallo(t_url, t_token) item = tarallo_session.get_item('schifomacchina') assert item is not None assert type(item) == Item assert item.code == 'SCHIFOMACCHINA' assert isinstance(item.features, dict) assert isinstance(item.product, Product) assert item.product.features["type"] == "case" assert item.location == ["Polito", "Chernobyl", "Table"]
def test_get_item(): tarallo_session = Tarallo(t_url, t_token) item = tarallo_session.get_item('1') assert item is not None assert type(item) == Item assert item.code == '1' assert isinstance(item.features, dict) assert item.features["type"] == "case" assert item.path[-2:-1][0] == "Polito" assert item.path[-1:][0] == "Magazzino" assert item.location == "Magazzino"
def test_travaso(): tarallo_session = Tarallo(t_url, t_token) test_item = tarallo_session.travaso("schifomacchina", "RamBox") assert test_item item_r69 = tarallo_session.get_item("R69") assert item_r69 is not None assert type(item_r69) == Item assert item_r69.code == 'R69' assert isinstance(item_r69.features, dict) assert item_r69.location == 'RamBox' item_r188 = tarallo_session.get_item("R188") assert item_r188 is not None assert type(item_r188) == Item assert item_r188.code == 'R188' assert isinstance(item_r188.features, dict) assert item_r188.location == 'RamBox' tarallo_session.move("R69", "schifomacchina") tarallo_session.move("R188", "schifomacchina")
def test_travaso(): tarallo_session = Tarallo(t_url, t_token) test_item = tarallo_session.travaso("1", "LabFis4") assert test_item is True item_a2 = tarallo_session.get_item("A2") assert item_a2 is not None assert type(item_a2) == Item assert item_a2.code == 'A2' assert isinstance(item_a2.features, dict) assert item_a2.location == 'LabFis4' item_b1 = tarallo_session.get_item("B1") assert item_b1 is not None assert type(item_b1) == Item assert item_b1.code == 'B1' assert isinstance(item_b1.features, dict) assert item_b1.location == 'LabFis4' tarallo_session.move("A2", "1") tarallo_session.move("B1", "1")
def test_add_item_cloned(): tarallo_session = Tarallo(t_url, t_token) cpu = tarallo_session.get_item("C1") assert cpu is not None # it comes from a computer, path will still contain that, I don't care: I want it on the Table. # Send this location to the server, not the path. # Let the server generate another code (since there's no way to delete items permanently we # can't test manually assigned codes... or rather we can, but just once) # Add it: should succeed # the following lines convert a Item -> ItemToUpload # and test some basic stuff data = cpu.serializable() del data["code"] data["parent"] = data.get("location")[-1] del data["location"] assert data["parent"] == 'Table' cpu_toUpload = ItemToUpload(data) assert tarallo_session.add_item(cpu_toUpload) # Let's get the entire item again and check... cpu = tarallo_session.get_item(cpu.code)
def test_delete_one_feature(): tarallo_session = Tarallo(t_url, t_token) # Insert a frequency assert tarallo_session.update_item_features('R70', {'frequency-hertz': 800000000}) # Remove it assert tarallo_session.update_item_features('R70', {'frequency-hertz': None}) # Check that it's gone assert 'frequency-hertz' not in tarallo_session.get_item('R70').features # Add it again assert tarallo_session.update_item_features('R70', {'frequency-hertz': 800000000})
def test_add_item(): tarallo_session = Tarallo(t_url, t_token) ram = ItemToUpload() ram.features["type"] = "ram" ram.features["color"] = "red" ram.features["capacity-byte"] = 1024 * 1024 * 512 # 512 MiB ram.parent = "Table" assert tarallo_session.add_item(ram) # set the code to the one received from the server assert ram.code is not None assert isinstance(ram.code, str) # Let's get it again and check... ram = tarallo_session.get_item(ram.code) assert ram.location == 'Table' assert ram.features["type"] == "ram" assert ram.features["color"] == "red" assert ram.features["capacity-byte"] == 1024 * 1024 * 512
def test_add_item(): tarallo_session = Tarallo(t_url, t_token) ram = Item() ram.features["type"] = "ram" ram.features["color"] = "red" ram.features["capacity-byte"] = 1024 * 1024 * 512 # 512 MiB ram.location = "LabFis4" assert tarallo_session.add_item(ram) is True # set the code to the one received from the server assert ram.code is not None assert isinstance(ram.code, str) # Let's get it again and check... ram = tarallo_session.get_item(ram.code) assert ram.path[-1:] == ['LabFis4'] assert ram.location == 'LabFis4' assert ram.features["type"] == "ram" assert ram.features["color"] == "red" assert ram.features["capacity-byte"] == 1024 * 1024 * 512
def test_get_invalid_item(): tarallo_session = Tarallo(t_url, t_token) tarallo_session.get_item('asd')