Beispiel #1
0
 def test_task_with_parent(self, mock_client):
     models.Webhook.objects.create(project=self.project, secret=self.secret)
     parent_task = task(id=10, assignee=user())
     child_task = task(id=11, assignee=user(), parent=parent_task.copy())
     mock_client.access_token().tasks.find_all.return_value = [child_task]
     mock_client.access_token().tasks.find_by_id.side_effect = [
         child_task, parent_task
     ]
     data = {
         'events': [
             {
                 'action': 'added',
                 'created_at': '2017-08-21T18:20:37.972Z',
                 'parent': {
                     'id': 10
                 },
                 'resource': 1337,
                 'type': 'task',
                 'user': 1123
             },
         ]
     }
     message = json.dumps(data)
     signature = sign_sha256_hmac(self.secret, message)
     request = self.factory.post('',
                                 content_type='application/json',
                                 data=message,
                                 **{'X-Hook-Signature': signature})
     views.WebhookView.as_view()(request, remote_id=3)
     self.assertEqual(2, models.Task.objects.count())
     parent, child = tuple(models.Task.objects.order_by('remote_id'))
     self.assertEqual(parent, child.parent)
Beispiel #2
0
 def _get_mock_response(self, mock_client, data):
     message = json.dumps(data)
     signature = sign_sha256_hmac(self.secret, message)
     mock_client.access_token().projects.find_by_id.return_value = project()
     mock_client.access_token().tasks.find_by_id.return_value = task()
     request = self.factory.post('',
                                 content_type='application/json',
                                 data=message,
                                 **{'X-Hook-Signature': signature})
     return views.WebhookView.as_view()(request, remote_id=3)
Beispiel #3
0
 def test_task_with_parent(self, mock_client):
     models.Webhook.objects.create(project=self.project, secret=self.secret)
     parent_task = task(id=10, assignee=user())
     child_task = task(id=11, assignee=user(), parent=parent_task.copy())
     mock_client.access_token().tasks.find_all.return_value = [child_task]
     mock_client.access_token().tasks.find_by_id.side_effect = [
         child_task,
         parent_task,
     ]
     data = {
         "events": [
             {
                 "action": "added",
                 "created_at": "2017-08-21T18:20:37.972Z",
                 "parent": {
                     "gid": "10"
                 },
                 "resource": {
                     "gid": "1337",
                     "resource_type": "task",
                 },
                 "user": {
                     "gid": "1123",
                     "resource_type": "user",
                 },
             },
         ]
     }
     message = json.dumps(data)
     signature = sign_sha256_hmac(self.secret, message)
     request = self.factory.post("",
                                 content_type="application/json",
                                 data=message,
                                 **{"X-Hook-Signature": signature})
     views.WebhookView.as_view()(request, remote_id=3)
     self.assertEqual(2, models.Task.objects.count())
     parent, child = tuple(models.Task.objects.order_by("remote_id"))
     self.assertEqual(parent, child.parent)