Skip to content

Commit

Permalink
Merge pull request #45 from rzashakeri/develop
Browse files Browse the repository at this point in the history
✅ test: Add VisitModelTest and test_visit_count
  • Loading branch information
rzashakeri authored Jan 1, 2024
2 parents 10c3d18 + 4598955 commit 9b08bc9
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions blog/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from django.test import TestCase
from django.core.files.uploadedfile import SimpleUploadedFile
from blog.models import Post, Tag
from blog.models import Post, Tag, Visit


class PostModelTest(TestCase):
def setUp(self):
self.tag1 = Tag.objects.create(name='tag1')
Expand Down Expand Up @@ -53,7 +55,6 @@ def test_post_tags_blank(self):
self.assertEqual(post.tags.count(), 0)



class TagModelTest(TestCase):

def setUp(self):
Expand All @@ -80,4 +81,20 @@ def test_ordering_by_name(self):
tags = Tag.objects.all()
self.assertEqual(tags[0], tag1)
self.assertEqual(tags[1], self.tag)
self.assertEqual(tags[2], tag2)
self.assertEqual(tags[2], tag2)


class VisitModelTest(TestCase):
def setUp(self):
self.post = Post.objects.create(
title='Test Post',
icon=SimpleUploadedFile('icon.png', b''),
content='Test content'
)
self.visit = Visit.objects.create(post=self.post, ip_address='127.0.0.1')

def test_visit_str(self):
self.assertEqual(str(self.visit), 'Test Post - 127.0.0.1')

def test_visit_count(self):
self.assertEqual(self.post.visit_count, 1)

0 comments on commit 9b08bc9

Please sign in to comment.