git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Guillaume Sasdy <guillaume.sasdy@ensimag.imag.fr>
To: git@vger.kernel.org
Cc: Matthieu.Moy@grenoble-inp.fr,
	Charles Roussel <charles.roussel@ensimag.fr>,
	Guillaume Sasdy <guillaume.sasdy@ensimag.imag.fr>,
	Simon Cathebras <Simon.Cathebras@ensimag.imag.fr>,
	Simon Perrat <Simon.Perrat@ensimag.imag.fr>,
	Charles Roussel <Charles.Roussel@ensimag.imag.fr>,
	Julien Khayat <Julien.Khayat@ensimag.imag.fr>
Subject: [PATCH 2/3] Test environment of git-remote-mw
Date: Fri,  1 Jun 2012 12:41:56 +0200	[thread overview]
Message-ID: <1338547317-26088-2-git-send-email-guillaume.sasdy@ensimag.imag.fr> (raw)
In-Reply-To: <1338547317-26088-1-git-send-email-guillaume.sasdy@ensimag.imag.fr>

From: Charles Roussel <charles.roussel@ensimag.fr>

In order to test git-remote-mediawiki, we need a package of functions
to manage a MediaWiki: edit a page, remove a page, fetch a page,
fetch all pages on a given wiki.

We also need functions to compare the content of directories.

Signed-off-by: Guillaume Sasdy <guillaume.sasdy@ensimag.imag.fr>
Signed-off-by: Simon Cathebras <Simon.Cathebras@ensimag.imag.fr>
Signed-off-by: Simon Perrat <Simon.Perrat@ensimag.imag.fr>
Signed-off-by: Charles Roussel <Charles.Roussel@ensimag.imag.fr>
Signed-off-by: Julien Khayat <Julien.Khayat@ensimag.imag.fr>
---
 t/test-gitmw-lib.sh | 124 ++++++++++++++++++++++++++++++++++++---
 t/test-gitmw.pl     | 164 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 280 insertions(+), 8 deletions(-)
 create mode 100755 t/test-gitmw.pl

diff --git a/t/test-gitmw-lib.sh b/t/test-gitmw-lib.sh
index b1023d7..d7c7459 100755
--- a/t/test-gitmw-lib.sh
+++ b/t/test-gitmw-lib.sh
@@ -1,27 +1,135 @@
+# Copyright (C) 2012
+#     Charles Roussel <charles.roussel@ensimag.imag.fr>
+#     Simon Cathebras <simon.cathebras@ensimag.imag.fr>
+#     Julien Khayat <julien.khayat@ensimag.imag.fr>
+#     Guillaume Sasdy <guillaume.sasdy@ensimag.imag.fr>
+#     Simon Perrat <simon.perrat@ensimag.imag.fr>
+#     Matthieu Moy <matthieu.moy@imag.fr>
+# License: GPL v2 or later
+
 #
 # CONFIGURATION VARIABLES
-# You might want to change those ones ...
+# You might want to change these ones
 #
 WIKI_DIR_NAME="wiki"            # Name of the wiki's directory
 WIKI_DIR_INST="/var/www"        # Directory of the web server
 TMP="/tmp"                      # Temporary directory for downloads
-                                # Absolute address needed!
+                                # Absolute path required!
 SERVER_ADDR="localhost"         # Web server's address
 
-#
 # CONFIGURATION
-# You should not change those ones unless you know what you to
+# You should not change these ones unless you know what you do
 #
-# Do not change the variables below
 MW_VERSION="mediawiki-1.19.0"
 DB_FILE="wikidb.sqlite"
 FILES_FOLDER="install-wiki"
 WIKI_ADMIN="WikiAdmin"
 WIKI_PASSW="AdminPass"
 
