def test_get_not_found(self):
     request = testing.DummyRequest()
     request.matchdict = {
         'uuid': self.anon_webhook.uuid.hex,
     }
     resource = views.WebhooksResource(request)
     self.assertRaises(NoResultFound, resource.get)
 def test_get(self):
     request = testing.DummyRequest()
     request.matchdict = {
         'uuid': self.owner_webhook.uuid.hex,
     }
     resource = views.WebhooksResource(request)
     webhook = resource.get()
     self.assertEqual(webhook['uuid'], self.owner_webhook.uuid.hex)
 def test_delete_not_found(self):
     self.assertEqual(DBSession.query(Webhook).count(), 2)
     request = testing.DummyRequest()
     request.matchdict = {
         'uuid': self.anon_webhook.uuid.hex,
     }
     resource = views.WebhooksResource(request)
     self.assertRaises(NoResultFound, resource.delete)
     self.assertEqual(DBSession.query(Webhook).count(), 2)
 def test_collection_get(self):
     request = testing.DummyRequest()
     resource = views.WebhooksResource(request)
     [webhook] = resource.collection_get()
     self.assertEqual(webhook['uuid'], self.webhook.uuid.hex)
     self.assertEqual(webhook['owner'], None)
     self.assertEqual(webhook['url'], u'http://example.org')
     self.assertEqual(webhook['event_type'], u'repo.push')
     self.assertEqual(webhook['active'], True)
 def test_delete(self):
     self.assertEqual(DBSession.query(Webhook).count(), 2)
     request = testing.DummyRequest()
     request.matchdict = {
         'uuid': self.owner_webhook.uuid.hex,
     }
     resource = views.WebhooksResource(request)
     webhook = resource.delete()
     self.assertEqual(DBSession.query(Webhook).count(), 1)
     self.assertEqual(webhook['uuid'], self.owner_webhook.uuid.hex)
 def test_get(self):
     request = testing.DummyRequest()
     request.matchdict = {
         'uuid': self.webhook.uuid.hex,
     }
     resource = views.WebhooksResource(request)
     webhook = resource.get()
     self.assertEqual(webhook['uuid'], self.webhook.uuid.hex)
     self.assertEqual(webhook['owner'], None)
     self.assertEqual(webhook['url'], u'http://example.org')
     self.assertEqual(webhook['event_type'], u'repo.push')
     self.assertEqual(webhook['active'], True)
 def test_delete(self):
     self.assertEqual(DBSession.query(Webhook).count(), 1)
     request = testing.DummyRequest()
     request.matchdict = {
         'uuid': self.webhook.uuid.hex,
     }
     resource = views.WebhooksResource(request)
     webhook = resource.delete()
     self.assertEqual(DBSession.query(Webhook).count(), 0)
     self.assertEqual(webhook['uuid'], self.webhook.uuid.hex)
     self.assertEqual(webhook['owner'], None)
     self.assertEqual(webhook['url'], u'http://example.org')
     self.assertEqual(webhook['event_type'], u'repo.push')
     self.assertEqual(webhook['active'], True)
 def test_collection_post(self):
     self.assertEqual(DBSession.query(Webhook).count(), 1)
     request = testing.DummyRequest()
     request.validated = {
         'url': u'http://www.example.org',
         'event_type': u'repo.push',
         'active': True,
     }
     resource = views.WebhooksResource(request)
     webhook = resource.collection_post()
     self.assertEqual(DBSession.query(Webhook).count(), 2)
     count = DBSession.query(Webhook). \
         filter(Webhook.uuid == webhook['uuid']). \
         count()
     self.assertEqual(count, 1)
     self.assertEqual(webhook['owner'], None)
 def test_update(self):
     webhook = DBSession.query(Webhook).one()
     request = testing.DummyRequest()
     request.validated = {
         'url': 'http://www.example.org/updated/',
         'event_type': u'repo.push',
         'active': False,
     }
     request.matchdict = {
         'uuid': webhook.uuid,
     }
     resource = views.WebhooksResource(request)
     resource.put()
     updated_webhook = DBSession.query(Webhook).one()
     self.assertEqual(updated_webhook.active, False)
     self.assertEqual(updated_webhook.url,
                      'http://www.example.org/updated/')
     self.assertEqual(updated_webhook.event_type, u'repo.push')
     self.assertEqual(updated_webhook.uuid, webhook.uuid)
 def test_collection_get(self):
     request = testing.DummyRequest()
     resource = views.WebhooksResource(request)
     [webhook] = resource.collection_get()
     self.assertEqual(webhook['uuid'], self.owner_webhook.uuid.hex)