コード例 #1
0
ファイル: test_rest_api.py プロジェクト: ajdlinux/patchwork
    def test_list(self):
        """Validate we can list bundles."""
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(0, len(resp.data))

        user = create_user()
        bundle_public = create_bundle(public=True, owner=user)
        bundle_private = create_bundle(public=False, owner=user)

        # anonymous users
        # should only see the public bundle
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        bundle_rsp = resp.data[0]
        self.assertSerialized(bundle_public, bundle_rsp)

        # authenticated user
        # should see the public and private bundle
        self.client.force_authenticate(user=user)
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(2, len(resp.data))
        for bundle_rsp, bundle_obj in zip(resp.data,
                                          [bundle_public, bundle_private]):
            self.assertSerialized(bundle_obj, bundle_rsp)
コード例 #2
0
ファイル: test_bundle.py プロジェクト: daxtens/patchwork
    def test_list_version_1_0(self):
        """Validate that newer fields are dropped for older API versions."""
        create_bundle(public=True)

        resp = self.client.get(self.api_url(version='1.0'))
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        self.assertIn('url', resp.data[0])
        self.assertNotIn('web_url', resp.data[0])
コード例 #3
0
    def test_list_version_1_0(self):
        """Validate that newer fields are dropped for older API versions."""
        create_bundle(public=True)

        resp = self.client.get(self.api_url(version='1.0'))
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        self.assertIn('url', resp.data[0])
        self.assertNotIn('web_url', resp.data[0])
コード例 #4
0
    def _create_bundles(self):
        user = create_user(username='******')
        project = create_project(linkname='myproject')
        bundle_public = create_bundle(public=True, owner=user, project=project)
        bundle_private = create_bundle(
            public=False, owner=user, project=project
        )

        return user, project, bundle_public, bundle_private
コード例 #5
0
ファイル: test_bundle.py プロジェクト: stephenfin/patchwork
    def _create_bundles(self):
        user = create_user(username='******')
        project = create_project(linkname='myproject')
        bundle_public = create_bundle(public=True, owner=user,
                                      project=project)
        bundle_private = create_bundle(public=False, owner=user,
                                       project=project)

        return user, project, bundle_public, bundle_private
コード例 #6
0
    def test_update_no_patches(self):
        """Validate we handle updating only the name."""
        user, project, patch_a, patch_b = self._test_create_update()
        bundle = create_bundle(owner=user, project=project)

        bundle.append_patch(patch_a)
        bundle.append_patch(patch_b)

        self.assertEqual(1, Bundle.objects.all().count())
        self.assertEqual(2, len(Bundle.objects.first().patches.all()))

        resp = self.client.patch(
            self.api_url(bundle.id),
            {
                'name': 'hello-bundle',
                'public': True,
            },
        )
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(2, len(resp.data['patches']))
        self.assertEqual('hello-bundle', resp.data['name'])
        self.assertTrue(resp.data['public'])
        self.assertEqual(1, Bundle.objects.all().count())
        self.assertEqual(2, len(Bundle.objects.first().patches.all()))
        self.assertEqual('hello-bundle', Bundle.objects.first().name)
        self.assertTrue(Bundle.objects.first().public)
コード例 #7
0
    def test_detail(self):
        """Validate we can get a specific bundle."""
        bundle = create_bundle(public=True)

        resp = self.client.get(self.api_url(bundle.id))
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertSerialized(bundle, resp.data)
コード例 #8
0
ファイル: test_bundles.py プロジェクト: nickglobal/patchwork
 def setUp(self, count=3):
     self.user = create_user()
     self.client.login(username=self.user.username,
                       password=self.user.username)
     self.bundle = create_bundle(owner=self.user)
     self.project = create_project()
     self.patches = create_patches(count, project=self.project)
