示例#1
0
 def test_bad_handlers_invalid_path(self):
     result = check_url_config(None)
     paths = [
         'django.views.bad_handler',
         'django.invalid_module.bad_handler',
         'invalid_module.bad_handler',
         'django',
     ]
     hints = [
         "Could not import '{}'. View does not exist in module django.views.",
         "Could not import '{}'. Parent module django.invalid_module does not exist.",
         "No module named 'invalid_module'",
         "Could not import '{}'. The path must be fully qualified.",
     ]
     for code, path, hint, error in zip([400, 403, 404, 500], paths, hints,
                                        result):
         with self.subTest('handler{}'.format(code)):
             self.assertEqual(
                 error,
                 Error(
                     "The custom handler{} view '{}' could not be imported."
                     .format(code, path),
                     hint=hint.format(path),
                     id='urls.E008',
                 ))
示例#2
0
 def test_check_view_not_class(self):
     self.assertEqual(check_url_config(None), [
         Error(
             "Your URL pattern 'missing_as_view' has an invalid view, pass "
             "EmptyCBV.as_view() instead of EmptyCBV.",
             id='urls.E009',
         ),
     ])
示例#3
0
 def test_failure_view_invalid_signature(self):
     msg = (
         "The CSRF failure view "
         "'check_framework.test_security.failure_view_with_invalid_signature' "
         "does not take the correct number of arguments.")
     self.assertEqual(
         csrf.check_csrf_failure_view(None),
         [Error(msg, id="security.E101")],
     )
示例#4
0
 def test_failure_view_import_error(self):
     self.assertEqual(
         csrf.check_csrf_failure_view(None),
         [
             Error(
                 "The CSRF failure view '' could not be imported.",
                 id='security.E102',
             )
         ],
     )
示例#5
0
 def test_bad_function_based_handlers(self):
     result = check_url_config(None)
     self.assertEqual(len(result), 4)
     for code, num_params, error in zip([400, 403, 404, 500], [2, 2, 2, 1], result):
         with self.subTest('handler{}'.format(code)):
             self.assertEqual(error, Error(
                 "The custom handler{} view 'check_framework.urls."
                 "bad_function_based_error_handlers.bad_handler' "
                 "does not take the correct number of arguments (request{})."
                 .format(code, ', exception' if num_params == 2 else ''),
                 id='urls.E007',
             ))
示例#6
0
 def test_bad_class_based_handlers(self):
     result = check_url_config(None)
     self.assertEqual(len(result), 4)
     for code, num_params, error in zip([400, 403, 404, 500], [2, 2, 2, 1], result):
         with self.subTest('handler%s' % code):
             self.assertEqual(error, Error(
                 "The custom handler%s view 'check_framework.urls."
                 "bad_class_based_error_handlers.HandlerView.as_view."
                 "<locals>.view' does not take the correct number of "
                 "arguments (request%s)." % (
                     code,
                     ', exception' if num_params == 2 else '',
                 ),
                 id='urls.E007',
             ))
示例#7
0
 def test_ambiguous_stage(self):
     with self.settings(
             MIGRATION_MODULES={"tests": "tests.test_migrations.ambiguous"
                                }):
         checks = run_checks(app_configs=[apps.get_app_config("tests")],
                             tags={"migrations"})
     self.assertEqual(len(checks), 1)
     self.assertEqual(
         checks[0],
         Error(
             msg=
             "Cannot automatically determine stage of tests.0001_initial.",
             hint=self.hint,
             obj=("tests", "0001_initial"),
             id="migrations.0001",
         ),
     )
示例#8
0
def unique_slugify(
    instance,
    values,
    queryset=None,
    slug_field_name="slug",
    slug_seperator="-",
    max_num=1000,
):
    slug_field = instance._meta.get_field(slug_field_name)
    max_len = slug_field.max_length
    slug = slugify(values)
    if max_len:
        slug = slug[:max_len]

    if queryset is None:
        queryset = instance.__class__._default_manager.all()

    if instance.pk:
        queryset = queryset.exclude(pk=instance.pk)

    original_slug = slug

    num = 1
    while len(queryset.filter(**{slug_field_name: slug})) != 0:
        slug = original_slug
        end = f"{slug_seperator}{num}"
        if len(slug) + len(end) > max_len:
            overflow = len(slug) + len(end) - max_len
            slug = slug[:-overflow]

        slug = "".join([slug, end])

        num += 1
        if num > max_num:
            raise Error(f"Over {max_num} slugs with the same base!")

    return slug
示例#9
0
    def post(self, request, *args, **kwargs):
        error = None
        params = json.loads(request.body)
        room_id = params.get('room_id')
        print(params)

        try:
            if room_id is None:
                raise Error('Комната не найдена')
            room = Game.objects.get(id=room_id)
            room.step = 1
            room.level = 3
            room.game_stage = 1
            players_info = PlayerGameInfo.objects.filter(room_id=room.id)
            senioring = 0
            for player in players_info:
                player.capital = 10000
                player.esm = 4
                player.egp = 2
                player.simple_fabric_count = 2
                player.senioring = senioring
                senioring += 1
                if player.player_id.id == request.user.id:
                    player.senior_player = True

                player.save()
            print('game_start')
            room.log = 'Игра началась'
            room.save()
        except BaseException as err:
            print(err)
            error = str(err)

        return JsonResponse({
            'error': error
        })