コード例 #1
0
 def test_synonyms_string_setter_handles_spaces(self, m_f):
     """Do not create Synonyms from whitespace."""
     smi = SynonymsMixin()
     smi.synonyms = list()
     smi.synonyms_string = ' , \t, space, \n'
     assert len(smi.synonyms) == 1
     assert smi.synonyms_string == 'space'
コード例 #2
0
 def test_synonyms_string_getter(self):
     """Return a string listing the names of all synonyms of an object."""
     smi = SynonymsMixin()
     smi.synonyms = [Synonym(name='pigeon'),
                     Synonym(name='rock dove'),
                     Synonym(name='flying rat')]
     assert smi.synonyms_string == 'pigeon, rock dove, flying rat'
コード例 #3
0
 def test_synonyms_string_setter_sets_new(self, m_f):
     """Create new synonyms if object has none."""
     smi = SynonymsMixin()
     smi.synonyms = list()
     smi.synonyms_string = 'pigeon, rock dove, flying rat'
     assert len(smi.synonyms) == 3
     assert smi.synonyms_string == 'pigeon, rock dove, flying rat'
     assert m_f.called
コード例 #4
0
 def test_synonyms_string_setter_clears_old(self, m_f):
     """Remove synonyms if given a falsey value."""
     smi = SynonymsMixin()
     synonyms = [Synonym(name='pigeon'),
                 Synonym(name='rock dove'),
                 Synonym(name='flying rat')]
     smi.synonyms = synonyms
     assert len(smi.synonyms) == 3
     smi.synonyms_string = None
     assert not smi.synonyms
     assert not m_f.called
     smi.synonyms = synonyms
     smi.synonyms_string = ''
     assert not smi.synonyms
コード例 #5
0
 def test_synonyms_string_setter_deletes_old(self, m_i, m_d, m_f):
     """Delete removed synonyms that are in a persistent db state."""
     state = mock.MagicMock()
     state.persistent = True
     m_i.return_value = state
     smi = SynonymsMixin()
     synonyms = [Synonym(name='pigeon'),
                 Synonym(name='rock dove'),
                 Synonym(name='flying rat')]
     smi.synonyms = list(synonyms)
     smi.synonyms_string = None
     assert not smi.synonyms
     m_i.assert_any_call(synonyms[0])
     m_i.assert_any_call(synonyms[1])
     m_i.assert_any_call(synonyms[2])
     assert m_d.call_count == 3
     assert m_f.called