Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gyuricska Milán
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
05850cfb
authored
May 21, 2013
by
Dudás Ádám
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
school: full test coverage for models
parent
d9b9640b
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
4 deletions
+42
-4
school/tests.py
+42
-4
No files found.
school/tests.py
View file @
05850cfb
from
datetime
import
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
django.test
import
TestCase
from
django.test
import
TestCase
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
from
django.core.exceptions
import
ValidationError
from
models
import
create_user_profile
,
Person
,
Course
,
Semester
,
Group
from
models
import
create_user_profile
,
Person
,
Course
,
Semester
,
Group
class
CreateUserProfileTestCase
(
TestCase
):
class
CreateUserProfileTestCase
(
TestCase
):
...
@@ -54,6 +55,10 @@ class PersonWithUserTestCase(TestCase):
...
@@ -54,6 +55,10 @@ class PersonWithUserTestCase(TestCase):
def
test_unicode
(
self
):
def
test_unicode
(
self
):
self
.
assertIsNotNone
(
self
.
person
.
__unicode__
())
self
.
assertIsNotNone
(
self
.
person
.
__unicode__
())
# without first or last name
self
.
person
.
user
.
first_name
=
None
self
.
person
.
user
.
last_name
=
None
self
.
assertIsNotNone
(
self
.
person
.
__unicode__
())
class
PersonWithoutUserTestCase
(
TestCase
):
class
PersonWithoutUserTestCase
(
TestCase
):
"""Test Person entities which doesn't have their user attribute set."""
"""Test Person entities which doesn't have their user attribute set."""
...
@@ -89,11 +94,29 @@ class CourseTestCase(TestCase):
...
@@ -89,11 +94,29 @@ class CourseTestCase(TestCase):
def
test_get_or_create_default_group
(
self
):
def
test_get_or_create_default_group
(
self
):
default_group
=
self
.
testcourse
.
get_or_create_default_group
()
default_group
=
self
.
testcourse
.
get_or_create_default_group
()
self
.
assertIsNotNone
(
default_group
)
self
.
assertIsNotNone
(
default_group
)
self
.
assertEquals
(
default_group
,
self
.
testcourse
.
default_group
)
self
.
assertEqual
(
default_group
,
self
.
testcourse
.
default_group
)
# now it already has a group, so this'll be a get
default_group1
=
self
.
testcourse
.
get_or_create_default_group
()
self
.
assertIsNotNone
(
default_group1
)
self
.
assertEqual
(
default_group
,
default_group1
)
def
test_owner_list
(
self
):
def
test_owner_list
(
self
):
owner_list
=
self
.
testcourse
.
owner_list
()
self
.
assertIsNotNone
(
self
.
testcourse
.
owner_list
())
self
.
assertIsNotNone
(
owner_list
)
# if the course has no owners:
self
.
testcourse
.
owners
.
all
()
.
delete
()
self
.
assertIsNotNone
(
self
.
testcourse
.
owner_list
())
def
test_unicode
(
self
):
self
.
assertIsNotNone
(
self
.
testcourse
.
__unicode__
())
# if the course doesn't have a name:
self
.
testcourse
.
name
=
None
self
.
assertIsNotNone
(
self
.
testcourse
.
__unicode__
())
def
test_short
(
self
):
self
.
assertIsNotNone
(
self
.
testcourse
.
short
())
# if the course doesn't have a short name:
self
.
testcourse
.
short_name
=
None
self
.
assertIsNotNone
(
self
.
testcourse
.
short
())
class
SemesterTestCase
(
TestCase
):
class
SemesterTestCase
(
TestCase
):
def
setUp
(
self
):
def
setUp
(
self
):
...
@@ -115,6 +138,10 @@ class SemesterTestCase(TestCase):
...
@@ -115,6 +138,10 @@ class SemesterTestCase(TestCase):
def
test_get_current
(
self
):
def
test_get_current
(
self
):
self
.
assertEqual
(
self
.
current_semester
,
Semester
.
get_current
())
self
.
assertEqual
(
self
.
current_semester
,
Semester
.
get_current
())
# if there's no current semester:
self
.
current_semester
.
delete
()
with
self
.
assertRaises
(
ValidationError
):
Semester
.
get_current
()
def
test_unicode
(
self
):
def
test_unicode
(
self
):
self
.
current_semester
.
__unicode__
()
self
.
current_semester
.
__unicode__
()
...
@@ -125,8 +152,10 @@ class GroupTestCase(TestCase):
...
@@ -125,8 +152,10 @@ class GroupTestCase(TestCase):
delta
=
timedelta
(
weeks
=
7
)
delta
=
timedelta
(
weeks
=
7
)
semester
=
Semester
.
objects
.
create
(
name
=
"testsem"
,
semester
=
Semester
.
objects
.
create
(
name
=
"testsem"
,
start
=
date
-
delta
,
end
=
date
+
delta
)
start
=
date
-
delta
,
end
=
date
+
delta
)
self
.
testcourse
=
Course
.
objects
.
create
(
code
=
"testcode"
,
name
=
"testname"
,
short_name
=
"tn"
)
self
.
testgroup
=
Group
.
objects
.
create
(
name
=
"testgrp"
,
self
.
testgroup
=
Group
.
objects
.
create
(
name
=
"testgrp"
,
semester
=
semester
)
semester
=
semester
,
course
=
self
.
testcourse
)
def
test_owner_list
(
self
):
def
test_owner_list
(
self
):
self
.
assertIsNotNone
(
self
.
testgroup
.
owner_list
())
self
.
assertIsNotNone
(
self
.
testgroup
.
owner_list
())
...
@@ -146,3 +175,12 @@ class GroupTestCase(TestCase):
...
@@ -146,3 +175,12 @@ class GroupTestCase(TestCase):
testmember2
=
Person
.
objects
.
create
(
code
=
"testprsn4"
)
testmember2
=
Person
.
objects
.
create
(
code
=
"testprsn4"
)
self
.
testgroup
.
members
.
add
(
testmember2
)
self
.
testgroup
.
members
.
add
(
testmember2
)
self
.
assertEqual
(
2
,
self
.
testgroup
.
member_count
())
self
.
assertEqual
(
2
,
self
.
testgroup
.
member_count
())
def
test_unicode
(
self
):
self
.
assertIsNotNone
(
self
.
testgroup
.
__unicode__
())
# if the group has no course associated:
self
.
testgroup
.
course
=
None
self
.
assertIsNotNone
(
self
.
testgroup
.
__unicode__
())
def
test_get_absolute_url
(
self
):
self
.
assertIsNotNone
(
self
.
testgroup
.
get_absolute_url
())
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment