Skip to content
Newer
Older
100644 99 lines (84 sloc) 3.52 KB
c8bf48c @rodrigomanhaes project logo showed in the projects page
rodrigomanhaes authored
1 import os
b01eec0 @hermancaldara Showing the total time of the acceptance test
hermancaldara authored
2 import time
8c44e5f @hermancaldara Created the test folders before harvest and removed those folders aft…
hermancaldara authored
3 import shutil
4cb79ae @rodrigomanhaes database is cleaned before each scenario
rodrigomanhaes authored
4 from django.core.management import call_command
c8bf48c @rodrigomanhaes project logo showed in the projects page
rodrigomanhaes authored
5 from django.conf import settings
9e85e22 @rodrigomanhaes removed duplicate code from step definitions
rodrigomanhaes authored
6 from splinter.browser import Browser
e3193a5 @rodrigomanhaes common web steps moved from terrain to a specific module
rodrigomanhaes authored
7 from lettuce import after, before, world
8 from web_steps import *
9e85e22 @rodrigomanhaes removed duplicate code from step definitions
rodrigomanhaes authored
9
8c44e5f @hermancaldara Created the test folders before harvest and removed those folders aft…
hermancaldara authored
10
11 PROJECT_ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
12
b01eec0 @hermancaldara Showing the total time of the acceptance test
hermancaldara authored
13 @before.harvest
0cc2508 @hermancaldara Refactored the code that shows the total time of the acceptance test
hermancaldara authored
14 def initial_run_time(variables):
15 world.time_before_harvest = time.time()
8c44e5f @hermancaldara Created the test folders before harvest and removed those folders aft…
hermancaldara authored
16 test_directories_list = [
17 os.path.join(PROJECT_ROOT_PATH, 'site_media', 'test', 'files', 'projects'),
18 os.path.join(PROJECT_ROOT_PATH, 'site_media', 'test', 'images', 'members'),
19 os.path.join(PROJECT_ROOT_PATH, 'site_media', 'test', 'images', 'news'),
20 os.path.join(PROJECT_ROOT_PATH, 'site_media', 'test', 'images', 'projects'),
a829f98 @ronaldoamaral added field logo, status, short_description; adjustment tools css; ( …
ronaldoamaral authored
21 os.path.join(PROJECT_ROOT_PATH, 'site_media', 'test', 'images', 'tools'),
8c44e5f @hermancaldara Created the test folders before harvest and removed those folders aft…
hermancaldara authored
22 ]
72dc118 @rodrigomanhaes updated selenium to allow running functional specs on firefox 5
rodrigomanhaes authored
23
8c44e5f @hermancaldara Created the test folders before harvest and removed those folders aft…
hermancaldara authored
24 for directory in test_directories_list:
25 if not os.path.exists(directory):
26 os.makedirs(directory)
72dc118 @rodrigomanhaes updated selenium to allow running functional specs on firefox 5
rodrigomanhaes authored
27
9e85e22 @rodrigomanhaes removed duplicate code from step definitions
rodrigomanhaes authored
28 @before.all
29 def set_browser():
30 world.browser = Browser()
31
4cb79ae @rodrigomanhaes database is cleaned before each scenario
rodrigomanhaes authored
32 @before.each_scenario
fede1fb @rodrigomanhaes history added to admin (closes issue #6)
rodrigomanhaes authored
33 def clean_database(scenario):
34 clean_data()
0ea770d @rodrigomanhaes added "files" dir for documents linked to projects
rodrigomanhaes authored
35 clean_media()
fede1fb @rodrigomanhaes history added to admin (closes issue #6)
rodrigomanhaes authored
36
37 def clean_data():
2bf90ea @romulomachado All code refactored following PEP-8
romulomachado authored
38 call_command('flush', interactive=False)
39 call_command('loaddata', 'all')
40
0ea770d @rodrigomanhaes added "files" dir for documents linked to projects
rodrigomanhaes authored
41 def clean_media():
f36905f @hermancaldara Modified the test structure of members app to put all the test files …
hermancaldara authored
42 clean_media_by_kind('images')
0ea770d @rodrigomanhaes added "files" dir for documents linked to projects
rodrigomanhaes authored
43 clean_media_by_kind('files')
44
39399f1 @rodrigomanhaes fixed functional tests to not delete layout images
rodrigomanhaes authored
45 def clean_media_by_kind(kind, skip_dir=None):
f36905f @hermancaldara Modified the test structure of members app to put all the test files …
hermancaldara authored
46 images_dir = os.path.join(settings.MEDIA_ROOT, 'test', kind)
802a001 @rodrigomanhaes link documents to projects
rodrigomanhaes authored
47 for file_name in os.listdir(images_dir):
f36905f @hermancaldara Modified the test structure of members app to put all the test files …
hermancaldara authored
48 clean_all(os.path.join(images_dir, file_name))
c8bf48c @rodrigomanhaes project logo showed in the projects page
rodrigomanhaes authored
49
39399f1 @rodrigomanhaes fixed functional tests to not delete layout images
rodrigomanhaes authored
50 def clean_all(directory, skip_dir=None):
c8bf48c @rodrigomanhaes project logo showed in the projects page
rodrigomanhaes authored
51 for file_name in os.listdir(directory):
52 absname = os.path.join(directory, file_name)
39399f1 @rodrigomanhaes fixed functional tests to not delete layout images
rodrigomanhaes authored
53 if skip_dir and skip_dir in absname:
54 pass
55 elif os.path.isdir(absname) and file_name not in ['.', '..']:
c8bf48c @rodrigomanhaes project logo showed in the projects page
rodrigomanhaes authored
56 clean_all(absname)
57 elif not file_name.startswith('.'):
58 os.unlink(absname)
59
9e85e22 @rodrigomanhaes removed duplicate code from step definitions
rodrigomanhaes authored
60 @after.all
61 def finish_him(total_result):
62 world.browser.quit()
0ea770d @rodrigomanhaes added "files" dir for documents linked to projects
rodrigomanhaes authored
63 clean_media()
39399f1 @rodrigomanhaes fixed functional tests to not delete layout images
rodrigomanhaes authored
64
b01eec0 @hermancaldara Showing the total time of the acceptance test
hermancaldara authored
65 @after.harvest
66 def run_time(results):
72dc118 @rodrigomanhaes updated selenium to allow running functional specs on firefox 5
rodrigomanhaes authored
67 shutil.rmtree(os.path.join(PROJECT_ROOT_PATH, 'site_media', 'test'))
0cc2508 @hermancaldara Refactored the code that shows the total time of the acceptance test
hermancaldara authored
68 time_after_harvest = time.time()
69 time_before_harvest = world.time_before_harvest
70 total_time = int(time_after_harvest - time_before_harvest)
71 minutes = total_time / 60
72 seconds = total_time % 60
73 total_features_ran = 0
74 total_scenarios_ran = 0
75 total_scenarios_passed = 0
76 total_scenarios_failed = dict()
b01eec0 @hermancaldara Showing the total time of the acceptance test
hermancaldara authored
77 for app in results:
0cc2508 @hermancaldara Refactored the code that shows the total time of the acceptance test
hermancaldara authored
78 total_features_ran += app.features_ran
79 total_scenarios_ran += app.scenarios_ran
80 total_scenarios_passed += app.scenarios_passed
81 for result in app.scenario_results:
82 if result.passed == False:
83 total_scenarios_failed.update({result.scenario.name: result.scenario.feature})
b01eec0 @hermancaldara Showing the total time of the acceptance test
hermancaldara authored
84
719bad8 @romulomachado Show the results of acceptance tests with colors
romulomachado authored
85 print '\n================================================'
86 print '=========== Acceptance tests results ===========\n'
87 print '\033[32m\033[1m%i features ran.\033[0;0m' % total_features_ran
88 print '\033[32m\033[1m%i scenarios ran.\033[0;0m' % total_scenarios_ran
89 print '\033[32m\033[1m%i scenarios passed.\033[0;0m' % total_scenarios_passed
0cc2508 @hermancaldara Refactored the code that shows the total time of the acceptance test
hermancaldara authored
90 if total_scenarios_failed:
719bad8 @romulomachado Show the results of acceptance tests with colors
romulomachado authored
91 print '\033[31m\033[1mError in:\033[0;0m'
0cc2508 @hermancaldara Refactored the code that shows the total time of the acceptance test
hermancaldara authored
92 for scenario, feature in total_scenarios_failed.iteritems():
719bad8 @romulomachado Show the results of acceptance tests with colors
romulomachado authored
93 print '\033[31m\033[1m' + feature.name + ' ~> ' + scenario + '\033[0;0m'
b01eec0 @hermancaldara Showing the total time of the acceptance test
hermancaldara authored
94 else:
719bad8 @romulomachado Show the results of acceptance tests with colors
romulomachado authored
95 print '\033[32m\033[1mNo errors! Congratulations!\033[0;0m'
96 print '----------------------------------------------------------------------'
b01eec0 @hermancaldara Showing the total time of the acceptance test
hermancaldara authored
97 print 'Everything ran in %i minute(s) and %i second(s).' % (minutes, seconds)
39399f1 @rodrigomanhaes fixed functional tests to not delete layout images
rodrigomanhaes authored
98
Something went wrong with that request. Please try again.