Exemplo n.º 1
0
 def test_to_dict(self):
     term = Term('definition1', 1, ImageFactory(), 1, 'term1')
     assert term.to_dict() == {
         'definition': 'definition1',
         'id': 1,
         'image': None,
         'rank': 1,
         'term': 'term1'
     }
Exemplo n.º 2
0
 def test_from_dict(self):
     raw_data = {
         'definition': 'term definition',
         'id': 12345,
         'image': None,
         'rank': 0,
         'term': 'term'
     }
     term = Term.from_dict(raw_data)
     assert term.definition == 'term definition'
     assert term.term_id == 12345
     assert term.image.url is None
     assert term.rank == 0
     assert term.term == 'term'
Exemplo n.º 3
0
 def test_to_dict(self):
     wordset = WordSet(0, 'title0', [Term('def0', 0, ImageFactory(), 0, 'term0')])
     assert wordset.to_dict() == {
         'id': 0,
         'title': 'title0',
         'terms': [
             {
                 'definition': 'def0',
                 'id': 0,
                 'image': None,
                 'rank': 0,
                 'term': 'term0'
             }
         ]
     }
Exemplo n.º 4
0
 def test_from_dict(self):
     raw_data = {
         'id': 0,
         'title': 'title0',
         'terms': [
             {
                 'definition': 'definition0',
                 'id': 0,
                 'image': None,
                 'rank': 0,
                 'term': 'term0'
             }
         ]
     }
     wordset = WordSet.from_dict(raw_data)
     assert wordset.set_id == 0
     assert wordset.title == 'title0'
     assert wordset.terms == [Term('definition0', 0, Image(None, None, None), 0, 'term0')]
Exemplo n.º 5
0
 def test_unequal_terms(self):
     term0 = Term('definition0', 0, ImageFactory(), 0, 'term0')
     term1 = Term('definition1', 1, ImageFactory(), 0, 'term1')
     assert term0 != term1
Exemplo n.º 6
0
 def test_equal_terms(self):
     term0 = Term('definition', 0, ImageFactory(), 0, 'term')
     term1 = Term('definition', 0, ImageFactory(), 0, 'term')
     assert term0 == term1
Exemplo n.º 7
0
 def test_correct_init(self):
     term = Term('definition', 1, ImageFactory(), 0, 'term')
     assert term.definition == 'definition'
     assert term.term_id == 1
     assert term.image.url is None
     assert term.term == 'term'
Exemplo n.º 8
0
 def test_wrong_term_json_structure(self):
     with self.assertRaises(ValueError):
         Term.from_dict({'some data': '142% unexpected'})