def test_create_input_stream(self, con): name = "some name" some_tsv_file = 'test.tsv' with open(some_tsv_file, "w") as f: f.write("Delete me!") some_dict = { "id": "some value", 'name': 'some name', 'entries': [{ 'str': 'some entry' }] } some_entry = "some entry" voc = Vocabulary() voc.name(name) voc.add_entry(some_entry) voc.source(some_tsv_file) response = Mock() response.json.return_value = some_dict con.return_value = response res = voc.create() self.assertEqual(str(res), str(some_dict)) os.remove("test.tsv")
def test_source_arg_file_type(self): file = 123 vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.source(file)
def test_source_file_exist(self): file = "path.tsv" vocabulary = Vocabulary() with self.assertRaises(QtArgumentError): vocabulary.source(file)
# Create Vocabulary try: vocabulary.name("some name").add_entry("Apple Inc.", "AAPL").create() except Exception as e: print(e) # Fetch from current object print("Fetch vocabulary") print(vocabulary.fetch(vocabulary.get_id())) # Create list of vocabularies from tsv file print("Create list of the vocabularies from TSV file") tsv_voc = Vocabulary() tsv_voc.name("revenue") tsv_voc.source(FILE_NAME) try: tsv_voc.create() except Exception as e: print(e) print(tsv_voc) # Update vocabulary, name and entries are mandatory options print("Update vocabulary") vocabulary.add_entry("Lenovo", "Thinkpad") vocabulary.name("updated name") print(vocabulary.get_id()) vocabulary.update(vocabulary.get_id()) print(vocabulary) # List all existing vocabularies