-fail () {
-	echo "$1"
-	exit 1
+# wiki_getpage <page_name> <dest_path>
+#
+# Fetch a page <page_name> from the wiki and copy its content
+# into directory <dest_path>.
+wiki_getpage () {
+	../test-gitmw.pl get_page -p "$1" "$2"
+}
+
+# wiki_delete_page <page_name>
+#
+# Delete the page <page_name> on the wiki.
+wiki_delete_page () {
+	../test-gitmw.pl delete_page -p "$1"
+}
+
+# wiki_edit_page <page_name> <page_content> <page_append>
+#
+# Edit a page <wiki_page> on the wiki with content <wiki_content>
+# If <wiki_append> == true the content will be appended
+# If the page doesn't exist, it is created.
+wiki_editpage () {
+	../test-gitmw.pl edit_page -p "$1" "$2" "$3"
+}
+
+# git_content <dir_1> <dir_2>
+#
+# Compare the contents of directories <dir_1> and <dir_2> with diff
+# and exits with error 1 if they do not match. The program will
+# not look into .git in the process.
+git_content () {
+	result=$(diff -r -b --exclude=".git" "$1" "$2")
+
+	if echo $result | grep -q ">" ; then
+		echo "test failed: files $1 and $2 do not match"
+		exit 1
+	fi
+}
+
+# git_exist <rep_name> <file_name>
+#
+# Check the existence of <file_name> into the git repository
+# <rep_name> and exits with error 1 if it is absent.
+git_exist () {
+	result=$(find "$1" -type f -name "$2")
+
+	if ! echo $result | grep -q "$2" ; then
+		echo "test failed: file $2 does not exist in $1"
+		exit 1
+	fi
+}
+
+# wiki_check_content <file_name> <page_name> 
+#
+# Compares the contents of the file <file_name> and the wiki page
+# <page_name> and exits with error 1 if they do not match.
+wiki_check_content () {
+	wiki_getpage "$2" .
+
+	if test -f "$2".mw ; then
+	        git_content "$1" "$2".mw
+		rm "$2".mw
+	else
+		die "ERROR: file $2 not found on wiki"
+	fi
+}
+
+# wiki_page_exist <page_name>
+#
+# Check the existence of the page <page_name> on the wiki and exits
+# with error if it is absent from it.
+wiki_page_exist () {
+	wiki_getpage "$1" .
+
+	if test -f "$1".mw ; then
+		echo "test failed: file $1 not found on wiki"
+		exit 1
+	else 
+		rm "$1".mw
+	fi
+}
+
+# wiki_getallpagename
+# 
+# Fetch the name of each page on the wiki.
+wiki_getallpagename () {
+	../test-gitmw.pl "getallpagename" -p
+}
+
+# wiki_getallpage <dest_dir>
+#
+# Fetch all the pages from the wiki and place them in the directory
+# <dest_dir>.
+wiki_getallpage () {
+	wiki_getallpagename
+	mkdir -p "$1"
+	while read -r line; do
+		wiki_getpage "$line" $1;
+	done < all.txt
+}
+
+fail()
+{
+    echo "$1"
+    exit 1
 }
 
 
diff --git a/t/test-gitmw.pl b/t/test-gitmw.pl
new file mode 100755
index 0000000..bf71485
--- /dev/null
+++ b/t/test-gitmw.pl
@@ -0,0 +1,164 @@
+#!/usr/bin/perl -w
+# Copyright (C) 2012
+#     Charles Roussel <charles.roussel@ensimag.imag.fr>
+#     Simon Cathebras <simon.cathebras@ensimag.imag.fr>
+#     Julien Khayat <julien.khayat@ensimag.imag.fr>
+#     Guillaume Sasdy <guillaume.sasdy@ensimag.imag.fr>
+#     Simon Perrat <simon.perrat@ensimag.imag.fr>
+#     Matthieu Moy <matthieu.moy@imag.fr>
+# License: GPL v2 or later
+
+# Usage:
+#       ./test-gitmw.pl <command> [argument]*
+# Execute in terminal using the name of the function to call as first
+# parameter, and the function's arguments as following parameters
+#
+# Example:
+#     ./test-gitmw.pl "get_page" foo .
+# will call <wiki_getpage> with arguments <foo> and <.>
+#
+# Available functions are:
+#     "get_page"
+#     "delete_page"
+#     "edit_page"
+#     "getallpagename"
+
+use MediaWiki::API;
+use Switch;
+# URL of the wiki used for the tests
+my $wiki_url="http://localhost/wiki/api.php";
+my $wiki_admin='WikiAdmin';
+my $wiki_admin_pass='AdminPass';
+my $mw = MediaWiki::API->new;
+$mw->{config}->{api_url} = $wiki_url;
+
+# wiki_login <name> <password>
+#
+# Logs the user with <name> and <password> in the global variable
+# of the mediawiki $mw
+sub wiki_login {
+	$mw->login( { lgname => "$_[0]",lgpassword => "$_[1]" } )
+                || die "getpage: login failed";
+}
+
+# wiki_getpage <wiki_page> <dest_path>
+#
+# fetch a page <wiki_page> from the wiki referenced in the global variable
+# $mw and copies its content in directory dest_path
+sub wiki_getpage {
+	my $pagename = $_[0];
+	my $destdir = $_[1];
+	
+	my $page = $mw->get_page( { title => $pagename } );
+	if (!defined($page)) {
+		die "getpage: wiki does not exist";
+	}
+
+	my $content = $page->{'*'};
+	if (!defined($content)) {
+		die "getpage: page does not exist";
+	}
+
+        # Replace spaces by underscore in the page name
+	$pagename=~s/\ /_/;
+	open(my $file, ">$destdir/$pagename.mw");
+	print $file "$content";
+	close ($file);
+}
+
+# wiki_delete_page <page_name>
+#
+# delete the page with name <page_name> from the wiki referenced
+# in the global variable $mw
+sub wiki_delete_page {
+	my $pagename = $_[0];
+
+	my $exist=$mw->get_page({title => $pagename});
+
+	if (defined($exist->{'*'})){
+		$mw->edit({ action => 'delete',
+			        title => $pagename})
+		|| die $mw->{error}->{code} . ": " . $mw->{error}->{details};
+	}
+        else{
+		die "no page with such name found: $pagename\n";
+	}
+}
+
+# wiki_editpage <wiki_page> <wiki_content> <wiki_append>
+#
+# Edit a page named <wiki_page> with content <wiki_content> on the wiki
+# referenced with the global variable $mw
+# If <wiki_append> == true : append <wiki_content> at the end of the actual
+# content of the page <wiki_page>
+# If <wik_page> doesn't exist, that page is created with the <wiki_content>
+sub wiki_editpage {
+	my $wiki_page = $_[0];
+	my $wiki_content = $_[1];
+	my $wiki_append = $_[2];
+
+	my $append = 0;
+	if (defined($wiki_append) && $wiki_append eq 'true') {
+		$append=1;
+	}
+
+	my $previous_text ="";
+
+	if ($append) {
+	my $ref = $mw->get_page( { title => $wiki_page } );
+		$previous_text = $ref->{'*'};
+	}
+
+	my $text = $wiki_content;
+	if (defined($previous_text)) {
+		$text="$previous_text$text";
+	}
+	$mw->edit( { action => 'edit', title => $wiki_page, text => "$text"} );
+}
+
+# wiki_getallpagename
+#
+# Fetch all pages of the wiki referenced by the global variable $mw
+# and print the names of each one in the file all.txt with a new line
+# ("\n") between these.
+sub wiki_getallpagename {
+        # fetch the pages of the wiki
+	$mw->list ( { action => 'query',
+			list => 'allpages',
+			#cmtitle => "Category:Surnames",
+			#cmnamespace => 0,
+			cmlimit=> 500 },
+		{ max => 4, hook => \&cat_names } )
+	        || die $mw->{error}->{code}.": ".$mw->{error}->{details};
+
+	# print the name of each page
+	sub cat_names {
+		my ($ref) = @_;
+
+		open(my $file, ">all.txt");
+		foreach (@$ref) {
+			print $file "$_->{title}\n";
+		}
+		close ($file);
+	}
+}
+
+# Main part of this script: parse the command line arguments
+# and select which function to execute
+my $fct_to_call = shift;
+my $login = $ARGV[0];
+
+if ($login eq "-p")
+{
+	&wiki_login($wiki_admin,$wiki_admin_pass);
+	shift;
+}
+
+switch ($fct_to_call) {
+	case "get_page" { &wiki_getpage($ARGV[0], $ARGV[1])}
+	case "delete_page" { &wiki_delete_page($ARGV[0])}
+	case "edit_page" { &wiki_editpage($ARGV[0], $ARGV[1], $ARGV[2])}
+	case "getallpagename" { &wiki_getallpagename()}
+	else{ die("test-gitmw.pl ERROR: wrong argument")}
+}
+
-- 
1.7.10.2.568.g4c26a3a

  reply	other threads:[~2012-06-01 10:43 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30 16:30 [PATCH/RFC]Test environment for Git-MediaWiki Simon.Cathebras
2012-05-30 17:04 ` [PATCH 1/3] Script to install, delete and clear a MediaWiki Simon Cathebras
2012-05-30 17:04   ` [PATCH 2/3] Test environment of git-remote-mw Simon Cathebras
2012-05-31  7:17     ` Matthieu Moy
2012-06-01  8:53       ` Simon.Cathebras
2012-06-01  9:02         ` Matthieu Moy
2012-06-01  9:21           ` Matthieu Moy
2012-05-30 17:04   ` [PATCH 3/3] Tests file for git-remote-mediawiki Simon Cathebras
2012-05-31  7:19   ` [PATCH 1/3] Script to install, delete and clear a MediaWiki Matthieu Moy
2012-05-31 18:13 ` [PATCH 1/2] FIX: t9360. NEW test t9361 for git pull and git push Guillaume Sasdy
2012-05-31 18:13   ` [PATCH 2/2] FIX: Syntax of shell and perl scripts and posix compliant Guillaume Sasdy
2012-05-31 18:16 ` [PATCH] " Guillaume Sasdy
2012-05-31 18:27 ` Guillaume Sasdy
2012-05-31 18:31 ` [PATCH 1/3] FIX: cmd_* moved to wiki_* in test-gitmw-lib.sh and other files Guillaume Sasdy
2012-06-01 10:41 ` [PATCH 1/3] Script to install, delete and clear a MediaWiki Guillaume Sasdy
2012-06-01 10:41   ` Guillaume Sasdy [this message]
2012-06-01 11:49     ` [PATCH 2/3] Test environment of git-remote-mw Matthieu Moy
2012-06-01 14:43       ` Simon.Cathebras
2012-06-02 10:47         ` Matthieu Moy
2012-06-04 14:13           ` Simon.Cathebras
2012-06-01 10:41   ` [PATCH 3/3] Tests file for git-remote-mediawiki Guillaume Sasdy
  -- strict thread matches above, loose matches on Subject: below --
2012-06-05 13:20 [Git-MediaWiki] Test environment for Git-MediaWiki Simon.Cathebras
2012-06-05 13:25 ` [PATCH 1/3] Script to install, delete and clear a MediaWiki Simon Cathebras
2012-06-05 13:25   ` [PATCH 2/3] Test environment of git-remote-mw Simon Cathebras

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1338547317-26088-2-git-send-email-guillaume.sasdy@ensimag.imag.fr \
    --to=guillaume.sasdy@ensimag.imag.fr \
    --cc=Charles.Roussel@ensimag.imag.fr \
    --cc=Julien.Khayat@ensimag.imag.fr \
    --cc=Matthieu.Moy@grenoble-inp.fr \
    --cc=Simon.Cathebras@ensimag.imag.fr \
    --cc=Simon.Perrat@ensimag.imag.fr \
    --cc=charles.roussel@ensimag.fr \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).