1
|
|
|
# coding: utf-8 |
2
|
|
|
from django.conf import settings |
3
|
|
|
from th_github.models import Github |
4
|
|
|
from th_github.forms import GithubProviderForm, GithubConsumerForm |
5
|
|
|
from django_th.tests.test_main import MainTest |
6
|
|
|
|
7
|
|
|
|
8
|
|
|
class GithubTest(MainTest): |
9
|
|
|
|
10
|
|
|
def create_github(self): |
11
|
|
|
""" |
12
|
|
|
Create a github object related to the trigger object |
13
|
|
|
""" |
14
|
|
|
trigger = self.create_triggerservice(consumer_name='ServiceGithub') |
15
|
|
|
name = 'github' |
16
|
|
|
repo = 'foobar' |
17
|
|
|
project = 'barfoo' |
18
|
|
|
status = True |
19
|
|
|
return Github.objects.create(trigger=trigger, |
20
|
|
|
name=name, |
21
|
|
|
status=status, |
22
|
|
|
repo=repo, |
23
|
|
|
project=project) |
24
|
|
|
|
25
|
|
|
def test_github(self): |
26
|
|
|
""" |
27
|
|
|
Test if the creation of the github object looks fine |
28
|
|
|
""" |
29
|
|
|
d = self.create_github() |
30
|
|
|
self.assertTrue(isinstance(d, Github)) |
31
|
|
|
self.assertEqual(d.show(), "My Github {}".format(d.name)) |
32
|
|
|
self.assertEqual(d.__str__(), d.name) |
33
|
|
|
|
34
|
|
|
""" |
35
|
|
|
Form |
36
|
|
|
""" |
37
|
|
|
# provider |
38
|
|
|
def test_valid_provider_form(self): |
39
|
|
|
""" |
40
|
|
|
test if that form is a valid provider one |
41
|
|
|
""" |
42
|
|
|
d = self.create_github() |
43
|
|
|
data = {'repo': d.repo, 'project': d.project} |
44
|
|
|
form = GithubProviderForm(data=data) |
45
|
|
|
self.assertTrue(form.is_valid()) |
46
|
|
|
|
47
|
|
|
def test_invalid_provider_form(self): |
48
|
|
|
""" |
49
|
|
|
test if that form is not a valid provider one |
50
|
|
|
""" |
51
|
|
|
form = GithubProviderForm(data={}) |
52
|
|
|
self.assertFalse(form.is_valid()) |
53
|
|
|
|
54
|
|
|
# consumer |
55
|
|
|
def test_valid_consumer_form(self): |
56
|
|
|
""" |
57
|
|
|
test if that form is a valid consumer one |
58
|
|
|
""" |
59
|
|
|
d = self.create_github() |
60
|
|
|
data = {'repo': d.repo, 'project': d.project} |
61
|
|
|
form = GithubConsumerForm(data=data) |
62
|
|
|
self.assertTrue(form.is_valid()) |
63
|
|
|
|
64
|
|
|
def test_invalid_consumer_form(self): |
65
|
|
|
""" |
66
|
|
|
test if that form is not a valid consumer one |
67
|
|
|
""" |
68
|
|
|
form = GithubConsumerForm(data={}) |
69
|
|
|
self.assertFalse(form.is_valid()) |
70
|
|
|
|
71
|
|
|
def test_get_config_th(self): |
72
|
|
|
""" |
73
|
|
|
does this settings exists ? |
74
|
|
|
""" |
75
|
|
|
self.assertTrue(settings.TH_GITHUB) |
76
|
|
|
|
77
|
|
|
def test_get_config_th_cache(self): |
78
|
|
|
self.assertIn('th_github', settings.CACHES) |
79
|
|
|
|
80
|
|
|
def test_get_services_list(self): |
81
|
|
|
th_service = ('th_github.my_github.ServiceGithub',) |
82
|
|
|
for service in th_service: |
83
|
|
|
self.assertIn(service, settings.TH_SERVICES) |
84
|
|
|
|