Exemplo n.º 1
0
    def test_atomic_add_delete_and_set_issues_with_errors(self, number, issue_data, user_data):
        user_data['createdIssues'] = {'set': (None, '', None, {}, [None])}
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_http_bad_request(resp)
        assert_in('set', self.deserialize(resp).get('messages', {}).get('errors', {}).get('createdIssues', {}))

        user_data['createdIssues'] = {'add': (None, '', None, [], {}, {'id': 500}),
                                      'remove': (None, '', None, {}, {'id': 500}, [])}
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_http_bad_request(resp)
        assert_in('add', self.deserialize(resp).get('messages', {}).get('errors', {}).get('createdIssues', {}))
        assert_in('remove', self.deserialize(resp).get('messages', {}).get('errors', {}).get('createdIssues', {}))

        user_data['createdIssues'] = {'add': None, 'remove': None}
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_http_bad_request(resp)
        assert_in('add', self.deserialize(resp).get('messages', {}).get('errors', {}).get('createdIssues', {}))
        assert_in('remove', self.deserialize(resp).get('messages', {}).get('errors', {}).get('createdIssues', {}))

        user_data['createdIssues'] = (self.get_issue_data(), self.get_issue_data(), 'invalid')
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_equal(
            self.deserialize(resp).get('messages', {}).get('errors', {}).get('createdIssues')[0]['_index'], 2
        )
        assert_http_bad_request(resp)
Exemplo n.º 2
0
 def test_issue_resource_should_support_only_xml_and_json_converters(self, number, data):
     for accept_type in self.ACCEPT_TYPES:
         resp = self.get('%s?_accept=%s' % (self.ISSUE_API_URL, accept_type))
         if accept_type in self.ACCEPT_TYPES[:2]:
             assert_in(accept_type, resp['Content-Type'])
         else:
             assert_in(self.ACCEPT_TYPES[0], resp['Content-Type'])
Exemplo n.º 3
0
 def test_create_issue_via_user_one_to_one_renamed_fail(
         self, number, issue_data, user_data):
     user_data['leading_issue_renamed'] = {}
     resp = self.post(self.USER_WITH_FORM_API_URL, data=user_data)
     assert_http_bad_request(resp)
     assert_in('leading_issue_renamed',
               self.deserialize(resp).get('messages', {}).get('errors'))
Exemplo n.º 4
0
 def test_reverse_with_defined_field_created_issues_renamed_fail(self, number, issue_data, user_data):
     issues_before_count = Issue.objects.all().count()
     user_data['created_issues_renamed'] = {'add': (self.get_issue_data(),
                                                    self.get_issue_data(), self.get_issue_data())}
     resp = self.post(self.USER_WITH_FORM_API_URL, data=user_data)
     assert_http_bad_request(resp)
     assert_in('created_issues_renamed', self.deserialize(resp).get('messages', {}).get('errors'))
     assert_equal(issues_before_count + 0, Issue.objects.all().count())
