Skip to content

Commit cbaac72

Browse files
committed
Split model and settings tests out to their own modules
1 parent 3d5ec86 commit cbaac72

4 files changed

Lines changed: 474 additions & 465 deletions

File tree

codespeed/tests/test_models.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import os
2+
3+
from django.conf import settings
4+
from django.test import TestCase
5+
6+
from codespeed.models import Project
7+
8+
9+
class TestProject(TestCase):
10+
11+
def setUp(self):
12+
self.github_project = Project(
13+
repo_type='H', repo_path='https://github.com/tobami/codespeed.git')
14+
self.git_project = Project(repo_type='G',
15+
repo_path='/home/foo/codespeed')
16+
17+
def test_repo_name(self):
18+
"""Test that only projects with local repositories have a repo_name attribute
19+
"""
20+
self.assertEqual(self.git_project.repo_name, 'codespeed')
21+
22+
self.assertRaises(AttributeError, getattr,
23+
self.github_project, 'repo_name')
24+
25+
def test_working_copy(self):
26+
"""Test that only projects with local repositories have a working_copy
27+
attribute
28+
29+
"""
30+
self.assertEqual(self.git_project.working_copy,
31+
os.path.join(settings.REPOSITORY_BASE_PATH,
32+
self.git_project.repo_name))
33+
34+
self.assertRaises(
35+
AttributeError, getattr, self.github_project, 'working_copy')
36+
37+
def test_github_browsing_url(self):
38+
"""If empty, the commit browsing url will be filled in with a default
39+
value when using github repository.
40+
"""
41+
42+
# It should work with https:// as well as git:// urls
43+
self.github_project.save()
44+
self.assertEquals(self.github_project.commit_browsing_url,
45+
'https://github.com/tobami/codespeed.git/'
46+
'commit/{commitid}')
47+
48+
self.github_project.repo_path = 'git://github.com/tobami/codespeed.git'
49+
self.github_project.save()
50+
self.assertEquals(self.github_project.commit_browsing_url,
51+
'https://github.com/tobami/codespeed.git/'
52+
'commit/{commitid}')
53+
54+
# If filled in, commit browsing url should not change
55+
self.github_project.commit_browsing_url = 'https://example.com/{commitid}'
56+
self.github_project.save()
57+
self.assertEquals(self.github_project.commit_browsing_url,
58+
'https://example.com/{commitid}')

codespeed/tests/test_settings.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
from django.conf import settings
2+
from django.test import TestCase
3+
4+
from codespeed import settings as default_settings
5+
6+
7+
class TestCodespeedSettings(TestCase):
8+
"""Test codespeed.settings
9+
"""
10+
11+
def setUp(self):
12+
self.cs_setting_keys = [key for key in dir(default_settings) if key.isupper()]
13+
14+
def test_website_name(self):
15+
"""See if WEBSITENAME is set
16+
"""
17+
self.assertTrue(default_settings.WEBSITE_NAME)
18+
self.assertEqual(default_settings.WEBSITE_NAME, 'MySpeedSite',
19+
"Change codespeed settings in project.settings")
20+
21+
def test_keys_in_settings(self):
22+
"""Check that all settings attributes from codespeed.settings exist
23+
in django.conf.settings
24+
"""
25+
for k in self.cs_setting_keys:
26+
self.assertTrue(hasattr(settings, k),
27+
"Key {0} is missing in settings.py.".format(k))
28+
29+
def test_settings_attributes(self):
30+
"""Check if all settings from codespeed.settings equals
31+
django.conf.settings
32+
"""
33+
for k in self.cs_setting_keys:
34+
self.assertEqual(getattr(settings, k), getattr(default_settings, k))

0 commit comments

Comments
 (0)