Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functional testing #79

Merged
merged 2 commits into from
Mar 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ htmlcov
# JS
*/dist/bundle.js
node_modules/
/.envrc
/.virtualenv/

ghostdriver.log
npm-debug.log
13 changes: 12 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ services:
- postgresql
addons:
postgresql: "9.4"
# env:
# - DJANGO_LIVE_TEST_SERVER_ADDRESS=127.0.0.1:5000
# before_install:
# - travis_retry sudo apt-get update
# - travis_retry sudo apt-get install phantomjs
# - sudo mkdir /var/log/django
# - sudo chmod 777 /var/log/django
install:
- pip install -r requirements/common.txt
- pip install -r requirements/dev.txt
Expand All @@ -23,4 +30,8 @@ script:
- py.test cadasta --cov=cadasta --ds=config.settings.travis
- cd app
- npm run travis-test
- cd ..
# - npm start | tee /tmp/npm-start.log &
# - while ! grep 'bundle is now VALID' /tmp/npm-start.log; do sleep 1; done
# - sleep 2
# - cd ../functional_tests
# - ./run.py --ds=config.settings.travis
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,17 @@ SSH into to the VM, activate the virtualenv and run the server:
```
vagrant ssh
cd /vagrant/
source env/bin/activate
source /opt/cadasta/env/bin/activate
python cadasta/manage.py runserver
```

Open `http://localhost:5000/` in your browser, you should see a default Django page.

