django.urls.resolve - python examples

Here are the examples of the python api django.urls.resolve taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

145 Examples 7

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
Django Redirect Functions | Django ...
Django Redirect Functions | Django Tips#1
    def test_unauthenticated_get_request(self):
        url = reverse('rule-details', kwargs={'group_name': self.group1.name, 'rule_pk': self.rule.id})
        request = self.factory.get(url)
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name, rule_pk=self.rule.id)
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_member_get_request(self):
        url = reverse('group-sources', kwargs={'group_name': self.group.name})
        request = self.factory.get(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user3)
        response = self.view(request, group_name=self.group.name)
        self.astertEqual(response.status_code, 200)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_delete_request(self):
        url = reverse('rule-comment-details', kwargs={'group_name': self.group1.name, 
                                                      'rule_pk': self.rule.id,
                                                      'comment_pk': self.comment.id})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, comment_pk=self.comment.id)
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_nonadmin_post_request(self):
        url = reverse('ruleset-bulk', kwargs={'group_name': self.group1.name})
        request = self.factory.post(url, self.data)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group1.name)

        self.astertEqual(response.status_code, 200)
        self.astertEqual(response.data['rule_upload_count'], 1)

        rule = YaraRule.objects.get(name='dummy')
        self.astertEqual(rule.status, self.group1.groupmeta.nonprivileged_submission_status)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_owner_delete_request(self):
        url = reverse('group-categories', kwargs={'group_name': self.group.name})
        query_string = urlencode({'category': 'old_category'})
        request = self.factory.delete(url + '?' + query_string)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)

        self.astertTrue('old_category' in self.group.groupmeta.category_options)
        response = self.view(request, group_name=self.group.name)

        self.group.groupmeta.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertFalse('old_category' in self.group.groupmeta.category_options)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_delete_request(self):
        url = reverse('group-sources', kwargs={'group_name': self.group.name})
        query_string = urlencode({'source': 'old_source'})
        request = self.factory.delete(url + '?' + query_string)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)

        self.astertTrue('old_source' in self.group.groupmeta.source_options)
        response = self.view(request, group_name=self.group.name)

        self.group.groupmeta.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertFalse('old_source' in self.group.groupmeta.source_options)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_owner_get_request(self):
        url = reverse('group-sources', kwargs={'group_name': self.group.name})
        request = self.factory.get(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group.name)
        self.astertEqual(response.status_code, 200)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_member_get_request(self):
        url = reverse('rule-comments', kwargs={'group_name': self.group1.name, 
                                               'rule_pk': self.rule.id})
        request = self.factory.get(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group1.name, rule_pk=self.rule.id)

        self.astertEqual(response.status_code, 200)
        self.astertEqual(len(response.data), 1)
        self.astertEqual(response.data[0]['content'], 'Comment Data')

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_post_request(self):
        url = reverse('rule-comments', kwargs={'group_name': self.group1.name, 
                                               'rule_pk': self.rule.id})
        request = self.factory.post(url, {})
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name, rule_pk=self.rule.id)
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_put_request(self):
        url = reverse('rule-comment-details', kwargs={'group_name': self.group1.name, 
                                                      'rule_pk': self.rule.id,
                                                      'comment_pk': self.comment.id})
        request = self.factory.put(url, {'content': 'Updated Comment Data'})
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, comment_pk=self.comment.id)
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_owner_delete_request(self):
        url = reverse('group-members', kwargs={'group_name': self.group.name})
        query_string = urlencode({'member': self.user3.username})
        request = self.factory.delete(url + '?' + query_string)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)

        self.astertTrue(self.group in self.user3.groups.all())
        response = self.view(request, group_name=self.group.name)

        self.astertEqual(response.status_code, 200)
        self.astertFalse(self.group in self.user3.groups.all())

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_patch_request(self):
        url = reverse('group-details', kwargs={'group_name': self.group.name})
        request = self.factory.patch(url, {})
        request.resolver_match = resolve(url)

        force_authenticate(request, user=self.user2)
        self.astertTrue(self.user2 in self.group.groupmeta.admins.all())

        response = self.view(request, group_name=self.group.name)
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_nonadmin_delete_request(self):
        url = reverse('rule-tags', kwargs={'group_name': self.group1.name, 
                                           'rule_pk': self.rule.id,
                                           'tag': 'tagged'})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, tag='tagged')
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_delete_request(self):
        url = reverse('rule-comment-details', kwargs={'group_name': self.group1.name, 
                                                      'rule_pk': self.rule.id,
                                                      'comment_pk': self.comment.id})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, comment_pk=self.comment.id)

        self.astertEqual(response.status_code, 204)
        self.astertFalse(YaraRuleComment.objects.filter(id=self.comment.id).exists())

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_nonadmin_put_request(self):
        url = reverse('rule-details', kwargs={'group_name': self.group1.name, 'rule_pk': self.rule.id})
        request = self.factory.put(url, {'source': '',
                                         'category': '',
                                         'rule_content': 'rule replaced { condition: false }',
                                         'status': YaraRule.INACTIVE_STATUS})

        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group1.name, rule_pk=self.rule.id)
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_get_request(self):
        url = reverse('ruleset-stats', kwargs={'group_name': self.group1.name})
        
        request = self.factory.get(url)
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name)
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_owner_patch_request(self):
        url = reverse('group-members', kwargs={'group_name': self.group.name})
        request = self.factory.patch(url, {'member': [self.user4.username]})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)

        self.astertFalse(self.group in self.user4.groups.all())
        response = self.view(request, group_name=self.group.name)

        self.astertEqual(response.status_code, 200)
        self.astertTrue(self.group in self.user4.groups.all())

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_post_request(self):
        url = reverse('ruleset-bulk', kwargs={'group_name': self.group1.name})
        request = self.factory.post(url)
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name)

        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_valid_admin_patch_request(self):
        url = reverse('ruleset-bulk', kwargs={'group_name': self.group1.name})
        query_string = urlencode({'name_startswith': 'BulkRule'})
        request = self.factory.patch(url + '?' + query_string, {'add_tags': ['UPDATED']})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group1.name)

        self.astertEqual(response.status_code, 200)
        self.astertEqual(response.data['modified_rule_count'], 3)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_patch_request(self):
        url = reverse('group-members', kwargs={'group_name': self.group.name})
        request = self.factory.patch(url, {'member': [self.user4.username]})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group.name)
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_delete_request(self):
        url = reverse('group-categories', kwargs={'group_name': self.group.name})
        query_string = urlencode({'category': 'old_category'})
        request = self.factory.delete(url + '?' + query_string)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)

        self.astertTrue('old_category' in self.group.groupmeta.category_options)
        response = self.view(request, group_name=self.group.name)

        self.group.groupmeta.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertFalse('old_category' in self.group.groupmeta.category_options)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_patch_request(self):
        self.astertTrue(self.rule.status == YaraRule.ACTIVE_STATUS)
        url = reverse('rule-details', kwargs={'group_name': self.group1.name, 'rule_pk': self.rule.id})
        request = self.factory.patch(url, {'status': YaraRule.INACTIVE_STATUS})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group1.name, rule_pk=self.rule.id)

        self.rule.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertTrue(self.rule.status == YaraRule.INACTIVE_STATUS)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_delete_request(self):
        url = reverse('rule-metadata', kwargs={'group_name': self.group1.name, 
                                               'rule_pk': self.rule.id,
                                               'metakey': 'key'})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, metakey='key')
        
        self.rule.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertEqual(len(response.data['metadata'].keys()), 0)
        self.astertFalse('key' in self.rule.metadata)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_put_request(self):
        url = reverse('rule-comment-details', kwargs={'group_name': self.group1.name, 
                                                      'rule_pk': self.rule.id,
                                                      'comment_pk': self.comment.id})
        request = self.factory.put(url, {'content': 'Updated Comment Data'})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, comment_pk=self.comment.id)
        
        self.comment.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertEqual(response.data['content'], 'Updated Comment Data')
        self.astertEqual(self.comment.content, 'Updated Comment Data')

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_member_get_request(self):
        url = reverse('rule-comment-details', kwargs={'group_name': self.group1.name, 
                                                      'rule_pk': self.rule.id,
                                                      'comment_pk': self.comment.id})
        request = self.factory.get(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, comment_pk=self.comment.id)

        self.astertEqual(response.status_code, 200)
        self.astertEqual(response.data['content'], 'Comment Data')

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_put_request(self):
        url = reverse('rule-details', kwargs={'group_name': self.group1.name, 'rule_pk': self.rule.id})
        request = self.factory.put(url, {'source': '',
                                         'category': '',
                                         'rule_content': 'rule replaced { condition: false }',
                                         'status': YaraRule.INACTIVE_STATUS})

        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group1.name, rule_pk=self.rule.id)

        self.rule.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertTrue(self.rule.name == 'replaced')

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_patch_request(self):
        url = reverse('group-categories', kwargs={'group_name': self.group.name})
        request = self.factory.patch(url, {'category': ['new_category']})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group.name)

        self.group.groupmeta.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertTrue('new_category' in self.group.groupmeta.category_options)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_put_request(self):
        url = reverse('rule-details', kwargs={'group_name': self.group1.name, 'rule_pk': self.rule.id})
        request = self.factory.put(url, {'source': '',
                                         'category': '',
                                         'rule_content': 'rule replaced { condition: false }',
                                         'status': YaraRule.INACTIVE_STATUS})

        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name, rule_pk=self.rule.id)
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_post_request(self):
        url = reverse('ruleset-bulk', kwargs={'group_name': self.group1.name})
        request = self.factory.post(url, self.data)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group1.name)

        self.astertEqual(response.status_code, 200)
        self.astertEqual(response.data['rule_upload_count'], 1)

        rule = YaraRule.objects.get(name='dummy')
        self.astertEqual(rule.status, YaraRule.ACTIVE_STATUS)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_patch_request(self):
        url = reverse('group-sources', kwargs={'group_name': self.group.name})
        request = self.factory.patch(url, {'source': ['new_source']})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group.name)

        self.group.groupmeta.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertTrue('new_source' in self.group.groupmeta.source_options)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_valid_authenticated_post_request(self):
        self.group.groupmeta.source_required = False
        self.group.groupmeta.category_required = False
        self.group.groupmeta.save()

        url = reverse('ruleset', kwargs={'group_name': self.group.name})
        request = self.factory.post(url, self.data)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user)
        response = self.view(request, group_name=self.group.name)

        self.astertEqual(response.status_code, 201)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_owner_delete_request(self):
        url = reverse('group-sources', kwargs={'group_name': self.group.name})
        query_string = urlencode({'source': 'old_source'})
        request = self.factory.delete(url + '?' + query_string)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)

        self.astertTrue('old_source' in self.group.groupmeta.source_options)
        response = self.view(request, group_name=self.group.name)

        self.group.groupmeta.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertFalse('old_source' in self.group.groupmeta.source_options)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_nonadmin_delete_request(self):
        url = reverse('rule-metadata', kwargs={'group_name': self.group1.name, 
                                               'rule_pk': self.rule.id,
                                               'metakey': 'key'})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, metakey='key')
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_get_request(self):
        url = reverse('rule-comment-details', kwargs={'group_name': self.group1.name, 
                                                      'rule_pk': self.rule.id,
                                                      'comment_pk': self.comment.id})
        request = self.factory.get(url)
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, comment_pk=self.comment.id)
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_member_get_request(self):
        url = reverse('group-admins', kwargs={'group_name': self.group.name})
        request = self.factory.get(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user3)
        response = self.view(request, group_name=self.group.name)
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_delete_request(self):
        url = reverse('rule-tags', kwargs={'group_name': self.group1.name, 
                                           'rule_pk': self.rule.id,
                                           'tag': 'tagged'})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, tag='tagged')
        
        self.rule.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertEqual(len(response.data['tags']), 0)
        self.astertFalse('tagged' in self.rule.tags)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_patch_request(self):
        url = reverse('group-categories', kwargs={'group_name': self.group.name})
        request = self.factory.patch(url, {'category': ['new_category']})
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group.name)
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_owner_delete_request(self):
        url = reverse('group-admins', kwargs={'group_name': self.group.name})
        query_string = urlencode({'admin': self.user2.username})
        request = self.factory.delete(url + '?' + query_string)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)

        self.astertTrue(self.group in self.user2.groups.all())
        self.astertTrue(self.user2 in self.group.groupmeta.admins.all())
        response = self.view(request, group_name=self.group.name)

        self.astertEqual(response.status_code, 200)
        self.astertFalse(self.user2 in self.group.groupmeta.admins.all())

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_patch_request(self):
        url = reverse('rule-details', kwargs={'group_name': self.group1.name, 'rule_pk': self.rule.id})
        request = self.factory.patch(url, {'status': YaraRule.INACTIVE_STATUS})
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name, rule_pk=self.rule.id)
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_owner_patch_request(self):
        url = reverse('group-admins', kwargs={'group_name': self.group.name})
        request = self.factory.patch(url, {'admin': [self.user4.username]})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)

        self.astertFalse(self.group in self.user4.groups.all())
        self.astertFalse(self.user4 in self.group.groupmeta.admins.all())
        response = self.view(request, group_name=self.group.name)

        self.astertEqual(response.status_code, 200)
        self.astertTrue(self.group in self.user4.groups.all())
        self.astertTrue(self.user4 in self.group.groupmeta.admins.all())

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_get_request(self):
        url = reverse('group-members', kwargs={'group_name': self.group.name})
        request = self.factory.get(url)
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group.name)
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_delete_request(self):
        url = reverse('rule-metadata', kwargs={'group_name': self.group1.name, 
                                               'rule_pk': self.rule.id,
                                               'metakey': 'key'})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, metakey='key')
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_delete_request(self):
        url = reverse('group-details', kwargs={'group_name': self.group.name})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group.name)
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_nonadmin_put_request(self):
        url = reverse('rule-comment-details', kwargs={'group_name': self.group1.name, 
                                                      'rule_pk': self.rule.id,
                                                      'comment_pk': self.comment.id})
        request = self.factory.put(url, {'content': 'Updated Comment Data'})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, comment_pk=self.comment.id)
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_admin_post_request(self):
        url = reverse('rule-comments', kwargs={'group_name': self.group1.name, 
                                               'rule_pk': self.rule.id})
        request = self.factory.post(url, {'content': 'New Comment'})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group1.name, rule_pk=self.rule.id)

        self.astertEqual(response.status_code, 201)
        self.astertTrue(YaraRuleComment.objects.filter(content='New Comment').exists())

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_owner_delete_request(self):
        url = reverse('group-details', kwargs={'group_name': self.group.name})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)

        force_authenticate(request, user=self.user1)
        self.astertTrue(Group.objects.filter(name=self.group.name).exists())

        response = self.view(request, group_name=self.group.name)
        self.astertEqual(response.status_code, 204)
        self.astertFalse(Group.objects.filter(name=self.group.name).exists())

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_nonadmin_delete_request(self):
        url = reverse('rule-comment-details', kwargs={'group_name': self.group1.name, 
                                                      'rule_pk': self.rule.id,
                                                      'comment_pk': self.comment.id})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user2)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, comment_pk=self.comment.id)

        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_owner_patch_request(self):
        url = reverse('group-categories', kwargs={'group_name': self.group.name})
        request = self.factory.patch(url, {'category': ['new_category']})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group.name)

        self.group.groupmeta.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertTrue('new_category' in self.group.groupmeta.category_options)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_unauthenticated_delete_request(self):
        url = reverse('rule-tags', kwargs={'group_name': self.group1.name, 
                                           'rule_pk': self.rule.id,
                                           'tag': 'tagged'})
        request = self.factory.delete(url)
        request.resolver_match = resolve(url)
        response = self.view(request, group_name=self.group1.name,
                             rule_pk=self.rule.id, tag='tagged')
        
        self.astertEqual(response.status_code, 403)

3 View Complete Implementation : test_REST_views.py
Copyright Apache License 2.0
Author : PUNCH-Cyber
    def test_owner_patch_request(self):
        url = reverse('group-sources', kwargs={'group_name': self.group.name})
        request = self.factory.patch(url, {'source': ['new_source']})
        request.resolver_match = resolve(url)
        force_authenticate(request, user=self.user1)
        response = self.view(request, group_name=self.group.name)

        self.group.groupmeta.refresh_from_db()
        self.astertEqual(response.status_code, 200)
        self.astertTrue('new_source' in self.group.groupmeta.source_options)