Commit 2c60ba57 authored by Soldatoff's avatar Soldatoff

Added test and files for it. Tests for working with custom names

parent 36a4d1b2
#RedirectMatch
/name.html /name123.html
# RewriteRule ^$ /cgi-bin/index.cgi [L]
^$ /cgi-bin/index.cgi
# RewriteRule ([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$ /cgi-bin/index.cgi?del=$1-$2 [L]
([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$ /cgi-bin/index.cgi?del=$1-$2
# RedirectMatch 301 ^/manual/(.*)$ http://www.php.net/manual/$1
^/manual/(.*)$ http://www.php.net/manual/$1
# RewriteRule ^([0-9A-Za-z]{12})(\.html?|$)$ /cgi-bin/index.cgi?op=download1&id=$1 [L]
^([0-9A-Za-z]{12})(\.html?|$)$ /cgi-bin/index.cgi?op=download1&id=$1
# RewriteRule ^([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&id=$1&fname=$2 [L]
^([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&id=$1&fname=$2
# RedirectMatch 301 /java/jwarehouse/org.eclipse.(.*)/(.*) http://www.devdaily.com/java/jwarehouse/eclipse/org.eclipse.$1/$2
/java/jwarehouse/org.eclipse.(.*)/(.*) http://www.devdaily.com/java/jwarehouse/eclipse/org.eclipse.$1/$2
# RewriteRule ^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})$ /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2 [L]
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})$ /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2
# RewriteRule ^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3 [L]
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3
# RewriteRule ^checkfiles\.html$ /cgi-bin/index.cgi?op=checkfiles [L]
^checkfiles\.html$ /cgi-bin/index.cgi?op=checkfiles
# Redirect 301 /2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html [status=301]
# RewriteRule ^contact\.html$ /cgi-bin/index.cgi?op=contact [L]
^contact\.html$ /cgi-bin/index.cgi?op=contact
# RewriteRule ^premium\.html$ /cgi-bin/index.cgi?op=payments [L]
^premium\.html$ /cgi-bin/index.cgi?op=payments
# RedirectMatch 301 ^/(.*)/htaccesselite-ultimate-htaccess-article.html(.*) /htaccess/htaccess.html
^/(.*)/htaccesselite-ultimate-htaccess-article.html(.*) /htaccess/htaccess.html
# RewriteRule ^login\.html$ /cgi-bin/index.cgi?op=login [L]
^login\.html$ /cgi-bin/index.cgi?op=login
# Redirect 301 /2007/phpbb/sending-post-form-data-with-php-curl.html /htaccess/sending-post-form-data-with-php-curl.html
/2007/phpbb/sending-post-form-data-with-php-curl.html /htaccess/sending-post-form-data-with-php-curl.html [status=301]
# RewriteRule ^catalogue(.*)\.html$ /cgi-bin/index.cgi?op=catalogue&date=$1 [L]
^catalogue(.*)\.html$ /cgi-bin/index.cgi?op=catalogue&date=$1
# RewriteRule ^news([0-9]*)\.html$ /cgi-bin/index.cgi?op=news&page=$1 [L]
^news([0-9]*)\.html$ /cgi-bin/index.cgi?op=news&page=$1
# Redirect 301 /2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html [status=301]
# RewriteRule ^n([0-9]+)-.*\.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1 [L]
^n([0-9]+)-.*\.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1
# RewriteRule ^free([0-9]+)\.html$ /cgi-bin/index.cgi?op=registration&aff_id=$1 [L]
^free([0-9]+)\.html$ /cgi-bin/index.cgi?op=registration&aff_id=$1
# RewriteRule ^users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$) /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2 [L]
^users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$) /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2
# RedirectMatch 301 ^/200([0-9])/([^01])(.*)$ /$2$3
^/200([0-9])/([^01])(.*)$ /$2$3
# RewriteRule ^embedmp3-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp3_embed&file_code=$1 [L]
^embedmp3-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp3_embed&file_code=$1
# RewriteRule ^embedmp4-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp32_embed&file_code=$1 [L]
^embedmp4-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp32_embed&file_code=$1
# RewriteRule ^box$ /cgi-bin/index_box.cgi [L]
^box$ /cgi-bin/index_box.cgi
if ($name_tests_redirect) {
rewrite ^/(.*)$ $name_tests_redirect redirect;
}
if ($name_tests_permanent_redirect) {
rewrite ^/(.*)$ $name_tests_permanent_redirect permanent;
}
if ($name_tests_status=301_redirect) {
rewrite ^/(.*)$ $name_tests_status=301_redirect redirect;
return status=301;
}
map $uri $name_tests_redirect {
/name.html /name123.html;
^$ /cgi-bin/index.cgi;
([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$ /cgi-bin/index.cgi?del=$1-$2;
^([0-9A-Za-z]{12})(\.html?|$)$ /cgi-bin/index.cgi?op=download1&id=$1;
^([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&id=$1&fname=$2;
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})$ /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2;
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3;
^checkfiles\.html$ /cgi-bin/index.cgi?op=checkfiles;
^contact\.html$ /cgi-bin/index.cgi?op=contact;
^premium\.html$ /cgi-bin/index.cgi?op=payments;
^/(.*)/htaccesselite-ultimate-htaccess-article.html(.*) /htaccess/htaccess.html;
^login\.html$ /cgi-bin/index.cgi?op=login;
^catalogue(.*)\.html$ /cgi-bin/index.cgi?op=catalogue&date=$1;
^news([0-9]*)\.html$ /cgi-bin/index.cgi?op=news&page=$1;
^n([0-9]+)-.*\.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1;
^free([0-9]+)\.html$ /cgi-bin/index.cgi?op=registration&aff_id=$1;
^users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$) /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2;
^/200([0-9])/([^01])(.*)$ /$2$3;
^embedmp3-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp3_embed&file_code=$1;
^embedmp4-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp32_embed&file_code=$1;
^box$ /cgi-bin/index_box.cgi;
}
\ No newline at end of file
map $uri $name_tests_permanent_redirect {
^/manual/(.*)$ http://www.php.net/manual/$1;
/java/jwarehouse/org.eclipse.(.*)/(.*) http://www.devdaily.com/java/jwarehouse/eclipse/org.eclipse.$1/$2;
}
\ No newline at end of file
map $uri $name_tests_status=301_redirect {
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html;
/2007/phpbb/sending-post-form-data-with-php-curl.html /htaccess/sending-post-form-data-with-php-curl.html;
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html;
}
\ No newline at end of file
if ($name_tests_redirect) {
rewrite ^/(.*)$ $name_tests_redirect redirect;
}
if ($name_tests_permanent_redirect) {
rewrite ^/(.*)$ $name_tests_permanent_redirect permanent;
}
if ($name_tests_status=301_redirect) {
rewrite ^/(.*)$ $name_tests_status=301_redirect redirect;
return status=301;
}
if ($prefix_redirect) {
rewrite ^/prefix/(.*)$ $prefix_redirect redirect;
}
map $uri $name_tests_redirect {
/name.html /name123.html;
^$ /cgi-bin/index.cgi;
([0-9A-Za-z]{12})-del-([0-9A-Za-z]+)/.+$ /cgi-bin/index.cgi?del=$1-$2;
^([0-9A-Za-z]{12})(\.html?|$)$ /cgi-bin/index.cgi?op=download1&id=$1;
^([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&id=$1&fname=$2;
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})$ /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2;
^([0-9A-Za-z\-_]{4,64})/([0-9A-Za-z]{12})(\/.+|\.html?|$) /cgi-bin/index.cgi?op=download1&usr_login=$1&id=$2&fname=$3;
^checkfiles\.html$ /cgi-bin/index.cgi?op=checkfiles;
^contact\.html$ /cgi-bin/index.cgi?op=contact;
^premium\.html$ /cgi-bin/index.cgi?op=payments;
^/(.*)/htaccesselite-ultimate-htaccess-article.html(.*) /htaccess/htaccess.html;
^login\.html$ /cgi-bin/index.cgi?op=login;
^catalogue(.*)\.html$ /cgi-bin/index.cgi?op=catalogue&date=$1;
^news([0-9]*)\.html$ /cgi-bin/index.cgi?op=news&page=$1;
^n([0-9]+)-.*\.html$ /cgi-bin/index.cgi?op=news_details&news_id=$1;
^free([0-9]+)\.html$ /cgi-bin/index.cgi?op=registration&aff_id=$1;
^users/([0-9A-Za-z\-_]{4,64})/?([0-9]+|$) /cgi-bin/index.cgi?op=user_public&usr_login=$1&fld_id=$2;
^/200([0-9])/([^01])(.*)$ /$2$3;
^embedmp3-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp3_embed&file_code=$1;
^embedmp4-([0-9A-Za-z]{12})\.html$ /cgi-bin/index.cgi?op=mp32_embed&file_code=$1;
^box$ /cgi-bin/index_box.cgi;
}
\ No newline at end of file
map $uri $name_tests_permanent_redirect {
^/manual/(.*)$ http://www.php.net/manual/$1;
/java/jwarehouse/org.eclipse.(.*)/(.*) http://www.devdaily.com/java/jwarehouse/eclipse/org.eclipse.$1/$2;
}
\ No newline at end of file
map $uri $name_tests_status=301_redirect {
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html;
/2007/phpbb/sending-post-form-data-with-php-curl.html /htaccess/sending-post-form-data-with-php-curl.html;
/2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html /dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html;
}
\ No newline at end of file
import unittest
import os
from redirector.tests.utils import get_abs_path, get_rel_path
from redirector.redirector import *
from redirector.utils import generators
from redirector.utils import parser
from redirector.utils.const import MAPS_DIR, CONFIG_DIR, CONFIG
class EqualRedirectorTest(unittest.TestCase):
def setUp(self):
self.redirector = Redirector()
def test_equal_namemap(self):
abs_yaml_path = get_abs_path(CONFIG)
abs_test_path = get_abs_path('name_test.map')
self.redirector.generate(abs_yaml_path, abs_test_path)
abs_res_conf_path = get_rel_path("{}/name_tests.conf".format(CONFIG_DIR))
res_conf_file = open(abs_res_conf_path, 'r')
res_conf_lines = []
for line in res_conf_file:
if len(line) > 2 or not line.startswith('#'):
res_conf_lines.append(line)
res_conf_file.close()
maps_dir = get_rel_path(MAPS_DIR)
abs_res_map_paths = [
"{}/name_tests.map".format(maps_dir),
"{}/name_tests_permanent_options.map".format(maps_dir),
"{}/name_tests_status=301_options.map".format(maps_dir)
]
res_map_lines = []
for path in abs_res_map_paths:
f = open(path, 'r')
for line in f:
if len(line) > 2 or not line.startswith('#'):
res_map_lines.append(line)
f.close()
abs_test_conf_path = get_rel_path('nginx/location-includes/name_tests.conf')
test_conf_file = open(abs_test_conf_path, 'r')
test_conf_lines = []
for line in test_conf_file:
if len(line) > 2 or not line.startswith('#'):
test_conf_lines.append(line)
test_conf_file.close()
test_maps_dir = get_rel_path('nginx/maps')
abs_test_map_paths = [
"{}/name_tests.map".format(test_maps_dir),
"{}/name_tests_permanent_options.map".format(test_maps_dir),
"{}/name_tests_status=301_options.map".format(test_maps_dir)
]
test_map_lines = []
for path in abs_test_map_paths:
f = open(path, 'r')
for line in f:
if len(line) > 2 or not line.startswith('#'):
test_map_lines.append(line)
f.close()
# unittest.TestCase.maxDiff = None
self.assertEqual(res_conf_lines, test_conf_lines)
self.assertEqual(res_map_lines, test_map_lines)
# for path in abs_res_map_paths:
# os.remove(path)
# os.remove(abs_res_conf_path)
import unittest
import os
from redirector.tests.utils import get_abs_path, get_rel_path
from redirector.redirector import *
......@@ -14,6 +16,7 @@ class EqualRedirectorTest(unittest.TestCase):
def test_equal_map(self):
abs_yaml_path = get_abs_path(CONFIG)
abs_test_path = get_abs_path('test.map')
self.redirector.generate(abs_yaml_path, abs_test_path)
abs_res_conf_path = get_rel_path("{}/test.conf".format(CONFIG_DIR))
......@@ -25,7 +28,7 @@ class EqualRedirectorTest(unittest.TestCase):
res_conf_lines.append(line)
res_conf_file.close()
maps_dir = get_rel_path(MAPS_DIR)
abs_res_map_paths = [
"{}/test.map".format(maps_dir),
......@@ -43,8 +46,6 @@ class EqualRedirectorTest(unittest.TestCase):
res_map_lines.append(line)
f.close()
self.redirector.generate(abs_yaml_path, abs_test_path)
abs_test_conf_path = get_rel_path('nginx/location-includes/test.conf')
test_conf_file = open(abs_test_conf_path, 'r')
......@@ -76,4 +77,8 @@ class EqualRedirectorTest(unittest.TestCase):
self.assertEqual(res_conf_lines, test_conf_lines)
self.assertEqual(res_map_lines, test_map_lines)
# for path in abs_res_map_paths:
# os.remove(path)
# os.remove(abs_res_conf_path)
......@@ -2,4 +2,6 @@ projects:
- map: redirector/tests/test.map
prefix: /test
name: /
- map: redirector/tests/name_test.map
prefix: /
name: /name
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment