def update(self, instance, validated_data):
     """Custom update method to allow manipulate the hexa color in count of words when creating"""
     words = validated_data.get('words')
     count = len(words.split())
     color = Colors.get_color(words, count)
     instance.color = Colors.get_color(words, count)
     instance.countwords = count
     instance.words = words
     instance.save()
     return instance
 def create(self, validated_data):
     """Custom create method to allow manipulate the hexa color in count of words when creating"""
     form = modelform_factory(Words, fields=('color', 'words', 'countwords'))
     words = validated_data.get('words')
     count = len(words.split())
     color = Colors.get_color(words, count)
     json = { 'color': color, 'words': words, 'countwords': count }
     populated_form = form(data=json)
     if populated_form.is_valid():
         return populated_form.save()
Beispiel #3
0
 def test_color_equaltohundred_returns_gray(self):
     words = "My test case one  My test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case one My test case one  My test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy test case oneMy"
     color = Colors.get_color(words, len(words.split(' ')))
     assert color == self.gray
Beispiel #4
0
 def test_color_lesshundred_returns_random(self):
     words = "My test case one"
     color = Colors.get_color(words, len(words.split(' ')))
     assert color != self.gray
Beispiel #5
0
 def test_color_spaceinstring_returns_random(self):
     words = " "
     color = Colors.get_color(words, len(words.split(' ')))
     assert color != self.gray
Beispiel #6
0
 def test_color_spacesinstring_returns_random(self):
     words = "  ksjd jsakd jkasjd       lka s                 "
     color = Colors.get_color(words, len(words.split(' ')))
     assert color != self.gray