1
+ from django .test import SimpleTestCase
2
+ from ponder .models import Commit , BugFix , Categorization , Categorizer , User
3
+ from unittest .mock import patch
4
+
5
+ class ModelTest (SimpleTestCase ):
6
+ # def setUp(self):
7
+
8
+ @patch ('ponder.models.Commit.objects.get' )
9
+ def test_commit_model (self , commit_get ):
10
+ commit_get .return_value = Commit (
11
+ id = 1 ,
12
+ project = "Mocked-project" ,
13
+ sha = "testsha1234" ,
14
+ author_email = "<[email protected] >"
15
+ )
16
+
17
+ mocked_commit = Commit .objects .get (id = 1 )
18
+
19
+ self .assertEqual (mocked_commit .project , "Mocked-project" )
20
+ self .assertEqual (mocked_commit .get_project (), "https://github.com/Mocked-project" )
21
+ self .
assertEqual (
mocked_commit .
email_author (),
"mailto:[email protected] " )
22
+ self .assertEqual (mocked_commit .get_commit (), "https://github.com/Mocked-project/commit/testsha1234" )
23
+
24
+
25
+ @patch ('ponder.models.Commit.objects.values' )
26
+ @patch ('ponder.models.BugFix.objects.get' )
27
+ def test_bugfix_model (self , bugfix_get , commit_values ):
28
+ commit_values = Commit .objects .values
29
+ commit_values .filter .return_value = Commit (
30
+ id = 1 ,
31
+ project = "Mocked-project" ,
32
+ sha = "testsha1234" ,
33
+ author_email = "<[email protected] >" ,
34
+ )
35
+
36
+ bugfix_get = BugFix .objects .get
37
+ bugfix_get .return_value = BugFix (
38
+ id = 9 ,
39
+ sha = "testsha1234" ,
40
+ )
41
+
42
+ mocked_bugfix = BugFix .objects .get (id = 9 )
43
+
44
+ self .assertIn ("testsha1234" , mocked_bugfix .get_sha ())
45
+ self .assertEqual (mocked_bugfix .get_id (), '9/' )
46
+
47
+ @patch ('ponder.models.Commit.objects.values' )
48
+ @patch ('ponder.models.User.objects.get' )
49
+ @patch ('ponder.models.Categorization.objects.get' )
50
+ def test_categorization (self , categorization_get , user_get , commit_values ):
51
+ user_get = User .objects .get
52
+ user_get .return_value = User (
53
+ id = 1 ,
54
+ username = "testuser" ,
55
+
56
+ )
57
+
58
+ commit_values = Commit .objects .values
59
+ commit_values .filter .return_value = Commit (
60
+ id = 1 ,
61
+ project = "Mocked-project" ,
62
+ sha = "testsha1234" ,
63
+ author_email = "<[email protected] >" ,
64
+ )
65
+
66
+ categorization_get = Categorization .objects .get
67
+ categorization_get .return_value = Categorization (
68
+ id = 1 ,
69
+ sha = "testsha1234" ,
70
+ bug_fix = BugFix (
71
+ id = 9 ,
72
+ sha = "testsha1234" ,
73
+ ),
74
+ categorizer = Categorizer (
75
+ name = "testuser"
76
+ )
77
+ )
78
+
79
+ mocked_categorization = Categorization .objects .get (id = 1 )
80
+
81
+ self .assertIn ("testsha1234" , mocked_categorization .get_sha ())
82
+ self .assertEqual (mocked_categorization .get_absolute_url (), "bug_fixes/9" )
83
+ self .
assertEqual (
mocked_categorization .
email_categorizer (),
"mailto:<[email protected] >" )
0 commit comments