|
| 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}') |
0 commit comments