Ejemplo n.º 1
0
 def test_create_tag_content_is_hair(self):
     '''Asserts that a tag with content "hair" is correctly stored in the database'''
     CONTENT_TEXT = "hair"
     tag = Tag(content=CONTENT_TEXT)
     tag.save()
     database_tag = Tag.objects.get(content=CONTENT_TEXT)
     self.assertEqual(database_tag.content, CONTENT_TEXT)
Ejemplo n.º 2
0
 def test_content_update_in_database(self):
     '''Asserts that the content can be updated in the database'''
     INITIAL_CONTENT = "make up"
     UPDATED_CONTENT = "beauty"
     tag = Tag(content=INITIAL_CONTENT)
     tag.save()
     database_tag = Tag.objects.get(content=INITIAL_CONTENT)
     database_tag.content = UPDATED_CONTENT
     database_tag.save()
     initial_content_tags_count = Tag.objects.filter(content__exact=INITIAL_CONTENT).count()
     self.assertEqual(initial_content_tags_count, 0)
Ejemplo n.º 3
0
 def get_tag(self, tag):
     """
     Creates Tag if it doesn't exist, else return existing one
     :param tag: tag name
     :return: Tag db object
     """
     try:
         return Tag.objects.get(name=tag)
     except Tag.DoesNotExist:
         tag = Tag(name=tag)
         tag.save()
         return tag
Ejemplo n.º 4
0
 def get_tag(self, tag):
     """
     Creates Tag if it doesn't exist, else return existing one
     :param tag: tag name
     :return: Tag db object
     """
     try:
         return Tag.objects.get(name=tag)
     except Tag.DoesNotExist:
         tag = Tag(name=tag)
         tag.save()
         return tag
Ejemplo n.º 5
0
 def test_create_three_tags(self):
     '''Asserts that three tags have been correctly stored in the database'''
     first_tag = Tag(content = "beauty")
     first_tag.save()
     second_tag = Tag(content = "make up")
     second_tag.save()
     third_tag = Tag(content = "nail polish")
     third_tag.save()
     tags_count = Tag.objects.all().count()
     self.assertEqual(tags_count, 3)
Ejemplo n.º 6
0
    def get_or_create_tag(tag_name):
        """
        Returns a Tag, which will be either created or retrieved from the
        database.
        """
        tag_name = tag_name.strip()
        if tag_name == '':
            raise ValueError('Tag value cannot be empty')

        try:
            return Tag.objects.get(name=tag_name)
        except Tag.DoesNotExist:
            tag = Tag(name=tag_name)
            tag.save()
            return tag
Ejemplo n.º 7
0
    def get_or_create_tag(tag_name):
        """
        Returns a Tag, which will be either created or retrieved from the
        database.
        """
        tag_name = tag_name.strip()
        if tag_name == '':
            raise ValueError('Tag value cannot be empty')

        try:
            return Tag.objects.get(name=tag_name)
        except Tag.DoesNotExist:
            tag = Tag(name=tag_name)
            tag.save()
            return tag
Ejemplo n.º 8
0
 def test_content_can_be_empty_string(self):
     '''Asserts that the content can be an empty string'''
     tag = Tag(content=str())
     tag.save()
     database_tag = Tag.objects.get(content=str())
     self.assertEqual(database_tag.content, str())