コード例 #9
0
ファイル: test_rest_api.py プロジェクト: alialnu/patchwork
    def test_detail(self):
        """Validate we can get a specific bundle."""
        bundle = create_bundle(public=True)

        resp = self.client.get(self.api_url(bundle.id))
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertSerialized(bundle, resp.data)
コード例 #10
0
ファイル: test_bundles.py プロジェクト: sandy-lcq/patchwork
 def setUp(self, count=3):
     self.user = create_user()
     self.client.login(username=self.user.username,
                       password=self.user.username)
     self.bundle = create_bundle(owner=self.user)
     self.project = create_project()
     self.patches = create_patches(count, project=self.project)
コード例 #11
0
ファイル: test_rest_api.py プロジェクト: alialnu/patchwork
    def test_list(self):
        """Validate we can list bundles."""
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(0, len(resp.data))

        user = create_user(username='******')
        project = create_project(linkname='myproject')
        bundle_public = create_bundle(public=True, owner=user,
                                      project=project)
        bundle_private = create_bundle(public=False, owner=user,
                                       project=project)

        # anonymous users
        # should only see the public bundle
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        bundle_rsp = resp.data[0]
        self.assertSerialized(bundle_public, bundle_rsp)

        # authenticated user
        # should see the public and private bundle
        self.client.force_authenticate(user=user)
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(2, len(resp.data))
        for bundle_rsp, bundle_obj in zip(
                resp.data, [bundle_public, bundle_private]):
            self.assertSerialized(bundle_obj, bundle_rsp)

        # test filtering by project
        resp = self.client.get(self.api_url(), {'project': 'myproject'})
        self.assertEqual([bundle_public.id, bundle_private.id],
                         [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'project': 'invalidproject'})
        self.assertEqual(0, len(resp.data))

        # test filtering by owner, both ID and username
        resp = self.client.get(self.api_url(), {'owner': user.id})
        self.assertEqual([bundle_public.id, bundle_private.id],
                         [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'owner': 'myuser'})
        self.assertEqual([bundle_public.id, bundle_private.id],
                         [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'owner': 'otheruser'})
        self.assertEqual(0, len(resp.data))
コード例 #12
0
    def test_list(self):
        """Validate we can list bundles."""
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(0, len(resp.data))

        user = create_user(username='******')
        project = create_project(linkname='myproject')
        bundle_public = create_bundle(public=True, owner=user, project=project)
        bundle_private = create_bundle(public=False,
                                       owner=user,
                                       project=project)

        # anonymous users
        # should only see the public bundle
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(1, len(resp.data))
        bundle_rsp = resp.data[0]
        self.assertSerialized(bundle_public, bundle_rsp)

        # authenticated user
        # should see the public and private bundle
        self.client.force_authenticate(user=user)
        resp = self.client.get(self.api_url())
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(2, len(resp.data))
        for bundle_rsp, bundle_obj in zip(resp.data,
                                          [bundle_public, bundle_private]):
            self.assertSerialized(bundle_obj, bundle_rsp)

        # test filtering by project
        resp = self.client.get(self.api_url(), {'project': 'myproject'})
        self.assertEqual([bundle_public.id, bundle_private.id],
                         [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'project': 'invalidproject'})
        self.assertEqual(0, len(resp.data))

        # test filtering by owner, both ID and username
        resp = self.client.get(self.api_url(), {'owner': user.id})
        self.assertEqual([bundle_public.id, bundle_private.id],
                         [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'owner': 'myuser'})
        self.assertEqual([bundle_public.id, bundle_private.id],
                         [x['id'] for x in resp.data])
        resp = self.client.get(self.api_url(), {'owner': 'otheruser'})
        self.assertEqual(0, len(resp.data))
コード例 #13
0
ファイル: test_user.py プロジェクト: nickglobal/patchwork
    def test_user_profile_bundles(self):
        bundle = create_bundle(owner=self.user)

        response = self.client.get(reverse('user-profile'))

        self.assertContains(response, 'Your Profile')
        self.assertContains(response, 'You have the following bundle')
        self.assertContains(response, bundle.get_absolute_url())
