This repository has been archived by the owner on Jan 26, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
transfered meetup tests from automated-testing repo
Signed-off-by: Fenn-25 <fenn25.fn@gmail.com>
- Loading branch information
1 parent
74595b0
commit 8454cf5
Showing
14 changed files
with
250 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,7 @@ local/ | |
|
||
# Documentation build | ||
_build | ||
|
||
# pytest | ||
|
||
.pytest_cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Automated Testing | ||
================= | ||
|
||
Documentation on running automated tests with selenium for systers/portal. | ||
|
||
Setup Selenium (Unix) | ||
--------------------- | ||
|
||
To run selenium test you would need to install (download) the standalone servers which implements WebDrivers' wire protocols : | ||
* geckodriver and | ||
* chromedriver | ||
|
||
is used here not withstanding, other WebDriver servers may be used with a little tweaking (which entails adding the desired webdriver in the browsers dictionary in the conftest.py) | ||
|
||
### Installation | ||
|
||
1. Download chromedriver [here](https://sites.google.com/a/chromium.org/chromedriver/home) | ||
1. Download geckodriver [here](https://github.com/mozilla/geckodriver/releases) | ||
|
||
Get latest versions, and make sure the version downloaded is meant for your OS and is compatible (32/64 bits) | ||
|
||
After downloading, extract both drivers and save in a directory (e.g webdrivers) in a location of choice, finally let selenium know where it can find the webdrivers by exporting the paths to the various executables, you would have to do this every time your (re)start you venv (or any enviroment for that matter) | ||
|
||
```bash | ||
export PATH=$PATH:/path/to/directory/of/executable/downloaded/ | ||
``` | ||
|
||
That is quite boring you can just make each of them available globally once and for all | ||
|
||
```bash | ||
sudo mv geckodriver /usr/local/bin | ||
sudo mv chromedriver /usr/local/bin | ||
``` | ||
|
||
You can also write a .bashrc script and export, to avoid the repetition this method however has thesame effect as simply moving the files to ```/usr/local/bin``` above. | ||
|
||
Note : Be sure to export only the directory(ies) containing the executables without including the executables to avoid the "NotADirectoryError: [Errno 20] Not a directory" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[pytest] | ||
DJANGO_SETTINGS_MODULE = systers_portal.settings.testing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
from selenium import webdriver | ||
from django.contrib.staticfiles.testing import StaticLiveServerTestCase | ||
from meetup.models import (Meetup, MeetupLocation, RequestMeetupLocation) | ||
from django.contrib.auth.models import User | ||
from django.utils import timezone | ||
from cities_light.models import City, Country | ||
from users.models import SystersUser | ||
from django.conf import settings | ||
from django.contrib.auth import (SESSION_KEY, BACKEND_SESSION_KEY, | ||
HASH_SESSION_KEY) | ||
from django.contrib.sessions.backends.db import SessionStore | ||
import json | ||
import os | ||
|
||
browsers = { | ||
'firefox': webdriver.Firefox, | ||
'chrome': webdriver.Chrome, | ||
} | ||
|
||
|
||
class SeleniumTestCase(StaticLiveServerTestCase): | ||
""" | ||
A base test case for selenium, providing different helper methods. | ||
""" | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
super().setUpClass() | ||
cls.browser = browsers['firefox']() | ||
cls.browser.implicitly_wait(0) | ||
|
||
@classmethod | ||
def tearDownClass(cls): | ||
cls.browser.quit() | ||
super().tearDownClass() | ||
|
||
def setUp(self): | ||
country = Country.objects.create(name='Bar', continent='AS') | ||
self.location = City.objects.create( | ||
name='Foo', display_name='Foo', country=country) | ||
with open('{0}{1}'.format( | ||
os.getcwd(), | ||
'/systers_portal/common/tests/selenium/credentials.json') | ||
) as json_data: | ||
credentials = json.load(json_data) | ||
self.user = User.objects.create( | ||
username=credentials['username'], password=credentials['password']) | ||
self.systers_user = SystersUser.objects.get(user=self.user) | ||
self.meetup_location = MeetupLocation.objects.create( | ||
name="Foo Systers", | ||
slug="foo", | ||
location=self.location, | ||
description="It's a test location", | ||
sponsors="BarBaz", | ||
leader=self.systers_user) | ||
self.meetup_location_request = RequestMeetupLocation.objects.create( | ||
name="Bar Systers", | ||
slug="bar", | ||
location=self.location, | ||
description="This is a test meetup location request", | ||
user=self.systers_user) | ||
self.meetup = Meetup.objects.create( | ||
title="Test Meetup", | ||
slug="baz", | ||
date=timezone.now().date(), | ||
time=timezone.now().time(), | ||
venue="FooBar colony", | ||
description="This is a testing meetup.", | ||
meetup_location=self.meetup_location, | ||
created_by=self.systers_user) | ||
|
||
def create_session_cookie(self): | ||
# Then create the authenticated session using the new user credentials | ||
session = SessionStore() | ||
session[SESSION_KEY] = self.user.pk | ||
session[BACKEND_SESSION_KEY] = settings.AUTHENTICATION_BACKENDS[0] | ||
session[HASH_SESSION_KEY] = self.user.get_session_auth_hash() | ||
session.save() | ||
|
||
# Finally, create the cookie dictionary | ||
cookie = { | ||
'name': settings.SESSION_COOKIE_NAME, | ||
'value': session.session_key, | ||
'secure': False, | ||
'path': '/', | ||
} | ||
return cookie |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"username":"foo", | ||
"password":"foobar" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
import pytest | ||
from selenium import webdriver | ||
|
||
browsers = { | ||
'firefox': webdriver.Firefox, | ||
'chrome': webdriver.Chrome, | ||
} | ||
|
||
|
||
@pytest.fixture(scope="class") | ||
def browser(request): | ||
if 'DISPLAY' not in os.environ: | ||
pytest.skip('Test requires display server (export DISPLAY)') | ||
|
||
b = browsers[request.config.getoption("--browser-config")]() | ||
|
||
request.addfinalizer(lambda *args: b.quit()) | ||
|
||
# inject class variables | ||
request.cls.browser = b | ||
|
||
return b | ||
|
||
|
||
def pytest_addoption(parser): | ||
parser.addoption( | ||
"--browser-config", | ||
action="store", | ||
default="chrome", | ||
help="firefox, chrome are allowed parameters") |
20 changes: 20 additions & 0 deletions
20
systers_portal/meetup/tests/selenium/test_meetup_location_admin_page.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from common.tests.selenium.base import SeleniumTestCase | ||
|
||
|
||
class TestMeetupLocationAdminPage(SeleniumTestCase): | ||
|
||
def test_can_add_new_meetup(self): | ||
self.browser.get(self.live_server_url) | ||
self.browser.add_cookie(self.create_session_cookie()) | ||
self.browser.refresh() | ||
self.browser.get('{0}{1}'.format(self.live_server_url, '/meetup/add')) | ||
self.assertTrue(True) | ||
|
||
def test_can_delete_meetup(self): | ||
self.browser.get(self.live_server_url) | ||
self.browser.add_cookie(self.create_session_cookie()) | ||
self.browser.refresh() | ||
self.browser.get('{0}{1}'.format(self.live_server_url, '/meetup/foo/about')) | ||
self.browser.find_element_by_xpath("//a[contains(text(),'Delete Meetup Location')]").click() | ||
self.browser.find_element_by_xpath('//input[@value="Confirm"]').click() | ||
self.assertTrue('Meetup Locations' in self.browser.title) |
15 changes: 15 additions & 0 deletions
15
systers_portal/meetup/tests/selenium/test_meetup_location_page.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from common.tests.selenium.base import SeleniumTestCase | ||
|
||
|
||
class TestMeetupLocationPage(SeleniumTestCase): | ||
|
||
def test_can_choose_location(self): | ||
self.browser.get('{0}{1}'.format(self.live_server_url, '/meetup/locations/')) | ||
self.browser.find_element_by_xpath("//a[contains(text(),'Foo Systers')]").click() | ||
self.assertTrue('Foo Systers' in self.browser.title) | ||
|
||
def test_can_get_members(self): | ||
self.browser.get('{0}{1}'.format(self.live_server_url, '/meetup/foo/about')) | ||
self.browser.find_element_by_xpath("//a[contains(text(),'Members')]").click() | ||
text = self.browser.find_element_by_xpath("//h2[contains(text(),'Moderators')]").text | ||
self.assertTrue(text in self.browser.page_source) |
23 changes: 23 additions & 0 deletions
23
systers_portal/meetup/tests/selenium/test_meetup_locations_page.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from common.tests.selenium.base import SeleniumTestCase | ||
|
||
|
||
class TestMeetupLocationsPage(SeleniumTestCase): | ||
|
||
def test_can_goto_meetuplocations_page(self): | ||
self.browser.get('{0}{1}'.format(self.live_server_url, '/meetup/locations/')) | ||
self.assertTrue('Meetup Locations' in self.browser.title) | ||
|
||
def test_can_choose_meetup_locations(self): | ||
self.browser.get(self.live_server_url) | ||
dropdown = self.browser.find_element_by_id('meetup-dropdown') | ||
dropdown.click() | ||
menu = dropdown.find_element_by_class_name('dropdown-menu') | ||
for menu_item in menu.find_elements_by_tag_name('li'): | ||
if menu_item.text == 'MEETUP LOCATIONS': | ||
menu_item.click() | ||
self.assertTrue('Meetup Locations' in self.browser.title) | ||
|
||
def test_can_choose_location(self): | ||
self.browser.get('{0}{1}'.format(self.live_server_url, '/meetup/locations/')) | ||
self.browser.find_element_by_xpath("//a[contains(text(),'Foo Systers')]").click() | ||
self.assertTrue('Foo Systers' in self.browser.title) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from common.tests.selenium.base import SeleniumTestCase | ||
|
||
|
||
class TestMeetupPage(SeleniumTestCase): | ||
|
||
def test_can_goto_meetup_page(self): | ||
self.browser.get('{0}{1}'.format(self.live_server_url, '/meetup/foo/baz/')) | ||
title = self.browser.find_element_by_id('meetup-title') | ||
self.assertTrue(title.text == 'Test Meetup') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters