Hey, folks. So as part of the possible move to MozTrap (or, really, it'd be useful for any other TCMS), I've come up with a truly hideous bash script to discover and extract test cases from the wiki. Here it is, in all its glory:
#!/bin/bash # Requires https://github.com/dominictarr/JSON.sh available as json.sh # pageid of Category:Test Cases main_cat_id=15824
testcase_ids+=(`curl -s "https://fedoraproject.org/w/api.php?action=query&list=categorymembers&am..." | json.sh -b | cut -f2`)
sub1_cat_ids=(`curl -s "https://fedoraproject.org/w/api.php?action=query&list=categorymembers&am..." | json.sh -b | cut -f2`)
echo "sub1_cat_ids are:" printf -- '%s\n' "${sub1_cat_ids[@]}"
for i in "${sub1_cat_ids[@]}" do sub2_cat_ids+=(`curl -s "https://fedoraproject.org/w/api.php?action=query&list=categorymembers&am..." | json.sh -b | cut -f2`) testcase_ids+=(`curl -s "https://fedoraproject.org/w/api.php?action=query&list=categorymembers&am..." | json.sh -b | cut -f2`) done
echo "sub2_cat_ids are:" printf -- '%s\n' "${sub2_cat_ids[@]}"
for i in "${sub2_cat_ids[@]}" do sub3_cat_ids+=(`curl -s "https://fedoraproject.org/w/api.php?action=query&list=categorymembers&am..." | json.sh -b | cut -f2`) testcase_ids+=(`curl -s "https://fedoraproject.org/w/api.php?action=query&list=categorymembers&am..." | json.sh -b | cut -f2`) done
echo "sub3_cat_ids are:" printf -- '%s\n' "${sub3_cat_ids[@]}"
for i in "${sub3_cat_ids[@]}" do sub4_cat_ids+=(`curl -s "https://fedoraproject.org/w/api.php?action=query&list=categorymembers&am..." | json.sh -b | cut -f2`) testcase_ids+=(`curl -s "https://fedoraproject.org/w/api.php?action=query&list=categorymembers&am..." | json.sh -b | cut -f2`) done
echo "sub4_cat_ids are:" printf -- '%s\n' "${sub4_cat_ids[@]}"
echo "testcase_ids are:" printf -- '%s\n' "${testcase_ids[@]}"
mkdir -p /home/adamw/local/test_cases for i in "${testcase_ids[@]}" do echo "Page title: `curl -s "https://fedoraproject.org/w/api.php?action=query&pageids=$i&prop=inf..." | json.sh -b | grep title | cut -f2`" > /home/adamw/local/test_cases/$i.mw echo "Test case contents:" >> /home/adamw/local/test_cases/$i.mw curl -s "https://fedoraproject.org/w/index.php?curid=$i&action=raw" >> /home/adamw/local/test_cases/$i.mw done
...I'm not proud. Yes, this is asking a PHP webapp to produce JSON then parsing it using bash, which is one of the dumbest things you'll see all week, but I suck at writing PHP from scratch. (Yes, yes, I also suck at writing shell scripts, thanks.)
You need https://github.com/dominictarr/JSON.sh , and you also probably want to change the hardcoded directory in the second to last line. This whacks the mediawiki API pretty hard, so probably no point running it unless you want to improve it or something; I have it running ATM and dumping all ~900 test cases in the wiki out to my system, once it's done I'll tar them and stick them up somewhere for others to access. Next step would be to write something to convert them to MozTrap's mass import format.
It stops at four levels of nesting because that seems to be all we have; sub4_cat_ids comes up empty. mediawiki's API doesn't have any way to say 'give me all the pages in this category and all its subcategories' - no way you can ask it to solve the nesting problem for you - so you pretty much have to do something like this. The 'progress reports' aren't really necessary, they were just to reassure me the thing was working properly as I went along.
There are all kinds of potential weaknesses and bugs in the approach, but for the actual set of categories and test cases we have in the Fedora wiki, it seems to work, and that's really all I cared about. It also produces some dupes - there are ~150 test cases in multiple categories...but I figured it's just as easy to wait for the dupes to get downloaded twice as it would be to spend time fixing the script to filter them out before doing the download step.
On Thu, 2014-08-21 at 19:15 -0700, Adam Williamson wrote:
Hey, folks. So as part of the possible move to MozTrap (or, really, it'd be useful for any other TCMS), I've come up with a truly hideous bash script to discover and extract test cases from the wiki.
I have it running ATM and dumping all ~900 test cases in the wiki out to my system, once it's done I'll tar them and stick them up somewhere for others to access. Next step would be to write something to convert them to MozTrap's mass import format.
I've put the full set of test cases (with obsolete ones and templates moved into subdirectories) up as https://fedorapeople.org/groups/qa/test_cases/fedora_test_cases_20140821.tar... . A somewhat-annotated version of the script is also available as https://fedorapeople.org/groups/qa/test_cases/extract_test_cases.sh .
Subject: Re: Test case discovery / extraction (MozTrap) From: adamwill@fedoraproject.org To: test@lists.fedoraproject.org Date: Thu, 21 Aug 2014 19:43:58 -0700
On Thu, 2014-08-21 at 19:15 -0700, Adam Williamson wrote:
Hey, folks. So as part of the possible move to MozTrap (or, really, it'd be useful for any other TCMS), I've come up with a truly hideous bash script to discover and extract test cases from the wiki.
I have it running ATM and dumping all ~900 test cases in the wiki out to my system, once it's done I'll tar them and stick them up somewhere for others to access. Next step would be to write something to convert them to MozTrap's mass import format.
I've put the full set of test cases (with obsolete ones and templates moved into subdirectories) up as https://fedorapeople.org/groups/qa/test_cases/fedora_test_cases_20140821.tar... . A somewhat-annotated version of the script is also available as https://fedorapeople.org/groups/qa/test_cases/extract_test_cases.sh . -- Adam Williamson Fedora QA Community Monkey IRC: adamw | Twitter: AdamW_Fedora | XMPP: adamw AT happyassassin . net http://www.happyassassin.net
It appears that there is going to be quite a bit of cleanup needed.
John.
On Fri, 2014-08-22 at 01:52 -0400, John Dulaney wrote:
Subject: Re: Test case discovery / extraction (MozTrap) From: adamwill@fedoraproject.org To: test@lists.fedoraproject.org Date: Thu, 21 Aug 2014 19:43:58 -0700
On Thu, 2014-08-21 at 19:15 -0700, Adam Williamson wrote:
Hey, folks. So as part of the possible move to MozTrap (or, really, it'd be useful for any other TCMS), I've come up with a truly hideous bash script to discover and extract test cases from the wiki.
I have it running ATM and dumping all ~900 test cases in the wiki out to my system, once it's done I'll tar them and stick them up somewhere for others to access. Next step would be to write something to convert them to MozTrap's mass import format.
I've put the full set of test cases (with obsolete ones and templates moved into subdirectories) up as https://fedorapeople.org/groups/qa/test_cases/fedora_test_cases_20140821.tar... . A somewhat-annotated version of the script is also available as https://fedorapeople.org/groups/qa/test_cases/extract_test_cases.sh .
It appears that there is going to be quite a bit of cleanup needed.
well, obviously, but did you mean something in particular on the basis of seeing this data? what type of 'cleanup'?
On Thu, 2014-08-21 at 19:43 -0700, Adam Williamson wrote:
On Thu, 2014-08-21 at 19:15 -0700, Adam Williamson wrote:
Hey, folks. So as part of the possible move to MozTrap (or, really, it'd be useful for any other TCMS), I've come up with a truly hideous bash script to discover and extract test cases from the wiki.
I have it running ATM and dumping all ~900 test cases in the wiki out to my system, once it's done I'll tar them and stick them up somewhere for others to access. Next step would be to write something to convert them to MozTrap's mass import format.
I've put the full set of test cases (with obsolete ones and templates moved into subdirectories) up as https://fedorapeople.org/groups/qa/test_cases/fedora_test_cases_20140821.tar... . A somewhat-annotated version of the script is also available as https://fedorapeople.org/groups/qa/test_cases/extract_test_cases.sh .
For some reason I got obsessed today with cleaning up the script, even though it's probably never going to be that much use again, so I put the cleaned up and somewhat-genericised version up as:
https://fedorapeople.org/groups/qa/test_cases/wiki_category.sh
it lets you pass options to specify the starting category, level of recursion, and specify one of three modes - just print out the IDs of sub-categories to the specified recursion level, print out the IDs of member pages to the specified recursion level, or extract the contents of the member pages (at the specified recursion level) to files in a given directory. I guess it might possibly be useful to someone else, sometime? Meh. That's today wasted!
(if called with no options it does what extract_test_cases.sh did, dumps the contents of all members of Test_Cases and its subcategories, to a recursion level of 3, into files...using a better directory name this time).