<commit_before>#-*-coding:utf8-*-
'''Tests for Environ object'''

import unittest
from wsgit import Environ

def environ(request):
    return Environ(request).get_dict()

class TestEnviron(unittest.TestCase):
    def test_request_method(self):
        self.assertEqual(environ({})['REQUEST_METHOD'], 'MOBILE')

    def test_reqeust_uri(self):
        self.assertEqual(environ({})['REQUEST_URI'], None)
        self.assertEqual(environ({'uri':'/'})['REQUEST_URI'], '/')
        self.assertEqual(environ({'uri':'/foo/bar/'})['REQUEST_URI'],
                                 '/foo/bar/')
        self.assertEqual(environ({'url': '/foo/bar/?foo=bar'}['REQUEST_URI'], 
                                 '/foo/bar/?foo=bar'))

    def test_path_info(self):
        self.assertEqual(environ({}).get('PATH_INFO'), None)
        self.assertEqual(environ({'url':'/'})['PATH_INFO'], '/')
        self.assertEqual(environ({'url': '/foo/bar/?foo=bar'}['PATH_INFO'], 
                                 '/foo/bar/'))

    def test_query_string(self):
        self.assertEqual(environ({}).get('QUERY_STRING'), None)
        self.assertEqual(environ({'url':'/'}).get('QUERY_STRING'), '')
        self.assertEqual(environ({'url': '/foo/bar/?foo=bar'}['PATH_INFO'], 
                                 'foo=bar'))
        self.assertEqual(environ({'url': '/foo/bar/?foo=bar&foo2=bar2'}['PATH_INFO'], 
                                 'foo=bar&foo2=bar2'))<commit_msg>remote_addr, remote_port test code added - #4<commit_after>#-*-coding:utf8-*-
'''Tests for Environ object'''

import unittest
from wsgit import Environ, Request

def environ(request_parameters, meta={}):
    return Environ({'parameters':request_parameters, 'meta':meta).get_dict()

class TestEnviron(unittest.TestCase):
    def test_request_method(self):
        self.assertEqual(environ({})['REQUEST_METHOD'], 'MOBILE')

    def test_reqeust_uri(self):
        request = 
        self.assertEqual(environ({})['REQUEST_URI'], None)
        self.assertEqual(environ({'uri':'/'})['REQUEST_URI'], '/')
        self.assertEqual(environ({'uri':'/foo/bar/'})['REQUEST_URI'],
                                 '/foo/bar/')
        self.assertEqual(environ({'url': '/foo/bar/?foo=bar'}['REQUEST_URI'], 
                                 '/foo/bar/?foo=bar'))

    def test_path_info(self):
        self.assertEqual(environ({}).get('PATH_INFO'), None)
        self.assertEqual(environ({'url':'/'})['PATH_INFO'], '/')
        self.assertEqual(environ({'url': '/foo/bar/?foo=bar'})['PATH_INFO'], 
                                 '/foo/bar/')
        self.assertEqual(environ({'url':'/foo//'})['PATH_INFO'], '/foo/')

    def test_query_string(self):
        self.assertEqual(environ({}).get('QUERY_STRING'), None)
        self.assertEqual(environ({'url':'/'}).get('QUERY_STRING'), '')
        self.assertEqual(environ({'url': '/foo/bar/?foo=bar'})['PATH_INFO'], 
                                 'foo=bar')
        self.assertEqual(environ({'url': '/?foo=bar&foo2=bar2'})['PATH_INFO'], 
                                 'foo=bar&foo2=bar2')

    def test_remote_addr(self):
        self.assertEqual(Environ({}).get_dict().get('REMOTE_ADDR'), None)
        self.assertEqual(environ(meta={'ip':'127.0.0.1'})['REMOTE_ADDR'],
                                 '127.0.0.1')

    def test_remote_port(self):
        self.assertEqual(Environ({}).get_dict().get('REMOTE_PORT'), None)
        self.assertEqual(environ(meta={'port':10295})['REMOTE_PORT'], '10295')
{'fraction_non_alphanumeric': 0.20172166427546628, 'fraction_numerical': 0.009469153515064563, 'mean_word_length': 2.7768147345612135, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 11, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3910837', 'n_tokens_mistral': 1100, 'n_tokens_neox': 1080, 'n_words': 122}