예제 #1
0
    def load(self, object_dict):
        self.action = object_dict.get('action', self.action)

        gh_issue = object_dict.get('issue', None)
        self.issue = GithubIssue()
        if gh_issue:
            self.issue.load(gh_issue)

        gh_user = object_dict.get('sender', None)
        self.sender = GithubUser()
        if gh_user:
            self.sender.load(gh_user)
예제 #2
0
 def test_non_empty_sender(self):
     payload = {
         "action": "sleep",
         "issue": {
             "title": "new issue"
         },
         "sender": {
             "login": "******"
         }
     }
     self.ghie.load(payload)
     self.assertEqual(self.ghie.action, "sleep")
     self.assertEqual(self.ghie.issue, GithubIssue(title="new issue"))
     self.assertEqual(self.ghie.sender, GithubUser(login="******"))
예제 #3
0
class GithubIssueEvent(BaseObject):

    properties = [
        'action',
        'issue',
        'sender'
    ]

    def __init__(self, **kwargs):
        super(GithubIssueEvent, self).__init__(**kwargs)
        self.action = "<No Action Specified>"

    def load(self, object_dict):
        self.action = object_dict.get('action', self.action)

        gh_issue = object_dict.get('issue', None)
        self.issue = GithubIssue()
        if gh_issue:
            self.issue.load(gh_issue)

        gh_user = object_dict.get('sender', None)
        self.sender = GithubUser()
        if gh_user:
            self.sender.load(gh_user)
예제 #4
0
 def setUp(self):
     self.ghi = GithubIssue()
예제 #5
0
class TestGithubIssue(unittest.TestCase):

    def setUp(self):
        self.ghi = GithubIssue()

    def test_default_setup(self):
        self.assertEqual(self.ghi.title, "No Title")
        self.assertEqual(self.ghi.html_url, "")
        self.assertEqual(self.ghi.state, "")
        self.assertEqual(self.ghi.assignee, GithubUser())
        self.assertEqual(self.ghi.labels, [])
        self.assertEqual(self.ghi.user, GithubUser())

    def test_load_empty_secondary_objects(self):
        payload = {}
        self.ghi.load(payload)
        self.assertEqual(self.ghi.title, "No Title")
        self.assertEqual(self.ghi.html_url, "")
        self.assertEqual(self.ghi.state, "")
        self.assertEqual(self.ghi.assignee, GithubUser())
        self.assertEqual(self.ghi.labels, [])
        self.assertEqual(self.ghi.user, GithubUser())

    def test_non_empty_assignee(self):
        payload = {
            "assignee": {
                "login": "******",
                "html_url": "http://news.com"
            }
        }
        self.ghi.load(payload)
        self.assertEqual(self.ghi.title, "No Title")
        self.assertEqual(self.ghi.html_url, "")
        self.assertEqual(self.ghi.state, "")
        self.assertEqual(self.ghi.assignee,
                         GithubUser(login="******",
                                    html_url="http://news.com"))
        self.assertEqual(self.ghi.labels, [])
        self.assertEqual(self.ghi.user, GithubUser())

    def test_single_label(self):
        payload = {
            "assignee": {
                "login": "******",
                "html_url": "http://news.com"
            },
            "labels": [
                {
                    "url": "label.com",
                    "name": "label name",
                    "color": "red"
                }
            ]
        }
        expected_labels = [
            GithubIssueLabel(url="label.com", name="label name", color="red")
        ]
        self.ghi.load(payload)
        self.assertEqual(self.ghi.title, "No Title")
        self.assertEqual(self.ghi.html_url, "")
        self.assertEqual(self.ghi.state, "")
        self.assertEqual(self.ghi.assignee,
                         GithubUser(login="******",
                                    html_url="http://news.com"))
        self.assertEqual(self.ghi.labels, expected_labels)
        self.assertEqual(self.ghi.user, GithubUser())

    def test_multiple_labels(self):
        payload = {
            "assignee": {
                "login": "******",
                "html_url": "http://news.com"
            },
            "labels": [
                {
                    "url": "label.com",
                    "name": "label name",
                    "color": "red"
                },
                {
                    "url": "label2.com",
                    "name": "label2 name",
                    "color": "blue"
                }
            ]
        }
        expected_labels = [
            GithubIssueLabel(url="label.com", name="label name", color="red"),
            GithubIssueLabel(url="label2.com",
                             name="label2 name",
                             color="blue")
        ]
        self.ghi.load(payload)
        self.assertEqual(self.ghi.title, "No Title")
        self.assertEqual(self.ghi.html_url, "")
        self.assertEqual(self.ghi.state, "")
        self.assertEqual(self.ghi.assignee,
                         GithubUser(login="******",
                                    html_url="http://news.com"))
        self.assertEqual(self.ghi.labels, expected_labels)
        self.assertEqual(self.ghi.user, GithubUser())

    def test_non_empty_user(self):
        payload = {
            "assignee": {
                "login": "******",
                "html_url": "http://news.com"
            },
            "labels": [
                {
                    "url": "label.com",
                    "name": "label name",
                    "color": "red"
                },
                {
                    "url": "label2.com",
                    "name": "label2 name",
                    "color": "blue"
                }
            ],
            "user": {
                "login": "******",
                "html_url": "u2.com"
            },
        }
        expected_labels = [
            GithubIssueLabel(url="label.com", name="label name", color="red"),
            GithubIssueLabel(url="label2.com",
                             name="label2 name",
                             color="blue")
        ]
        self.ghi.load(payload)
        self.assertEqual(self.ghi.title, "No Title")
        self.assertEqual(self.ghi.html_url, "")
        self.assertEqual(self.ghi.state, "")
        self.assertEqual(self.ghi.assignee,
                         GithubUser(login="******",
                                    html_url="http://news.com"))
        self.assertEqual(self.ghi.labels, expected_labels)
        self.assertEqual(self.ghi.user,
                         GithubUser(login="******", html_url="u2.com"))
예제 #6
0
 def test_load_empty_secondary_objects(self):
     payload = {}
     self.ghie.load(payload)
     self.assertEqual(self.ghie.action, "<No Action Specified>")
     self.assertEqual(self.ghie.issue, GithubIssue())
     self.assertEqual(self.ghie.sender, GithubUser())