<commit_before>from django.test import TestCase
from django.core.urlresolvers import reverse
from django.template import Template
from django.template import Context
from django.template import RequestContext
from django.test.client import Client
from django.http import HttpRequest
from django.http import QueryDict

class SetQueryParametersTestCase(TestCase):
    def test_empty_querystring(self):
        t = Template(
                '{% load query_parameters %}'
                '{% set_query_parameters prop1=val1 %}'
            )
        request = HttpRequest()
        request.GET = QueryDict('')

        c = RequestContext(request)
        result = t.render(c)
        self.assertEqual(result, 'prop1=val1')

    def test_new_property(self):
        t = Template(
                '{% load query_parameters %}'
                '{% set_query_parameters prop1=val1 %}'
            )
        request = HttpRequest()
        request.GET = QueryDict('prop2=val2')

        c = RequestContext(request)
        result = t.render(c)
        self.assertEqual(result, 'prop1=val1&prop2=val2')

    def test_invalid_parameters(self):
        from django.template import TemplateSyntaxError
        self.assertRaises(TemplateSyntaxError, Template, '{% load query_parameters %}{% set_query_parameters prop1 %}')

    def test_multiple_new_properties(self):
        t = Template(
                '{% load query_parameters %}'
                '{% set_query_parameters prop1=val1 prop2=val2 %}'
            )
        request = HttpRequest()
        request.GET = QueryDict('prop3=val3')

        c = RequestContext(request)
        result = t.render(c)
        self.assertEqual(result, 'prop1=val1&prop2=val2&prop3=val3')

    def test_update_property(self):
        t = Template(
                '{% load query_parameters %}'
                '{% set_query_parameters prop1=val1 %}'
            )
        request = HttpRequest()
        request.GET = QueryDict('prop1=val2')

        c = RequestContext(request)
        result = t.render(c)
        self.assertEqual(result, 'prop1=val1')


    def test_overwriting_properties(self):
        t = Template(
                '{% load query_parameters %}'
                '{% set_query_parameters prop1=val1 prop1=val2 %}'
            )
        request = HttpRequest()
        request.GET = QueryDict('prop1=val3')

        c = RequestContext(request)
        result = t.render(c)
        self.assertEqual(result, 'prop1=val2')

<commit_msg>Added additional unit tests for set_query_parameters<commit_after>from django.test import TestCase
from django.core.urlresolvers import reverse
from django.template import Template
from django.template import Context
from django.template import RequestContext
from django.test.client import Client
from django.http import HttpRequest
from django.http import QueryDict

class SetQueryParametersTestCase(TestCase):
    def test_empty_querystring(self):
        t = Template(
                '{% load query_parameters %}'
                '{% set_query_parameters prop1=val1 %}'
            )
        request = HttpRequest()
        request.GET = QueryDict('')

        c = RequestContext(request)
        result = t.render(c)
        self.assertEqual(result, 'prop1=val1')

    def test_new_property(self):
        t = Template(
                '{% load query_parameters %}'
                '{% set_query_parameters prop1=val1 %}'
            )
        request = HttpRequest()
        request.GET = QueryDict('prop2=val2')

        c = RequestContext(request)
        result = t.render(c)
        self.assertEqual(result, 'prop1=val1&prop2=val2')

    def test_invalid_parameters(self):
        from django.template import TemplateSyntaxError
        self.assertRaises(TemplateSyntaxError, Template, '{% load query_parameters %}{% set_query_parameters prop1 %}')

    def test_multiple_new_properties(self):
        t = Template(
                '{% load query_parameters %}'
                '{% set_query_parameters prop1=val1 prop2=val2 %}'
            )
        request = HttpRequest()
        request.GET = QueryDict('prop3=val3')

        c = RequestContext(request)
        result = t.render(c)
        self.assertEqual(result, 'prop1=val1&prop2=val2&prop3=val3')

    def test_update_property(self):
        t = Template(
                '{% load query_parameters %}'
                '{% set_query_parameters prop1=val1 %}'
            )
        request = HttpRequest()
        request.GET = QueryDict('prop1=val2')

        c = RequestContext(request)
        result = t.render(c)
        self.assertEqual(result, 'prop1=val1')

    def test_update_and_add_property(self):
        t = Template(
                '{% load query_parameters %}'
                '{% set_query_parameters prop1=val1_modified prop3=val3 %}'
            )
        request = HttpRequest()
        request.GET = QueryDict('prop1=val1&prop2=val2')

        c = RequestContext(request)
        result = t.render(c)
        self.assertEqual(result, 'prop1=val1_modified&prop2=val2&prop3=val3')


{'fraction_non_alphanumeric': 0.10297029702970296, 'fraction_numerical': 0.016633663366336635, 'mean_word_length': 2.443081117927744, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4089084', 'n_tokens_mistral': 1432, 'n_tokens_neox': 1385, 'n_words': 281}