Beispiel #1
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()
        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)
Beispiel #2
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])
Beispiel #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])
Beispiel #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
Beispiel #5
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
Beispiel #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)
Beispiel #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)
Beispiel #8
0
 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)
Beispiel #9
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)
Beispiel #10
0
 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)
Beispiel #11
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))
Beispiel #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))
Beispiel #13
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())
    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())
Beispiel #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())
Beispiel #16
0
    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)
Beispiel #17
0
    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)
Beispiel #18
0
    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)
Beispiel #19
0
 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)
Beispiel #20
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)
Beispiel #21
0
 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)
Beispiel #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)