Skip to content

Commit e0bdc22

Browse files
committed
Initiated view tests
1 parent a5cf1ab commit e0bdc22

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tests/test_views.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from django.test import TestCase
2+
3+
from main.models import *
4+
from django.urls import reverse
5+
import random
6+
from time import sleep
7+
8+
class IndexViewTest(TestCase):
9+
10+
@classmethod
11+
def setUpTestData(cls):
12+
# Called initially when test is executed, create objects to be used by test methods
13+
# create 10 random objects
14+
number_of_components = 10
15+
for component_no in range(number_of_components):
16+
Component.objects.create(name='component'+str(component_no), downloads=random.randint(0,50), stars=random.randint(0,50))
17+
sleep(0.5)
18+
19+
def test_view_url_exists_at_desired_location(self):
20+
response = self.client.get('/')
21+
self.assertEqual(response.status_code, 200)
22+
23+
def test_view_accessible_by_name(self):
24+
response = self.client.get(reverse('main:index'))
25+
self.assertEqual(response.status_code, 200)

0 commit comments

Comments
 (0)