Beispiel #1
0
    def setUp(self):
        # GIVEN published monitoring, organization and approved task
        monitoring = mommy.make(Monitoring, status=MONITORING_PUBLISHED)
        organization = mommy.make(Organization, monitoring=monitoring)
        task = mommy.make(Task, organization=organization, status=Task.TASK_APPROVED)

        # AND expertA account
        expertA = User.objects.create_user('expertA', '*****@*****.**', 'password')
        expertA.profile.is_expertA = True

        # AND kwargs to reverse view urls
        self.kwargs = {
            'monitoring_pk': monitoring.pk,
            'task_pk': task.pk,
            'org_pk': organization.pk
        }

        # AND dict of all urlpatterns by urlname
        self.patterns_by_name = dict((p.name, p) for p in get_named_patterns())
Beispiel #2
0
    def setUp(self):
        # GIVEN published monitoring, organization and approved task
        monitoring = mommy.make(Monitoring, status=MONITORING_PUBLISHED)
        organization = mommy.make(Organization, monitoring=monitoring)
        task = mommy.make(Task, organization=organization, status=Task.TASK_APPROVED)

        # AND superuser account
        admin = User.objects.create_superuser('admin', '*****@*****.**', 'password')
        admin.groups.add(Group.objects.get(name=admin.profile.expertA_group))

        # AND kwargs to reverse view urls
        self.kwargs = {
            'monitoring_pk': monitoring.pk,
            'task_pk': task.pk,
            'org_pk': organization.pk
        }

        # AND dict of all urlpatterns by urlname
        self.patterns_by_name = dict((p.name, p) for p in get_named_patterns())
Beispiel #3
0
class CanonicalViewKwargsTestCase(TestCase):
    # Url patterns and views should use and accept only canonical kwargs

    test_patterns = {
        p.name: p
        for p in get_named_patterns() if p._full_name.startswith('exmo2010:')
    }

    canonical_kwargs = {
        'monitoring_pk',
        'score_pk',
        'parameter_pk',
        'task_pk',
        'org_pk',
        'clarification_pk',
        'claim_pk',
        'obs_group_pk',
        'monitoring_status',  # for monitorings_list
        'activation_key',  # for registration_activate
        'user_pk',  # for password_reset_confirm
        'token',  # for password_reset_confirm
        'report_type',  # for public_stats_*
        'print_report_type',  # for task_scores
    }

    @parameterized.expand(test_patterns)
    def test_urlpattern(self, name):
        pat = self.test_patterns[name]

        if pat.regex.groups > len(pat.regex.groupindex):
            raise Exception(
                'Urlpattern ("%s", "%s") uses positional args and can\'t be reversed for this test. '
                'It should be modified to use only kwargs or excluded from this test and tested explicitly'
                % (pat.regex.pattern, pat.name))
        unknown_kwargs = set(pat.regex.groupindex) - self.canonical_kwargs
        if unknown_kwargs:
            raise Exception(
                'Urlpattern ("%s", "%s") uses unknown kwargs and can\'t be reversed for this test. '
                'These kwargs should be added to this test\'s auto_pattern_kwargs in setUp'
                % (pat.regex.pattern, pat.name))
Beispiel #4
0
    def setUp(self):
        # GIVEN published monitoring, organization and approved task
        monitoring = mommy.make(Monitoring, status=MONITORING_PUBLISHED)
        organization = mommy.make(Organization, monitoring=monitoring)
        task = mommy.make(Task,
                          organization=organization,
                          status=Task.TASK_APPROVED)

        # AND expertA account
        expertA = User.objects.create_user('expertA', '*****@*****.**',
                                           'password')
        expertA.profile.is_expertA = True

        # AND kwargs to reverse view urls
        self.kwargs = {
            'monitoring_pk': monitoring.pk,
            'task_pk': task.pk,
            'org_pk': organization.pk
        }

        # AND dict of all urlpatterns by urlname
        self.patterns_by_name = dict((p.name, p) for p in get_named_patterns())
Beispiel #5
0
def crumbs_dict(crumbs_tree):
    '''
    Constructs flat crumbs_dict from `crumbs_tree`
    crumbs_dict is a dict of Crumb nodes by urlnames
    `crumbs_tree` should have following structure:
    {
        urlname: (title, {
            urlname: title,  # leaf node without children
            urlname: (title, { ... }),  # node with more children
            ... ,
        }),
        ... ,
    }
    '''
    crumbs_dict = {}
    patterns = dict((p.name, p) for p in get_named_patterns())
    for urlname, title, parents in traverse_tree(crumbs_tree):
        pat = patterns[urlname]
        if len(pat.regex.groupindex) == 0:
            # pattern does not have arguments and can be reversed right now as optimization
            pat = reverse(pat._full_name)
        crumbs_dict[urlname] = Crumb(urlname, title, pat, parents)
    return crumbs_dict
Beispiel #6
0
def crumbs_dict(crumbs_tree):
    '''
    Constructs flat crumbs_dict from `crumbs_tree`
    crumbs_dict is a dict of Crumb nodes by urlnames
    `crumbs_tree` should have following structure:
    {
        urlname: (title, {
            urlname: title,  # leaf node without children
            urlname: (title, { ... }),  # node with more children
            ... ,
        }),
        ... ,
    }
    '''
    crumbs_dict = {}
    patterns = dict((p.name, p) for p in get_named_patterns())
    for urlname, title, parents in traverse_tree(crumbs_tree):
        pat = patterns[urlname]
        if len(pat.regex.groupindex) == 0:
            # pattern does not have arguments and can be reversed right now as optimization
            pat = reverse_lazy(pat._full_name)
        crumbs_dict[urlname] = Crumb(urlname, title, pat, parents)
    return crumbs_dict