예제 #1
0
    def test_user_can_read_only_itself(self):
        resp = self.get(
            ('%s%s/') % (self.USER_API_URL, self.logged_user.user.pk))
        assert_valid_JSON_response(resp)

        user = self.get_user_obj()
        resp = self.get(('%s%s/') % (self.USER_API_URL, user.pk))
        assert_http_not_found(resp)
예제 #2
0
    def test_user_can_update_only_itself(self):
        user = self.get_user_obj()
        resp = self.put('%s%s/' % (self.USER_API_URL, user.pk), data={})
        assert_http_not_found(resp)

        user = self.logged_user.user
        resp = self.put('%s%s/' % (self.USER_API_URL, user.pk), data={})
        assert_valid_JSON_response(resp)
예제 #3
0
 def test_404_exception(self):
     self.logged_user.user.perms.add_perm(
         'core.issue_tracker.IssueIsCore.read')
     for accept_type in self.ACCEPT_TYPES:
         resp = self.get('%s%s/' % (self.ISSUE_API_URL, 5),
                         headers={'HTTP_ACCEPT': accept_type})
         assert_in(accept_type, resp['Content-Type'])
         assert_http_not_found(resp)
예제 #4
0
    def test_only_superuser_may_edit_user(self):
        user = self.get_user_obj()
        resp = self.get('%s%s/' % (self.USER_UI_URL, user.pk))
        assert_http_not_found(resp)

        CHANGED_USERNAME = '******'
        self.post('%s%s/' % (self.USER_UI_URL, user.pk), data={'detail-is-user-username': CHANGED_USERNAME})
        assert_http_not_found(resp)
        assert_not_equal(User.objects.get(pk=user.pk).username, CHANGED_USERNAME)
예제 #5
0
 def test_read_user_with_more_headers_accept_types(self, number, data):
     resp = self.post(self.USER_API_URL, data=data)
     assert_valid_JSON_created_response(resp)
     pk = self.get_pk(resp)
     for accept_type in self.ACCEPT_TYPES:
         resp = self.get(self.USER_API_URL, headers={'HTTP_ACCEPT': accept_type})
         assert_in(accept_type, resp['Content-Type'])
         resp = self.get('%s%s/' % (self.USER_API_URL, pk), headers={'HTTP_ACCEPT': accept_type})
         assert_true(accept_type in resp['Content-Type'])
         resp = self.get('%s1050/' % self.USER_API_URL, headers={'HTTP_ACCEPT': accept_type})
         assert_true(accept_type in resp['Content-Type'])
         assert_http_not_found(resp)
예제 #6
0
    def test_delete_user(self, number, data):
        resp = self.post(self.USER_API_URL, data=data)
        assert_valid_JSON_created_response(resp)

        pk = self.get_pk(resp)
        resp = self.delete('%s%s/' % (self.USER_API_URL, pk))
        assert_http_accepted(resp)

        resp = self.get(self.USER_API_URL)
        assert_equal(len(self.deserialize(resp)), 0)

        resp = self.delete('%s%s/' % (self.USER_API_URL, pk))
        assert_http_not_found(resp)
예제 #7
0
    def test_update_error_user(self, number, data):
        resp = self.post(self.USER_API_URL, data=data)
        assert_valid_JSON_created_response(resp)
        pk = self.get_pk(resp)

        assert_valid_JSON_response(self.put('{}{}/'.format(self.USER_API_URL, pk),
                                            data={'email': '*****@*****.**'}))

        assert_http_bad_request(
            self.put('{}{}/'.format(self.USER_API_URL, pk), data={'email': 'invalid_email'})
        )

        assert_http_not_found(self.put('{}{}/'.format(self.USER_API_URL, 0), data={}))
예제 #8
0
    def test_read_user_with_more_querystring_accept_types(self, number, data):
        user = UserFactory()
        [issue.watched_by.add(user) for issue in (IssueFactory() for _ in range(10))]

        for accept_type in self.ACCEPT_TYPES:
            resp = self.get('%s?_accept=%s' % (self.USER_API_URL, accept_type))
            assert_in(accept_type, resp['Content-Type'])
            resp = self.get('%s%s/?_accept=%s' % (self.USER_API_URL, user.pk, accept_type),
                            headers={'HTTP_ACCEPT': accept_type})
            assert_true(accept_type in resp['Content-Type'])
            resp = self.get('%s1050/?_accept=%s' % (self.USER_API_URL, accept_type),
                            headers={'HTTP_ACCEPT': accept_type})
            assert_true(accept_type in resp['Content-Type'])
            assert_http_not_found(resp)
    def test_should_delete_data_from_resource(self, resource_name, resource,
                                              model):
        for i in range(self.iteration):
            inst = self.new_instance(model)

            url = resource._resource_url(inst.pk)

            if not resource(
                    self.get_request_with_user(
                        self.r_factory.delete(url))).has_delete_permission(
                            obj=inst):
                break

            resp = self.delete(url)
            assert_http_accepted(
                resp,
                'REST delete of model: {}\n response: {}'.format(model, resp))
            resp = self.get(url)
            assert_http_not_found(
                resp,
                'REST get (should not found) of model: {}\n response: {}'.
                format(model, resp))
예제 #10
0
 def test_only_superuser_can_get_number_of_other_users_issues(self):
     user = self.get_user_obj()
     resp = self.get(self.USER_ISSUES_API_URL % {'user_pk': user.pk})
     assert_http_not_found(resp)
예제 #11
0
 def test_404_exception(self):
     for accept_type in self.ACCEPT_TYPES:
         resp = self.get('%s%s/' % (self.ISSUE_API_URL, 5), headers={'HTTP_ACCEPT': accept_type})
         assert_in(accept_type, resp['Content-Type'])
         assert_http_not_found(resp)
예제 #12
0
 def test_issue_should_return_not_found_because_can_add_is_disabled(self):
     assert_http_not_found(self.get('%sadd/' % self.ISSUE_UI_URL))
     assert_http_not_found(self.post('%sadd/' % self.ISSUE_UI_URL, data={}))
예제 #13
0
 def test_404_exception(self):
     for accept_type in self.ACCEPT_TYPES:
         resp = self.get('%s%s/' % (self.ISSUE_API_URL, 5), headers={'HTTP_ACCEPT': accept_type})
         assert_in(accept_type, resp['Content-Type'])
         assert_http_not_found(resp)