コード例 #14
0
    def test_user_profile_bundles(self):
        bundle = create_bundle(owner=self.user)

        response = self.client.get(reverse('user-profile'))

        self.assertContains(response, 'Your Profile')
        self.assertContains(response, 'You have the following bundle')
        self.assertContains(response, bundle.get_absolute_url())
コード例 #15
0
    def test_delete(self):
        """Validate we can delete an existing bundle."""
        user = create_user()
        bundle = create_bundle(owner=user)

        self.client.force_authenticate(user=user)

        resp = self.client.delete(self.api_url(bundle.id))
        self.assertEqual(status.HTTP_204_NO_CONTENT, resp.status_code)
        self.assertEqual(0, Bundle.objects.all().count())
コード例 #16
0
ファイル: test_bundle.py プロジェクト: wangxi11/patchwork
    def test_delete_anonymous(self):
        """Delete a bundle when not signed in.

        Ensure deletions can only be performed when signed in.
        """
        user, project, patch_a, patch_b = self._test_create_update(
            authenticate=False)
        bundle = create_bundle(owner=user, project=project)

        resp = self.client.delete(self.api_url(bundle.id))
        self.assertEqual(status.HTTP_404_NOT_FOUND, resp.status_code)
コード例 #17
0
ファイル: test_bundle.py プロジェクト: wangxi11/patchwork
    def test_update_anonymous(self):
        """Update an existing bundle when not signed in.

        Ensure updates can only be performed by signed in users.
        """
        user, project, patch_a, patch_b = self._test_create_update(
            authenticate=False)
        bundle = create_bundle(owner=user, project=project)

        resp = self.client.patch(self.api_url(bundle.id), {
            'name': 'hello-bundle',
            'patches': [patch_a.id, patch_b.id]
        })
        self.assertEqual(status.HTTP_404_NOT_FOUND, resp.status_code)
コード例 #18
0
ファイル: test_bundle.py プロジェクト: talih0/patchwork
    def test_update(self):
        """Validate we can update an existing bundle."""
        user, project, patch_a, patch_b = self._test_create_update()
        bundle = create_bundle(owner=user, project=project)

        self.assertEqual(1, Bundle.objects.all().count())
        self.assertEqual(0, len(Bundle.objects.first().patches.all()))

        resp = self.client.patch(self.api_url(bundle.id), {
            'name': 'hello-bundle',
            'patches': [patch_a.id, patch_b.id]
        })
        self.assertEqual(status.HTTP_200_OK, resp.status_code)
        self.assertEqual(2, len(resp.data['patches']))
        self.assertEqual('hello-bundle', resp.data['name'])
        self.assertEqual(1, Bundle.objects.all().count())
        self.assertEqual(2, len(Bundle.objects.first().patches.all()))
        self.assertEqual('hello-bundle', Bundle.objects.first().name)
コード例 #19
0
ファイル: test_bundles.py プロジェクト: sandy-lcq/patchwork
 def test_single_bundle(self):
     bundle = create_bundle(owner=self.user)
     bundle.save()
     response = self.client.get(reverse('user-bundles'))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.context['bundles']), 1)
コード例 #20
0
ファイル: test_bundle.py プロジェクト: daxtens/patchwork
    def test_detail_version_1_0(self):
        bundle = create_bundle(public=True)

        resp = self.client.get(self.api_url(bundle.id, version='1.0'))
        self.assertIn('url', resp.data)
        self.assertNotIn('web_url', resp.data)
コード例 #21
0
ファイル: test_bundles.py プロジェクト: nickglobal/patchwork
 def test_single_bundle(self):
     bundle = create_bundle(owner=self.user)
     bundle.save()
     response = self.client.get(reverse('user-bundles'))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(len(response.context['bundles']), 1)
コード例 #22
0
    def test_detail_version_1_0(self):
        bundle = create_bundle(public=True)

        resp = self.client.get(self.api_url(bundle.id, version='1.0'))
        self.assertIn('url', resp.data)
        self.assertNotIn('web_url', resp.data)