def test_install_201(self): app = models.Addon().save() data = { "capabilitiesUrl": "https://api.hipchat.com/v2/capabilities", "oauthId": "abc", "oauthSecret": "xyz", "groupId": 123, "roomId": "1234" } self.assertFalse(models.Install.objects.exists()) request = self.factory.post( '/', json.dumps(data), content_type='application/json' ) token_data = { 'access_token': '52363462337245724', 'expires_in': 3599, 'group_id': 123, 'group_name': 'Example Company', 'scope': 'send_notification', 'token_type': 'bearer' } with mock.patch('hipchat.models.request_access_token', lambda x: token_data): resp = views.install(request, app_id=app.id) self.assertEqual(resp.status_code, 201) install = models.Install.objects.get() self.assertEqual(install.oauth_id, data['oauthId']) self.assertEqual(install.oauth_secret, data['oauthSecret']) self.assertEqual(install.group_id, data['groupId']) self.assertEqual(install.room_id, int(data['roomId']))
def test_install_422(self): app = models.Addon().save() models.Install(app=app, oauth_id="abc", group_id=0).save() data = { "capabilitiesUrl": "https://api.hipchat.com/v2/capabilities", "oauthId": "abc", "oauthSecret": "xyz", "groupId": 123, "roomId": "1234" } request = self.factory.post( '/', json.dumps(data), content_type='application/json' ) resp = views.install(request, app_id=app.id) self.assertEqual(resp.status_code, 422)