Exemplo n.º 5
0
 def test_filename_and_content_type_can_be_evaluated_from_file_content(self, number, data):
     data['contract'] = {
         'content': base64.b64encode(
             ('Contract of %s code: šří+áýšé' % data['email']).encode('utf-8')
         ).decode('utf-8')
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_valid_JSON_created_response(resp)
     assert_in('.txt', self.deserialize(resp)['contract']['filename'])
Exemplo n.º 6
0
    def test_create_user_with_file_url(self, number, data):
        resp = self.get_file_url_response(data)

        assert_valid_JSON_created_response(resp)
        data = self.deserialize(resp)

        assert_not_equal(data['contract'], None)
        assert_in('filename', data['contract'])
        assert_in('url', data['contract'])
        assert_equal(data['contract']['content_type'], 'application/pdf')
Exemplo n.º 7
0
 def test_filename_and_content_type_can_be_evaluated_from_file_content(
         self, number, data):
     data['contract'] = {
         'content':
         base64.b64encode(('Contract of %s code: šří+áýšé' %
                           data['email']).encode('utf-8')).decode('utf-8')
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_valid_JSON_created_response(resp)
     assert_in('.txt', self.deserialize(resp)['contract']['filename'])
Exemplo n.º 8
0
 def test_should_raise_bad_request_if_url_is_not_valid(self, number, data):
     data['contract'] = {
         'filename': 'testfile.pdf',
         'url': 'hs://foo.bar/testfile.pdf',
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     assert_equal(errors['contract']['url'], ugettext('Enter a valid URL.'))
Exemplo n.º 9
0
 def test_should_raise_bad_request_if_url_is_not_valid(self, number, data):
     data['contract'] = {
         'filename': 'testfile.pdf',
         'url': 'hs://foo.bar/testfile.pdf',
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     assert_equal(errors['contract']['url'], ugettext('Enter a valid URL.'))
Exemplo n.º 10
0
    def test_create_user_with_file_url(self, number, data):
        resp = self.get_file_url_response(data)

        assert_valid_JSON_created_response(resp)
        data = self.deserialize(resp)

        assert_not_equal(data['contract'], None)
        assert_in('filename', data['contract'])
        assert_in('url', data['contract'])
        assert_equal(data['contract']['content_type'], 'application/pdf')
Exemplo n.º 11
0
 def test_should_raise_bad_request_if_file_content_is_not_in_base64(self, number, data):
     data['contract'] = {
         'content_type': 'text/plain',
         'filename': 'contract.txt',
         'content': 'abc',
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     assert_equal(errors['contract']['content'], ugettext('File content must be in base64 format'))
Exemplo n.º 12
0
 def test_should_raise_bad_request_if_file_is_unreachable(self, number, data):
     url = 'http://foo.bar/testfile.pdf'
     data['contract'] = {
         'filename': 'testfile.pdf',
         'url': url,
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     assert_equal(errors['contract']['url'], ugettext('File is unreachable on the URL address'))
Exemplo n.º 13
0
    def test_create_issue_via_user_one_to_one_bad_request(self, number, issue_data, user_data):
        issue_data['created_by'] = self.get_user_data()
        user_data['leading_issue'] = {}
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_http_bad_request(resp)
        assert_in('leading_issue', self.deserialize(resp).get('messages', {}).get('errors'))

        user_data['leading_issue'] = 'bad data'
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_http_bad_request(resp)
        assert_in('leading_issue', self.deserialize(resp).get('messages', {}).get('errors'))
Exemplo n.º 14
0
 def test_should_raise_bad_request_if_required_items_are_not_provided(
         self, number, data):
     REQUIRED_ITEMS = {'content'}
     REQUIRED_URL_ITEMS = {'url'}
     data['contract'] = {}
     resp = self.post(self.USER_API_URL, data=data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     msg = ugettext('File data item must contains {} or {}').format(
         ', '.join(REQUIRED_ITEMS), ', '.join(REQUIRED_URL_ITEMS))
     assert_equal(errors['contract'], msg)
Exemplo n.º 15
0
 def test_reverse_with_defined_field_created_issues_renamed_fail(
         self, number, issue_data, user_data):
     issues_before_count = Issue.objects.all().count()
     user_data['created_issues_renamed'] = {
         'add': (self.get_issue_data(), self.get_issue_data(),
                 self.get_issue_data())
     }
     resp = self.post(self.USER_WITH_FORM_API_URL, data=user_data)
     assert_http_bad_request(resp)
     assert_in('created_issues_renamed',
               self.deserialize(resp).get('messages', {}).get('errors'))
     assert_equal(issues_before_count + 0, Issue.objects.all().count())
Exemplo n.º 16
0
    def test_atomic_add_delete_and_set_issues_with_errors(
            self, number, issue_data, user_data):
        user_data['createdIssues'] = {'set': (None, '', None, {}, [None])}
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_http_bad_request(resp)
        assert_in(
            'set',
            self.deserialize(resp).get('messages',
                                       {}).get('errors',
                                               {}).get('createdIssues', {}))

        user_data['createdIssues'] = {
            'add': (None, '', None, [], {}, {
                'id': 500
            }),
            'remove': (None, '', None, {}, {
                'id': 500
            }, [])
        }
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_http_bad_request(resp)
        assert_in(
            'add',
            self.deserialize(resp).get('messages',
                                       {}).get('errors',
                                               {}).get('createdIssues', {}))
        assert_in(
            'remove',
            self.deserialize(resp).get('messages',
                                       {}).get('errors',
                                               {}).get('createdIssues', {}))

        user_data['createdIssues'] = {'add': None, 'remove': None}
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_http_bad_request(resp)
        assert_in(
            'add',
            self.deserialize(resp).get('messages',
                                       {}).get('errors',
                                               {}).get('createdIssues', {}))
        assert_in(
            'remove',
            self.deserialize(resp).get('messages',
                                       {}).get('errors',
                                               {}).get('createdIssues', {}))

        user_data['createdIssues'] = (self.get_issue_data(),
                                      self.get_issue_data(), 'invalid')
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_equal(
            self.deserialize(resp).get('messages', {}).get(
                'errors', {}).get('createdIssues')[0]['_index'], 2)
        assert_http_bad_request(resp)
Exemplo n.º 17
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)
Exemplo n.º 18
0
 def test_should_raise_bad_request_if_required_items_are_not_provided(self, number, data):
     REQUIRED_ITEMS = {'content'}
     REQUIRED_URL_ITEMS = {'url'}
     data['contract'] = {}
     resp = self.post(self.USER_API_URL, data=data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     msg = ugettext('File data item must contains {} or {}').format(
               ', '.join(REQUIRED_ITEMS), ', '.join(REQUIRED_URL_ITEMS)
           )
     assert_equal(errors['contract'], msg)
Exemplo n.º 19
0
 def test_should_raise_bad_request_if_file_content_is_not_in_base64(
         self, number, data):
     data['contract'] = {
         'content_type': 'text/plain',
         'filename': 'contract.txt',
         'content': 'abc',
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     assert_equal(errors['contract']['content'],
                  ugettext('File content must be in base64 format'))
Exemplo n.º 20
0
 def test_should_raise_bad_request_if_file_is_unreachable(
         self, number, data):
     url = 'http://foo.bar/testfile.pdf'
     data['contract'] = {
         'filename': 'testfile.pdf',
         'url': url,
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     assert_equal(errors['contract']['url'],
                  ugettext('File is unreachable on the URL address'))
Exemplo n.º 21
0
    def test_create_issue_via_user_one_to_one_bad_request(
            self, number, issue_data, user_data):
        issue_data['created_by'] = self.get_user_data()
        user_data['leading_issue'] = {}
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_http_bad_request(resp)
        assert_in('leading_issue',
                  self.deserialize(resp).get('messages', {}).get('errors'))

        user_data['leading_issue'] = 'bad data'
        resp = self.post(self.USER_API_URL, data=user_data)
        assert_http_bad_request(resp)
        assert_in('leading_issue',
                  self.deserialize(resp).get('messages', {}).get('errors'))
Exemplo n.º 22
0
 def test_should_raise_bad_request_if_response_is_too_large(self, number, data):
     data['contract'] = {
         'content_type': 'text/plain',
         'filename': 'contract.txt',
         'content': base64.b64encode(
             ('Contract of %s code: šří+áýšé' % data['email']).encode('utf-8')
         ).decode('utf-8')
     }
     resp = self.get_file_url_response(data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     msg = ugettext('Response too large, maximum size is {} bytes').format(pyston_settings.FILE_SIZE_LIMIT)
     assert_equal(errors['contract']['url'], msg)
Exemplo n.º 23
0
 def test_create_user_with_file_and_not_defined_content_type(self, number, data):
     data['contract'] = {
         'filename': 'contract.txt',
         'content': base64.b64encode(
             ('Contract of %s code: šří+áýšé' % data['email']).encode('utf-8')
         ).decode('utf-8')
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_valid_JSON_created_response(resp)
     data = self.deserialize(resp)
     assert_not_equal(data['contract'], None)
     assert_in('filename', data['contract'])
     assert_in('url', data['contract'])
     assert_equal(data['contract']['content_type'], 'text/plain')
Exemplo n.º 24
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)
Exemplo n.º 25
0
 def test_should_raise_bad_request_with_invalid_filename(self, number, data):
     data['contract'] = {
         'filename': 'contract',
         'content': base64.b64encode(
             ('Contract of %s code: šří+áýšé' % data['email']).encode('utf-8')
         ).decode('utf-8')
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     assert_equal(
         errors['contract'],
         ugettext('Content type cannot be evaluated from input data please send it')
     )
Exemplo n.º 26
0
 def test_create_user_with_file_and_not_defined_content_type(
         self, number, data):
     data['contract'] = {
         'filename':
         'contract.txt',
         'content':
         base64.b64encode(('Contract of %s code: šří+áýšé' %
                           data['email']).encode('utf-8')).decode('utf-8')
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_valid_JSON_created_response(resp)
     data = self.deserialize(resp)
     assert_not_equal(data['contract'], None)
     assert_in('filename', data['contract'])
     assert_in('url', data['contract'])
     assert_equal(data['contract']['content_type'], 'text/plain')
Exemplo n.º 27
0
 def test_should_raise_bad_request_with_invalid_filename(
         self, number, data):
     data['contract'] = {
         'filename':
         'contract',
         'content':
         base64.b64encode(('Contract of %s code: šří+áýšé' %
                           data['email']).encode('utf-8')).decode('utf-8')
     }
     resp = self.post(self.USER_API_URL, data=data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     assert_equal(
         errors['contract'],
         ugettext(
             'Content type cannot be evaluated from input data please send it'
         ))
Exemplo n.º 28
0
 def test_should_raise_bad_request_if_response_is_too_large(
         self, number, data):
     data['contract'] = {
         'content_type':
         'text/plain',
         'filename':
         'contract.txt',
         'content':
         base64.b64encode(('Contract of %s code: šří+áýšé' %
                           data['email']).encode('utf-8')).decode('utf-8')
     }
     resp = self.get_file_url_response(data)
     assert_http_bad_request(resp)
     errors = self.deserialize(resp).get('messages', {}).get('errors')
     assert_in('contract', errors)
     msg = ugettext('Response too large, maximum size is {} bytes').format(
         pyston_settings.FILE_SIZE_LIMIT)
     assert_equal(errors['contract']['url'], msg)
Exemplo n.º 29
0
    def test_atomic_add_delete_and_set_issue_with_watchers_with_errors(
            self, number, issue_data, user_data):
        issue_data['created_by'] = user_data
        issue_data['watched_by'] = {
            'add': [None, [], 'invalid_text', {}],
            'remove': [None, 'invalid_text', 5, {}]
        }
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in(
            'add',
            self.deserialize(resp).get('messages',
                                       {}).get('errors').get('watched_by'))
        assert_in(
            'remove',
            self.deserialize(resp).get('messages',
                                       {}).get('errors').get('watched_by'))

        issue_data['watched_by'] = {'remove': ['invalid_text', 5, {}]}
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in(
            'remove',
            self.deserialize(resp).get('messages',
                                       {}).get('errors').get('watched_by'))

        issue_data['created_by'] = user_data
        issue_data['watched_by'] = {'set': [None, [], 'invalid_text', {}]}
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in(
            'set',
            self.deserialize(resp).get('messages',
                                       {}).get('errors').get('watched_by'))

        issue_data['created_by'] = user_data
        issue_data['watched_by'] = {'set': ''}
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in(
            'set',
            self.deserialize(resp).get('messages',
                                       {}).get('errors').get('watched_by'))

        issue_data['created_by'] = user_data
        issue_data['watched_by'] = {'set': None}
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in(
            'set',
            self.deserialize(resp).get('messages',
                                       {}).get('errors').get('watched_by'))

        issue_data['created_by'] = user_data
        issue_data['watched_by'] = {'set': {}}
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in(
            'set',
            self.deserialize(resp).get('messages',
                                       {}).get('errors').get('watched_by'))

        issue_data['created_by'] = user_data
        issue_data['watched_by'] = [{'invalid': 'invalid2'}]
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_equal(
            self.deserialize(resp).get(
                'messages', {}).get('errors')['watched_by'][0]['_index'], 0)
Exemplo n.º 30
0
    def test_create_user_with_file_url_too_large(self, number, data):
        resp = self.get_file_url_response(data)

        assert_http_bad_request(resp)
        assert_in('contract', self.deserialize(resp).get('messages', {}).get('errors', {}))
Exemplo n.º 31
0
 def test_create_issue_via_user_one_to_one_renamed_fail(self, number, issue_data, user_data):
     user_data['leading_issue_renamed'] = {}
     resp = self.post(self.USER_WITH_FORM_API_URL, data=user_data)
     assert_http_bad_request(resp)
     assert_in('leading_issue_renamed', self.deserialize(resp).get('messages', {}).get('errors'))
Exemplo n.º 32
0
    def test_atomic_add_delete_and_set_issue_with_watchers_with_errors(self, number, issue_data, user_data):
        issue_data['created_by'] = user_data
        issue_data['watched_by'] = {'add': [None, [], 'invalid_text', {}], 'remove': ['invalid_text', 5, {}]}
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in('add', self.deserialize(resp).get('messages', {}).get('errors').get('watched_by'))
        assert_in('remove', self.deserialize(resp).get('messages', {}).get('errors').get('watched_by'))

        issue_data['created_by'] = user_data
        issue_data['watched_by'] = {'set': [None, [], 'invalid_text', {}]}
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in('set', self.deserialize(resp).get('messages', {}).get('errors').get('watched_by'))

        issue_data['created_by'] = user_data
        issue_data['watched_by'] = {'set': ''}
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in('set', self.deserialize(resp).get('messages', {}).get('errors').get('watched_by'))

        issue_data['created_by'] = user_data
        issue_data['watched_by'] = {'set': None}
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in('set', self.deserialize(resp).get('messages', {}).get('errors').get('watched_by'))

        issue_data['created_by'] = user_data
        issue_data['watched_by'] = {'set': {}}
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_in('set', self.deserialize(resp).get('messages', {}).get('errors').get('watched_by'))

        issue_data['created_by'] = user_data
        issue_data['watched_by'] = [{'invalid': 'invalid2'}]
        resp = self.post(self.ISSUE_API_URL, data=issue_data)
        assert_http_bad_request(resp)
        assert_equal(self.deserialize(resp).get('messages', {}).get('errors')['watched_by'][0]['_index'], 0)
Exemplo n.º 33
0
    def test_create_user_with_file_url_too_large(self, number, data):
        resp = self.get_file_url_response(data)

        assert_http_bad_request(resp)
        assert_in('contract',
                  self.deserialize(resp).get('messages', {}).get('errors', {}))