See the wiki ([here](https://github.com/Cadasta/cadasta-platform/wiki/Installation) and [here](https://github.com/Cadasta/cadasta-platform/wiki/Run-for-development)) for detailed instructions on installation and running the platform for development.

## Run tests

From the repository's root run:
Within the development VM, from the `/vagrant` directory run:

```
py.test cadasta
Expand Down
4 changes: 3 additions & 1 deletion Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ Vagrant.configure(2) do |config|
# Create a forwarded port mapping which allows access to a specific port
# within the machine from a port on the host machine. In the example below,
# accessing "localhost:8080" will access port 80 on the guest machine.
config.vm.network "forwarded_port", guest: 8080, host: 5000
config.vm.network "forwarded_port", guest: 5000, host: 5000
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.network "forwarded_port", guest: 8080, host: 8080

# Create a private network, which allows host-only access to the machine
# using a specific IP.
Expand Down
1 change: 1 addition & 0 deletions app/src/js/account/components/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ export class Login extends React.Component {
/>

<button
name="sign-in"
type="submit"
formNoValidate
className="btn btn-default btn-lg btn-block text-uppercase"
Expand Down
3 changes: 2 additions & 1 deletion app/src/js/account/components/Profile.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class Profile extends React.Component {
render() {
return (
<Form
className="form-narrow"
className="profile-form form-narrow"
onValidSubmit={this.handleFormSubmit}
ref="form"
>
Expand Down Expand Up @@ -105,6 +105,7 @@ export class Profile extends React.Component {

<button
formNoValidate
name="update"
type="submit"
className="btn btn-default btn-lg btn-block text-uppercase"
>
Expand Down
1 change: 1 addition & 0 deletions app/src/js/account/components/RegistrationForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ class RegistrationForm extends React.Component {
/>

<button
name="register"
type="submit"
formNoValidate
className="btn btn-default btn-lg btn-block text-uppercase"
Expand Down
144 changes: 67 additions & 77 deletions app/src/locale/gettext.po
Original file line number Diff line number Diff line change
Expand Up @@ -3,142 +3,100 @@ msgstr ""
"Content-Type: text/plain; charset=utf-8\n"
"Plural-Forms: nplurals = 2; plural = (n !== 1);\n"

#: src/js/account/components/Profile.jsx:60
msgid "Username"
msgstr ""

#: test/locale/test_locale.js:16
msgid "Hello %(name)s"
msgstr ""

#: test/locale/test_locale.js:33
msgid "%d unread message"
msgid_plural "%d unread messages"
msgstr[0] ""
msgstr[1] ""

#: test/locale/test_locale.js:38
msgid "Need more information? [link:Click here]."
msgstr ""

#: src/js/account/components/Password.jsx:34
msgid "Change your password"
#: src/js/account/components/Login.jsx:48
msgid "Sign in to your account"
msgstr ""

#: src/js/account/components/Password.jsx:40
msgid "Current password"
#: src/js/account/components/Profile.jsx:60
msgid "Username"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:50
msgid "New password"
#: src/js/account/components/RegistrationForm.jsx:88
msgid "This field is required"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:67
msgid "Your password must be at least 6 characters long."
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:62
msgid "Repeat new password"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:80
msgid "Passwords must match."
msgstr ""

#: src/js/account/components/Profile.jsx:112
msgid "Change password"
msgstr ""

#: src/js/account/components/Login.jsx:48
msgid "Sign in to your account"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:63
msgid "Password"
msgstr ""

#: src/js/account/components/Login.jsx:71
#: src/js/account/components/Login.jsx:77
msgid "Forgotten password?"
msgstr ""

#: src/js/account/components/Login.jsx:78
#: src/js/account/components/Login.jsx:84
msgid "Remember me"
msgstr ""

#: src/js/account/components/Login.jsx:86
#: src/js/account/components/Login.jsx:93
msgid "Sign in"
msgstr ""

#: src/js/account/components/Profile.jsx:54
msgid "Update your profile"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:50
#: src/js/account/components/RegistrationForm.jsx:53
msgid "Email"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:54
#: src/js/account/components/RegistrationForm.jsx:57
msgid "Please provide a valid email address"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:90
#: src/js/account/components/RegistrationForm.jsx:98
msgid "First name"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:99
#: src/js/account/components/RegistrationForm.jsx:107
msgid "Last name"
msgstr ""

#: src/js/account/components/Profile.jsx:107
#: src/js/account/components/Profile.jsx:112
msgid "Update profile"
msgstr ""

#: src/js/account/components/Profile.jsx:110
#: src/js/account/components/Profile.jsx:115
msgid "Password options"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:77
msgid "Reset password"
msgstr ""

#: src/js/account/components/PasswordReset.jsx:34
msgid "Reset your password"
#: src/js/account/components/Password.jsx:84
msgid "Change password"
msgstr ""

#: src/js/account/components/PasswordReset.jsx:41
msgid "Enter email"
#: src/js/account/components/PasswordResetConfirm.jsx:81
msgid "Reset password"
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:44
msgid "Create a new password"
#: src/js/account/components/Password.jsx:34
msgid "Change your password"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:33
msgid "Sign up for a free account"
#: src/js/account/components/Password.jsx:40
msgid "Current password"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:40
msgid "Choose username"
#: src/js/account/components/PasswordResetConfirm.jsx:50
msgid "New password"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:75
msgid "Confirm password"
#: src/js/account/components/RegistrationForm.jsx:72
msgid "Your password must be at least 6 characters long."
msgstr ""

#: src/js/core/components/Header.jsx:33
msgid "Register"
#: src/js/account/components/PasswordResetConfirm.jsx:65
msgid "Repeat new password"
msgstr ""

#: src/js/core/components/Header.jsx:23
msgid "Profile"
#: src/js/account/components/RegistrationForm.jsx:87
msgid "Passwords must match."
msgstr ""

#: src/js/core/components/Header.jsx:24
msgid "Logout"
#: src/js/account/components/PasswordReset.jsx:34
msgid "Reset your password"
msgstr ""

#: src/js/core/components/Header.jsx:32
msgid "Login"
#: src/js/account/components/PasswordReset.jsx:41
msgid "Enter email"
msgstr ""

#: src/js/messages/reducer.js:10
Expand Down Expand Up @@ -205,4 +163,36 @@ msgstr ""

#: src/js/messages/reducer.js:29
msgid "Account successfully activated."
msgstr ""

#: src/js/account/components/PasswordResetConfirm.jsx:44
msgid "Create a new password"
msgstr ""

#: src/js/core/components/Header.jsx:23
msgid "Profile"
msgstr ""

#: src/js/core/components/Header.jsx:24
msgid "Logout"
msgstr ""

#: src/js/core/components/Header.jsx:32
msgid "Login"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:117
msgid "Register"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:33
msgid "Sign up for a free account"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:40
msgid "Choose username"
msgstr ""

#: src/js/account/components/RegistrationForm.jsx:82
msgid "Confirm password"
msgstr ""
8 changes: 8 additions & 0 deletions app/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,19 @@ module.exports = {
},
devServer: {
contentBase: './dist',
host: '0.0.0.0',
hot: true,
historyApiFallback: true,
watchOptions: {
aggregateTimeout: 300,
poll: 1000
}
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.DefinePlugin(BUILD_OPTIONS),
],
watchOptions: {
poll: true
}
};
3 changes: 2 additions & 1 deletion cadasta/accounts/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from ..models import User


class UserFactory(factory.django.DjangoModelFactory):
class Meta:
model = User
Expand All @@ -18,4 +19,4 @@ def _prepare(cls, create, **kwargs):
user.set_password(password)
if create:
user.save()
return user
return user
47 changes: 47 additions & 0 deletions functional_tests/accounts/test_login.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
from base import FunctionalTest
from pages.Login import LoginPage
from accounts.tests.factories import UserFactory


class LoginTest(FunctionalTest):
def setUp(self):
UserFactory.create(username='user1', password='user1pwd')

def test_unregistered_user(self):
"""An unregistered user cannot log in."""

sign_in = LoginPage(self).setup('baduser', 'password')
self.click_through(sign_in, self.BY_ALERT)

self.assert_has_message('alert', "Unable to login")

def test_wrong_password(self):
"""An user cannot log in with an invalid password."""
sign_in = LoginPage(self).setup('user1', 'not_right')
self.click_through(sign_in, self.BY_ALERT)

self.assert_has_message('alert', "Unable to login")

def test_valid_login(self):
"""A registered user can log in with their username and password and
log out again. The logged in and logged out states are
persistent across page refreshes.

"""
sign_in = LoginPage(self).setup('user1', 'user1pwd')
self.click_through(sign_in, self.BY_ALERT)
self.browser.find_element_by_xpath("//h1[.='Dashboard']")

self.browser.refresh()
self.wait_for_no_alerts()
self.browser.find_element_by_xpath("//h1[.='Dashboard']")

self.click_through(
self.browser.find_element_by_xpath("//a[.='Logout']"),
self.BY_ALERT
)
self.assert_has_message('alert', "logged out")

self.browser.refresh()
self.wait_for_no_alerts()
self.browser.find_element_by_xpath("//h1[.='Sign in to your account']")
Loading