changes so tests run
This commit is contained in:
parent
d7a156cf0a
commit
e7676b4dcc
10
.drone.yml
10
.drone.yml
|
@ -1,19 +1,21 @@
|
|||
build:
|
||||
image: olymk2/mhackspace
|
||||
pull: true
|
||||
environment:
|
||||
SERVER_ENVIRONMENT: DOCKER
|
||||
commands:
|
||||
- cd website
|
||||
# - cd website
|
||||
- sleep 15
|
||||
- python3 -m "scaffold"
|
||||
- nose2-3.5
|
||||
- pytest
|
||||
|
||||
|
||||
compose:
|
||||
database:
|
||||
image: olymk2/mariadb
|
||||
pull: true
|
||||
volume:
|
||||
- /website/data/migrate:/docker-entrypoint-initdb.d
|
||||
# volume:
|
||||
# - /website/data/migrate:/docker-entrypoint-initdb.d
|
||||
environment:
|
||||
MYSQL_DATABASE: maidstone_hackspace
|
||||
MYSQL_USER: mhackspace
|
||||
|
|
|
@ -11,7 +11,7 @@ RUN apk add --update --no-cache py-psycopg2 py-lxml py-flask py-pillow py-openss
|
|||
|
||||
RUN apk add --update --no-cache build-base make git bzr python3-dev libffi-dev openssl-dev libxml2-dev libxslt-dev jpeg-dev zlib-dev && \
|
||||
pip3 install lxml && \
|
||||
pip3 install --no-cache-dir lxml dateutils requests requests-oauthlib mailer gocardless paypalrestsdk pytz nose2 oauthlib flask flask-login pymysql misaka slimit cssmin pillow && \
|
||||
pip3 install --no-cache-dir lxml dateutils requests requests-oauthlib mailer gocardless paypalrestsdk pytz pytest nose2 oauthlib flask flask-login pymysql misaka slimit cssmin pillow && \
|
||||
pip3 install --upgrade git+git://github.com/olymk2/scaffold.git@master && \
|
||||
#pip3 install --upgrade --no-cache-dir bzr+lp:scaffold/trunk#egg=scaffold && \
|
||||
apk del build-base make git bzr python3-dev libffi-dev openssl-dev libxml2-dev libxslt-dev
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import os
|
||||
import constants
|
||||
import socket
|
||||
|
||||
from scaffold.core.data.database import db
|
||||
from scaffold import web
|
||||
from libs import mail
|
||||
|
||||
from website import constants
|
||||
from website.libs import mail
|
||||
|
||||
|
||||
schema = 'https:'
|
||||
|
@ -88,6 +90,6 @@ with web.template as setup:
|
|||
schema=schema,
|
||||
domain=domain,
|
||||
port=port)
|
||||
|
||||
print(database)
|
||||
db.config(database)
|
||||
mail.sendmail.set_server(email_server)
|
||||
|
|
|
@ -53,12 +53,12 @@ google_captcha = {
|
|||
|
||||
# TODO in scaffold remove when commited
|
||||
def get_ip_from_hostname(hostname, schema='http'):
|
||||
try:
|
||||
'%s://%s' % (schema, socket.gethostbyname('nginx'))
|
||||
except socket.gaierror:
|
||||
return '%s://%s' % (schema, '127.0.0.1')
|
||||
#try:
|
||||
# '%s://%s' % (schema, socket.gethostbyname('nginx'))
|
||||
#except socket.gaierror:
|
||||
return '%s://%s' % (schema, '127.0.0.1')
|
||||
|
||||
app_domain = 'http://%s' % socket.gethostbyname('nginx')
|
||||
app_domain = get_ip_from_hostname('nginx')
|
||||
app_email_template_path = 'templates/email/'
|
||||
schema = 'https:'
|
||||
domain = get_ip_from_hostname('nginx')
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from mailer import Mailer
|
||||
from mailer import Message
|
||||
from config.logger import log
|
||||
from website.config.logger import log
|
||||
|
||||
class sendmail:
|
||||
config = 'localhost'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
"""https://developers.google.com/recaptcha/docs/verify"""
|
||||
|
||||
from requests import post
|
||||
from config.logger import log
|
||||
from website.config.logger import log
|
||||
|
||||
def verify_captcha(secret, response, remoteip=''):
|
||||
try:
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os, sys
|
||||
import unittest
|
||||
import random
|
||||
from collections import defaultdict
|
||||
|
||||
sys.path.append(os.path.abspath('../'))
|
||||
|
||||
from config import settings
|
||||
from scaffold.core.data.database import db
|
||||
from data import site_user
|
||||
from tests.test_data import clean, populate
|
||||
|
||||
|
||||
class TestBase(unittest.TestCase):
|
||||
def setUp(self):
|
||||
clean()
|
||||
populate()
|
|
@ -1,61 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os, sys
|
||||
import unittest
|
||||
from collections import defaultdict
|
||||
|
||||
from config import settings
|
||||
|
||||
from data.badges import create_badge, assign_badge, remove_badge, fetch_badge, fetch_user_badges_grouped
|
||||
|
||||
from scaffold.core.data.database import db
|
||||
from tests.base import TestBase
|
||||
|
||||
import unittest
|
||||
|
||||
class TestBadges(TestBase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestBadges, self).setUp()
|
||||
create_badge().execute({'name': 'member'})
|
||||
create_badge().execute({'name': 'backer'})
|
||||
create_badge().execute({'name': 'teacher'})
|
||||
create_badge().execute({'name': 'chairman'})
|
||||
create_badge().execute({'name': 'treasurer'})
|
||||
create_badge().execute({'name': 'secretary'})
|
||||
assign_badge().execute({'badge_id': '1', 'user_id': '1' })
|
||||
assign_badge().execute({'badge_id': '2', 'user_id': '1' })
|
||||
assign_badge().execute({'badge_id': '3', 'user_id': '1' })
|
||||
|
||||
def testFetchUserBadges(self):
|
||||
self.assertTrue([a for a in fetch_badge({'badge_id': '1', 'user_id': '1' })])
|
||||
|
||||
def test_badge_grouping(self):
|
||||
self.assertEquals(fetch_user_badges_grouped(),{1: [1, 2, 3]} )
|
||||
|
||||
def testSelectingBadges(self):
|
||||
# this record should exist
|
||||
self.assertTrue([a for a in fetch_badge({'badge_id': '1', 'user_id': '1' })])
|
||||
|
||||
# these don't exist
|
||||
self.assertFalse([a for a in fetch_badge({'badge_id': '10', 'user_id': '10' })])
|
||||
self.assertFalse([a for a in fetch_badge({'user_id': '10'})])
|
||||
|
||||
def assignBadgeToUser(self):
|
||||
assign_badge().execute({'badge_id': '1', 'user_id': '1' })
|
||||
assign_badge().execute({'badge_id': '1', 'user_id': '1' })
|
||||
assign_badge().execute({'badge_id': '2', 'user_id': '1' })
|
||||
assign_badge().execute({'badge_id': '3', 'user_id': '1' })
|
||||
|
||||
def testAddingBadges(self):
|
||||
create_badge().execute({'name': 'badget'})
|
||||
self.assertEquals(fetch_user_badges_grouped(),{1: [1, 2, 3]} )
|
||||
|
||||
def testRemoveBadges(self):
|
||||
remove_badge().execute({'id': '1' })
|
||||
remove_badge().execute({'id': '2' })
|
||||
remove_badge().execute({'id': '3' })
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(buffer=False)
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os, sys
|
||||
import unittest
|
||||
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
from config import settings
|
||||
from data import site_user
|
||||
from scaffold.core.data.database import db
|
||||
print(settings.database)
|
||||
|
||||
class TestBasePage(unittest.TestCase):
|
||||
#~ class TestBasePage(TestDataSetup):
|
||||
|
||||
def testCreateBasicUser(self):
|
||||
"""User has not signed up yet but has interacted with the site, donated perhaps ?"""
|
||||
site_user.create_basic_user().execute({
|
||||
'first_name': 'myfirstname',
|
||||
'last_name': 'mylastname'
|
||||
})
|
||||
|
||||
def testCreateNormalUser(self):
|
||||
pw_hash = generate_password_hash('letmein')
|
||||
site_user.create().execute({
|
||||
'username': 'test@test.com',
|
||||
'first_name': 'myfirstname',
|
||||
'last_name': 'mylastname',
|
||||
'password': pw_hash
|
||||
})
|
||||
|
||||
def testCreateDuplicateUsers(self):
|
||||
pw_hash = generate_password_hash('letmein')
|
||||
site_user.create().execute({
|
||||
'username': 'test@test.com',
|
||||
'first_name': 'myfirstname',
|
||||
'last_name': 'mylastname',
|
||||
'password': pw_hash
|
||||
})
|
||||
|
||||
site_user.create().execute({
|
||||
'username': 'test@test.com',
|
||||
'first_name': 'myfirstname',
|
||||
'last_name': 'mylastname',
|
||||
'password': pw_hash
|
||||
})
|
||||
|
||||
def testRegisterNewUser(self):
|
||||
pw_hash = generate_password_hash('letmein')
|
||||
site_user.create().execute({
|
||||
'username': 'new_user@test.com',
|
||||
'first_name': 'myfirstname',
|
||||
'last_name': 'mylastname',
|
||||
'password': pw_hash
|
||||
})
|
||||
|
||||
user_details = site_user.get_by_username({
|
||||
'username': 'new_user@test.com'}).get()
|
||||
self.assertTrue(user_details)
|
||||
self.assertTrue(pw_hash == user_details.get('password'))
|
||||
self.assertTrue(user_details)
|
||||
|
||||
|
||||
def testRegisteringExistingUser(self):
|
||||
pw_hash = generate_password_hash('letmein')
|
||||
site_user.create().execute({
|
||||
'username': 'test@test.com',
|
||||
'first_name': 'myfirstname',
|
||||
'last_name': 'mylastname',
|
||||
'created': '',
|
||||
'password': pw_hash
|
||||
})
|
||||
|
||||
def testChangeUserPassword(self):
|
||||
site_user.change_password().execute({
|
||||
'id': '1',
|
||||
'password': 'password hash'
|
||||
})
|
||||
|
||||
def testUpdateLastLogin(self):
|
||||
site_user.update_last_login().execute({
|
||||
'id': '1'
|
||||
})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(buffer=False)
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os, sys
|
||||
import unittest
|
||||
import random
|
||||
from collections import defaultdict
|
||||
from werkzeug.security import generate_password_hash, check_password_hash
|
||||
|
||||
|
||||
from config import settings
|
||||
from scaffold.core.data.sql import query
|
||||
from scaffold.core.data.database import db
|
||||
from data import site_user
|
||||
|
||||
data_first_names = ['ralf', 'teddy', 'sprite']
|
||||
data_last_names = ['fuzzie']
|
||||
|
||||
|
||||
|
||||
def clean():
|
||||
clean_file = os.path.abspath('./data/migrate/clean.sql')
|
||||
with open(clean_file, 'r') as clean_fp:
|
||||
sql = clean_fp.read()
|
||||
query().execute({}, sql)
|
||||
|
||||
def populate():
|
||||
site_user.create_basic_user().execute(data={
|
||||
'first_name': random.choice(data_first_names),
|
||||
'last_name': random.choice(data_last_names),
|
||||
'password': generate_password_hash('test')
|
||||
})
|
|
@ -1,38 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os, sys
|
||||
import unittest
|
||||
from collections import defaultdict
|
||||
|
||||
from website.config import settings
|
||||
from scaffold.core.data.database import db
|
||||
from website.data import site_user
|
||||
|
||||
|
||||
class TestBasePage(unittest.TestCase):
|
||||
|
||||
def test_fetch_non_existant_oauth_user(self):
|
||||
site_user.create_oauth_login().execute({
|
||||
'username': 'Non existant username',
|
||||
'provider': 1,
|
||||
'user_id': 1,
|
||||
})
|
||||
|
||||
def test_fetch_existant_oauth_user(self):
|
||||
site_user.create_oauth_login().execute({
|
||||
'username': 'nick',
|
||||
'provider': 1,
|
||||
'user_id': 1,
|
||||
})
|
||||
|
||||
def test_update_oauth_user(self):
|
||||
site_user.update_oauth_login().execute({
|
||||
'user_id': '2',
|
||||
'username': 'nick_modified',
|
||||
'provider': 3,
|
||||
})
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(buffer=False)
|
||||
|
|
@ -1,37 +0,0 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
import os, sys
|
||||
import unittest
|
||||
from collections import defaultdict
|
||||
|
||||
from scaffold.core.data.database import db
|
||||
from data import site_user
|
||||
|
||||
|
||||
class TestBasePage(unittest.TestCase):
|
||||
|
||||
def test_fetch_non_existant_oauth_user(self):
|
||||
site_user.create_oauth_login().execute({
|
||||
'username': 'Non existant username',
|
||||
'provider': 1,
|
||||
'user_id': 1,
|
||||
})
|
||||
|
||||
def test_fetch_existant_oauth_user(self):
|
||||
site_user.create_oauth_login().execute({
|
||||
'username': 'nick',
|
||||
'provider': 1,
|
||||
'user_id': 1,
|
||||
})
|
||||
|
||||
def test_update_oauth_user(self):
|
||||
result = site_user.update_oauth_login().execute({
|
||||
'user_id': '2',
|
||||
'username': 'nick_modified',
|
||||
'provider': '3',
|
||||
})
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main(buffer=False)
|
Loading…
Reference in New Issue