Ejemplo n.º 1
0
 def test_create_input_stream_none(self, con):
     name = "some name"
     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)
     response = Mock()
     response.json.return_value = some_dict
     con.return_value = response
     res = voc.create()
     self.assertEqual(str(res), str(some_dict))
Ejemplo n.º 2
0
 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")
Ejemplo n.º 3
0
 def test_create_miss_name(self):
     entries = {"str": "str", "category": "category"}
     vocabulary = Vocabulary()
     vocabulary.entries(entries)
     with self.assertRaises(QtVocabularyError):
         vocabulary.create()
Ejemplo n.º 4
0
 def test_create_miss_entry(self):
     name = "some name"
     voc = Vocabulary()
     voc.name(name)
     with self.assertRaises(QtVocabularyError):
         voc.create()
Ejemplo n.º 5
0
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
print("List all vocabularies")
print(vocabulary.read())