Commits

Ian Cordasco committed a81dc50

Test issue creation

  • Participants
  • Parent commits 8b08bcf

Comments (0)

Files changed (2)

                      body=None,
                      assignee=None,
                      milestone=None,
-                     labels=[]):
+                     labels=None):
         """Creates an issue on this repository.
 
         :param str title: (required), title of the issue
         issue = {'title': title, 'body': body, 'assignee': assignee,
                  'milestone': milestone, 'labels': labels}
         self._remove_none(issue)
-        url = self._build_url('issues', base_url=self._api)
+        json = None
+
+        if issue:
+            url = self._build_url('issues', base_url=self._api)
+            json = self._json(self._post(url, issue), 201)
 
-        json = self._json(self._post(url, issue), 201)
         return Issue(json, self) if json else None
 
     @requires_auth

tests/test_repos.py

         expect(self.repo.create_fork('github3py')
                ).isinstance(github3.repos.Repository)
         self.mock_assertions()
+
+    def test_create_issue(self):
+        self.request.return_value = generate_response('issue', 201)
+        title = 'Construct _api attribute on our own'
+        self.args = ('post', self.api + 'issues')
+        self.conf = {'data': {'title': title}}
+
+        with expect.githuberror():
+            self.repo.create_issue(title)
+
+        self.login()
+        expect(self.repo.create_issue(None)).is_None()
+        expect(self.repo.create_issue(title)).isinstance(github3.issues.Issue)
+        self.mock_assertions()
+
+        body = 'Fake body'
+        self.conf['data'].update(body=body)
+        expect(self.repo.create_issue(title, body)
+               ).isinstance(github3.issues.Issue)
+        self.mock_assertions()
+
+        assignee, mile, labels = 'sigmavirus24', 1, ['bug', 'enhancement']
+        self.conf['data'].update({'assignee': assignee, 'milestone': mile,
+                                  'labels': labels})
+        expect(self.repo.create_issue(title, body, assignee, mile, labels)
+               ).isinstance(github3.issues.Issue)
+        self.mock_assertions()