move tests
This commit is contained in:
parent
e7676b4dcc
commit
bf23afc5ec
|
@ -0,0 +1,13 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
#sys.path.insert(0, os.path.abspath('../../scaffold/scaffold/'))
|
||||||
|
#sys.path.insert(0, os.path.abspath('../../scaffold/'))
|
||||||
|
|
||||||
|
#sys.path.append(os.path.abspath('../../scaffold/scaffold/'))
|
||||||
|
#sys.path.append(os.path.abspath('../../scaffold/'))
|
||||||
|
|
||||||
|
from website import index
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
index.app.run(host='0.0.0.0', port=5001, debug=True)
|
|
@ -0,0 +1,26 @@
|
||||||
|
import os
|
||||||
|
from setuptools import setup, find_packages
|
||||||
|
|
||||||
|
|
||||||
|
def read(fname):
|
||||||
|
return open(os.path.join(os.path.dirname(__file__), fname)).read()
|
||||||
|
|
||||||
|
setup(
|
||||||
|
name = "mhackspace",
|
||||||
|
version = "0.0.1",
|
||||||
|
author = "Oliver Marks",
|
||||||
|
author_email = "contact@maidstone-hackspace.org.uk",
|
||||||
|
description = ("Maidstone Hackspace website"),
|
||||||
|
license = "MIT",
|
||||||
|
keywords = "templating web",
|
||||||
|
url = "https://maidstone-hackspace.org.uk",
|
||||||
|
packages=find_packages(),
|
||||||
|
|
||||||
|
long_description=read('README.md'),
|
||||||
|
classifiers=[
|
||||||
|
"Development Status :: 3 - Alpha",
|
||||||
|
"Topic :: Utilities",
|
||||||
|
"License :: OSI Approved :: MIT",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1,19 @@
|
||||||
|
#!/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()
|
|
@ -0,0 +1,60 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import os, sys
|
||||||
|
import unittest
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
from website.config import settings
|
||||||
|
from website.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)
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,88 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import os, sys
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
from werkzeug.security import generate_password_hash, check_password_hash
|
||||||
|
|
||||||
|
from website.config import settings
|
||||||
|
from website.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)
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,31 @@
|
||||||
|
#!/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 scaffold.core.data.sql import query
|
||||||
|
from scaffold.core.data.database import db
|
||||||
|
|
||||||
|
from website.config import settings
|
||||||
|
from website.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')
|
||||||
|
})
|
Binary file not shown.
|
@ -0,0 +1,38 @@
|
||||||
|
#!/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)
|
||||||
|
|
Binary file not shown.
|
@ -0,0 +1,37 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
import os, sys
|
||||||
|
import unittest
|
||||||
|
from collections import defaultdict
|
||||||
|
|
||||||
|
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):
|
||||||
|
result = site_user.update_oauth_login().execute({
|
||||||
|
'user_id': '2',
|
||||||
|
'username': 'nick_modified',
|
||||||
|
'provider': '3',
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
unittest.main(buffer=False)
|
Binary file not shown.
|
@ -0,0 +1,87 @@
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
from flask import Flask, send_from_directory
|
||||||
|
from flask import make_response
|
||||||
|
|
||||||
|
sys.path.append(os.path.abspath('../../../scaffold/'))
|
||||||
|
sys.path.insert(0,os.path.abspath('../../../scaffold/'))
|
||||||
|
|
||||||
|
from config import settings
|
||||||
|
import generate
|
||||||
|
from pages import homepage
|
||||||
|
from pages import chat
|
||||||
|
from pages import blog
|
||||||
|
from pages import members
|
||||||
|
from pages.contact import contact_page, submit_contact_page
|
||||||
|
|
||||||
|
from pages.core.login_pages import login_pages
|
||||||
|
from pages.core.authorize import authorize_pages, login_manager
|
||||||
|
from pages.donate import donate_pages
|
||||||
|
from pages.google_groups import google_groups_pages
|
||||||
|
from pages.equipment import equipment_pages
|
||||||
|
from pages.profile import profile_pages
|
||||||
|
|
||||||
|
|
||||||
|
web_app = Flask(__name__, static_folder='static')
|
||||||
|
web_app.config['PROPAGATE_EXCEPTIONS'] = True
|
||||||
|
web_app.secret_key = settings.flask_secret_key
|
||||||
|
login_manager.init_app(web_app)
|
||||||
|
|
||||||
|
web_app.register_blueprint(login_pages)
|
||||||
|
web_app.register_blueprint(authorize_pages)
|
||||||
|
web_app.register_blueprint(equipment_pages)
|
||||||
|
web_app.register_blueprint(profile_pages)
|
||||||
|
web_app.register_blueprint(google_groups_pages)
|
||||||
|
web_app.register_blueprint(donate_pages)
|
||||||
|
|
||||||
|
#~ @web_app.route('/static/<path:filename>')
|
||||||
|
#~ def send_js(filename):
|
||||||
|
#~ print filename
|
||||||
|
#~ print send_from_directory('/static_resources/', filename)
|
||||||
|
#~ path = os.path.abspath('./static_resources/')
|
||||||
|
#~ print path + 'css/'
|
||||||
|
#~ return send_from_directory(path + 'css/', 'default.css')
|
||||||
|
|
||||||
|
# local testing server, add your pages here
|
||||||
|
@web_app.route("/examples/", methods=['GET'])
|
||||||
|
def examples():
|
||||||
|
"""temporary for testing / examples"""
|
||||||
|
return make_response(generate.examples())
|
||||||
|
|
||||||
|
@web_app.route("/blogs/", methods=['GET'])
|
||||||
|
def blogs():
|
||||||
|
"""temporary for testing / examples"""
|
||||||
|
return make_response(blog.index())
|
||||||
|
|
||||||
|
@web_app.route("/", methods=['GET'])
|
||||||
|
def index():
|
||||||
|
"""home page"""
|
||||||
|
return make_response(homepage.index())
|
||||||
|
|
||||||
|
@web_app.route("/members/", methods=['GET'])
|
||||||
|
def members_index():
|
||||||
|
"""list of members"""
|
||||||
|
return make_response(members.index())
|
||||||
|
|
||||||
|
@web_app.route("/members/<user_id>/<name>", methods=['GET'])
|
||||||
|
def members_profile(user_id, name):
|
||||||
|
"""members profile"""
|
||||||
|
return make_response(members.profile(user_id, name))
|
||||||
|
|
||||||
|
@web_app.route("/chat/", methods=['GET'])
|
||||||
|
def chat_index():
|
||||||
|
"""competition page"""
|
||||||
|
return make_response(chat.index())
|
||||||
|
|
||||||
|
@web_app.route("/contact-us/", methods=['GET'])
|
||||||
|
def contact_us():
|
||||||
|
"""Contact page"""
|
||||||
|
return make_response(contact_page())
|
||||||
|
|
||||||
|
@web_app.route("/contact-us/", methods=['POST'])
|
||||||
|
def submit_contact_us():
|
||||||
|
"""Contact page"""
|
||||||
|
return make_response(submit_contact_page())
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
web_app.run(host='0.0.0.0', port=5000, debug=True)
|
Loading…
Reference in New Issue