1
+ from django .test import TestCase
2
+
3
+ # Tests for models
4
+
5
+ from main .models import *
6
+ import re
7
+
8
+ class ComponentModelTest (TestCase ):
9
+
10
+ @classmethod
11
+ def setUpTestData (cls ):
12
+ # Called initially when test is executed, create object to be used by test methods
13
+ Component .objects .create (name = '@test/component' , author = 'test_author' )
14
+
15
+ # Test max length of name
16
+ def test_name_max_length (self ):
17
+ component = Component .objects .get (id = 1 )
18
+ max_length = component ._meta .get_field ('name' ).max_length
19
+ self .assertEquals (max_length , 100 )
20
+
21
+ # Test if url_name is a Slug Field
22
+ def test_url_name (self ):
23
+ component = Component .objects .get (id = 1 )
24
+ url_name = component .url_name
25
+ self .assertTrue (re .match ('[-\w]+' , url_name ))
26
+
27
+ # Test max length of author name
28
+ def test_author_max_length (self ):
29
+ component = Component .objects .get (id = 1 )
30
+ max_length = component ._meta .get_field ('author' ).max_length
31
+ self .assertEquals (max_length , 200 )
32
+
33
+ class TagModelTest (TestCase ):
34
+
35
+ @classmethod
36
+ def setUpTestData (cls ):
37
+ # Called initially when test is executed, create object to be used by test methods
38
+ Tag .objects .create (name = 'test_tag' )
39
+
40
+ # Test max length of name
41
+ def test_name_max_length (self ):
42
+ tag = Tag .objects .get (id = 1 )
43
+ max_length = tag ._meta .get_field ('name' ).max_length
44
+ self .assertEquals (max_length , 50 )
45
+
46
+ class ContributorModelTest (TestCase ):
47
+
48
+ @classmethod
49
+ def setUpTestData (cls ):
50
+ # Called initially when test is executed, create object to be used by test methods
51
+ Contributor .objects .create (username = 'test_contributor' )
52
+
53
+ # Test max length of name
54
+ def test_name_max_length (self ):
55
+ contributor = Contributor .objects .get (id = 1 )
56
+ max_length = contributor ._meta .get_field ('username' ).max_length
57
+ self .assertEquals (max_length , 100 )
0 commit comments