Пример #1
0
class AppTestCase(unittest.TestCase):
    def setUp(self):
        self.app = App()
        self.user = User('*****@*****.**', 'password', 'Patrick')

    def test_creation_of_app_obj(self):
        self.assertIsInstance(self.app, App, msg="Object not instance of App")

    def test_sign_up_to_app(self):
        """Should test if user successfully signs up to app"""
        self.app.sign_up(self.user)
        index = len(self.app.all_users) - 1
        self.assertEqual(self.app.all_users[index].name, 'Patrick')
        self.assertEqual(self.app.all_users[index].email, '*****@*****.**')
        self.assertEqual(self.app.all_users[index].password, 'password')

    def test_sign_up_with_exisiting_email(self):
        """Should test that user can sign up with same email"""
        self.app.sign_up(self.user)
        self.assertFalse(self.app.sign_up(self.user))
        self.user = User('*****@*****.**', 'password', 'Patrick')
        self.assertTrue(self.app.sign_up(self.user))

    def test_sign_in_to_app(self):
        self.app.sign_up(self.user)
        self.assertTrue(self.app.sign_in(self.user),
                        msg='Should return True for sign in')
Пример #2
0
	def init():
		path = App.get_url().path

		if path is '/':
			body = App.stache('test', {
					"title":  "Welcome to Slither",
					"output": "The path is: %s" % path,
					"post":   App.fetch('post', 'test_input', ''),
				});
		else:
			App.status = '404 Not Found'
			body       = '404. bummer.'
		return body
Пример #3
0
def test_init_apps_from_test_params_w_replay_end_time():
    defaults = {
        "apps_to_test": ["test-app1", "test-app2", "test-app3"],
        "test_params": {
            "rate": 100,
            "replay_start_time": "2018-08-29T10:30",
            "replay_end_time": "2018-08-30T12:31",
            "base_url": "http://shadowreader.example.com",
            "identifier": "qa",
        },
        "overrides": [],
        "timezone": "Japan",
    }

    apps, test_params = orchestrator.init_apps_from_test_params(defaults)
    app1 = apps[0]
    app2 = App(
        name="test-app1",
        replay_start_time=MyTime(year=2018,
                                 month=8,
                                 day=29,
                                 hour=10,
                                 minute=30,
                                 tzinfo="Japan"),
        rate=100,
        base_url="http://shadowreader.example.com",
        identifier="qa",
        loop_duration=1561,
        baseline=0,
    )

    assert app1 == app2
    assert len(apps) == 3
    assert app2.replay_start_time == app1.replay_start_time
Пример #4
0
def test_init_apps_from_test_params():
    defaults = {
        'apps_to_test': ['test-app1', 'test-app2', 'test-app3'],
        'test_params': {
            "rate": 100,
            "loop_duration": 60,
            "replay_start_time": "2018-3-20-16-00",
            "base_url": "http://shadowreader.example.com",
            "identifier": "qa",
        },
        "overrides": [],
        'timezone': 'US/Pacific'
    }

    apps, test_params = orchestrator.init_apps_from_test_params(defaults)
    app1 = apps[0]
    app2 = App(name='test-app1',
               replay_start_time=MyTime().from_epoch(epoch=1521586800,
                                                     tzinfo='US/Pacific'),
               rate=100,
               base_url='http://shadowreader.example.com',
               identifier='qa',
               loop_duration=60,
               baseline=0)

    assert app1 == app2 and len(apps) == 3
Пример #5
0
def test_init_apps_from_test_params_w_isoformat():
    defaults = {
        "apps_to_test": ["test-app1", "test-app2", "test-app3"],
        "test_params": {
            "rate": 100,
            "loop_duration": 60,
            "replay_start_time": "2018-08-02T00:30",
            "base_url": "http://shadowreader.example.com",
            "identifier": "qa",
        },
        "overrides": [],
        "timezone": "US/Pacific",
    }

    apps, test_params = orchestrator.init_apps_from_test_params(defaults)
    app1 = apps[0]
    app2 = App(
        name="test-app1",
        replay_start_time=MyTime().from_epoch(epoch=1533195000,
                                              tzinfo="US/Pacific"),
        rate=100,
        base_url="http://shadowreader.example.com",
        identifier="qa",
        loop_duration=60,
        baseline=0,
    )
    assert app1 == app2 and len(apps) == 3
    assert app2.replay_start_time == app1.replay_start_time
Пример #6
0
def _init_app_obj_from_params(app_name: str, params: dict,
                              tzinfo: timezone) -> App:
    """
    "rate": 50,
    "loop_duration": 60,
    "replay_start_time": "2018-3-26-12-30",
    "base_url": "https://www.my-website.com",
    "identifier": "qa",
    "env_to_test": "qa"
    """
    rate = params["rate"]
    if "baseline" in params:
        baseline = params["baseline"]
    else:
        baseline = 0

    base_url = params["base_url"]

    identifier = params["identifier"] if "identifier" in params else ""

    replay_duration, replay_start_time = determine_replay_time_window(
        params, tzinfo)

    return App(
        name=app_name,
        replay_start_time=replay_start_time,
        loop_duration=replay_duration,
        base_url=base_url,
        rate=rate,
        baseline=baseline,
        identifier=identifier,
    )
Пример #7
0
def test_validate_base_url():
    mytime = MyTime(epoch=1522091259)
    base_url = 'shadowreader.example.com/'
    app = App(name='test',
              replay_start_time=mytime,
              loop_duration=60,
              base_url=base_url,
              rate=100,
              identifier='qa',
              baseline=100)
    assert app.base_url == 'https://shadowreader.example.com'
Пример #8
0
def test_app_str():
    mytime = MyTime(epoch=1522091259)
    base_url = 'http://shadowreader.example.com'
    app = App(name='test',
              replay_start_time=mytime,
              loop_duration=60,
              base_url=base_url,
              rate=100,
              identifier='qa',
              baseline=100)
    s = 'App(name="test", replay_start_time=2018-03-26 19:07:39 UTC, loop_duration=60, base_url="http://shadowreader.example.com", identifier="qa", rate=100, cur_timestamp=1522091259, baseline=100)'
    assert str(app) == s
Пример #9
0
def test_app_init():
    mytime = MyTime()
    base_url = 'http://shadowreader.example.com'
    app = App(name='test',
              replay_start_time=mytime,
              loop_duration=60,
              base_url=base_url,
              rate=100,
              baseline=0)
    assert app.name == 'test' and app.loop_duration == 60 and app.base_url == base_url
    assert app.cur_timestamp == mytime.epoch and app.rate == 100 and app.identifier == base_url
    assert app.baseline == 0
Пример #10
0
def test_validate_base_url():
    mytime = MyTime(epoch=1522091259)
    base_url = "shadowreader.example.com/"
    app = App(
        name="test",
        replay_start_time=mytime,
        loop_duration=60,
        base_url=base_url,
        rate=100,
        identifier="qa",
        baseline=100,
    )
    assert app.base_url == "http://shadowreader.example.com"
Пример #11
0
def main(argv):
    app = App(config._sections['app'], argv)

    try:
        t_collector = threading.Thread(name='app.collector',
                                       target=app.collector)
        t_collector.start()

        t_display = threading.Thread(name='app.display', target=app.display)
        t_display.start()

        t_alerting = threading.Thread(name='app.alerting', target=app.alerting)
        t_alerting.start()

    except KeyboardInterrupt:
        print('Manual break by user')
Пример #12
0
def test_app_init_w_identifier():
    mytime = MyTime()
    base_url = "http://shadowreader.example.com"
    app = App(
        name="test",
        replay_start_time=mytime,
        loop_duration=60,
        base_url=base_url,
        rate=100,
        identifier="qa",
        baseline=999,
    )
    assert app.name == "test" and app.loop_duration == 60 and app.base_url == base_url
    assert (
        app.cur_timestamp == mytime.epoch and app.rate == 100 and app.identifier == "qa"
    )
    assert app.baseline == 999
Пример #13
0
def test_init_apps_from_test_params_w_override():
    defaults = {
        "apps_to_test": ["test-app1", "test-app2"],
        "test_params": {
            "rate": 100,
            "loop_duration": 60,
            "replay_start_time": "2018-3-20-16-00",
            "base_url": "http://shadowreader.example.com",
            "identifier": "qa",
        },
        "overrides": [
            {
                "app": "test-app1",
                "rate": 50,
                "loop_duration": 30,
                "replay_start_time": "2018-3-20-17-00",
                "base_url": "http://shadowreader.example.com",
                "identifier": "qa",
            },
            {
                "app": "test-app2",
                "rate": 0,
                "loop_duration": 30,
                "replay_start_time": "2018-3-20-17-00",
                "base_url": "http://shadowreader.example.com",
                "identifier": "qa",
            },
        ],
        "timezone":
        "US/Pacific",
    }

    apps, test_params = orchestrator.init_apps_from_test_params(defaults)
    app1 = apps[0]
    app1_copy = App(
        name="test-app1",
        replay_start_time=MyTime(epoch=1521590400),
        rate=50,
        base_url="http://shadowreader.example.com",
        identifier="qa",
        loop_duration=30,
        baseline=0,
    )

    assert app1 == app1_copy and len(apps) == 1
Пример #14
0
def test_user_agent_generation_for_past():
    mytime = MyTime(epoch=1520020741)
    stage = 'local'
    step = 1234
    base_url = 'http://shadowreader.example.com'
    app = App(
            name='my-test-app',
            replay_start_time=mytime,
            loop_duration=60,
            base_url=base_url,
            rate=100,
            baseline=0
    )
    headers = Headers(
            shadowreader_type='past', stage=stage, app=app, step=step).headers
    user_agent = headers['x-request-id']
    print(headers)
    assert user_agent == f'sr_local_past_{base_url}_my-test-app_03-02-2018-19-59_60m_20'
Пример #15
0
def test_user_agent_generation_for_past_w_identifier():
    mytime = MyTime(epoch=1520020741)
    stage = "local"
    step = 1234
    base_url = "http://shadowreader.example.com"
    app = App(
        name="my-test-app",
        replay_start_time=mytime,
        loop_duration=60,
        base_url=base_url,
        identifier="qa",
        rate=100,
        baseline=0,
    )
    headers = Headers(shadowreader_type="past",
                      stage=stage,
                      app=app,
                      step=step).headers
    user_agent = headers["x-request-id"]
    print(headers)
    assert user_agent == "sr_local_past_qa_my-test-app_03-02-2018-19-59_60m_20"
Пример #16
0
from datetime import time, date
from time import strftime, gmtime

from flask import Flask, render_template, \
    request, redirect, url_for, session, flash
from classes.user import User
from classes.bucket import Bucket
from classes.item import Item
from classes.app import App

app = Flask(__name__)
app.secret_key = 'MySecretKey'
all_items = []
current_user = None
bucketApp = App()


@app.route('/', methods=['GET'])
def index():
    return render_template('index.html')


@app.route('/signUp', methods=['POST'])
def sign_up():
    """
    Signs up user to the app
    """
    # Pick form values
    name = request.form['name']
    email = request.form['email']
    password = request.form['password']
Пример #17
0
from classes.app import App

if __name__ == "__main__":
    theApp = App()
    theApp.on_execute()
Пример #18
0
# -*- coding: utf-8 -*-
"""
######## Lemmings Game project for Computer Science Degree - UC3M Madrid ########
Authors:
Rosa A. Reyes
Paloma Nuñez

Directory Organisation:
    assets/
        lemming.pyxres # all of the project's sprites made with pyxeleditor.
    classes/
        __init__.py # Archive that makes possible to put subdirectories.
        app.py
        blocker.py
        cell.py
        gate.py
        ladder.py
        lemming.py
        marker.py
        umbrella.py
    .gitignore  # default archive to tell git what to not upload to Github.
    main.py     # main archive where we call the class App() where all the logic is executed.
    README.md   # project's description with main functions and functionality.
"""

from classes.app import App

App()
Пример #19
0
from flask import redirect, render_template, url_for, session, flash, \
                  request

from recipe_app import app

# import class objects
from classes.app import App
from classes.user import User
from classes.recipe_category import RecipeCategory
from classes.recipe import Recipe

# creating App object
recipe_app = App()

# Global user objects
current_user = None
recipes_category = None
recipe = None


# index route
@app.route('/', methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
def index():
    """Renders index or home page

        Returns:
            an index page template
    """
    if request.method == 'POST':
        # getting form variables
Пример #20
0
def handler(event, context):
    try:
        app = App()
        return app.get_params(event)
    except Exception as error:
        return {'statusCode': 200, 'body': error}
Пример #21
0
#! /usr/bin/env python
import pygame
from pygame.locals import *
from classes.globals import *

from classes.app import App
import json

DATA_DIR="data"
ASSETS_DIR="assets"

def read_map(filename):
	tmp = {}
	mapfile = open("%s/%s.dat"%(DATA_DIR,filename), "r")
	keyfile = open("%s/%s_keys.json"% (DATA_DIR, filename), "r")
	#keys = json.load(keyfile)
	#while line = mapfile.readline

if __name__ == "__main__" :
	file = open(DATA_DIR + "/sprites.json", "r")
	theApp = App()
	theApp._sprites = json.load(file)
	theApp.on_execute("%s/%s"%(ASSETS_DIR, "DungeonCrawl_ProjectUtumnoTileset.png"))
	map = read_map("map")
Пример #22
0
class ViewModel:
    """
        Klasa główna programu łącząca logikę klasy App z widokiem klasy Gui.
    """
    def __init__(self):
        self.app = App()
        self.gui = Gui()

    def run(self):
        """
            Metoda uruchamiająca program.
        """
        self.__login()
        self.gui.run()

    def info(self):
        """
            Metoda wyświetlająca informacje o aplikacji.
        """
        self.gui.info('Program SecretSanta służy do automatyzacji '
                      'zabawy w tajemniczego Świętego Mikołaja.')

    def __login(self):
        """
            Metoda dodająca do GUI przycisk logowania z odpowiednią akcją.
        """
        self.gui.add_login_button(self.__handle_login)

    def __handle_login(self):
        """
            Metoda łącząca się z pocztą Gmail i aktualizująca GUI po zalogowaniu.
        """
        try:
            self.app.login(self.gui.name, self.gui.login, self.gui.pwd)
            self.gui.delete_login_widgets()
            self.gui.add_user_info(self.app.user)
            self.gui.add_file_button(self.__handle_csv)
        except ConnectionRefusedError:
            self.gui.error('Nie udało się połączyć z serwerem poczty.')
        except smtplib.SMTPServerDisconnected:
            self.gui.error('Nieprawidłowy login lub hasło')
        except smtplib.SMTPAuthenticationError:
            self.gui.error('Nie udało się zalogować.\n'
                           'Być może nie został włączony "Dostęp mniej bezpiecznych aplikacji"')
        except smtplib.SMTPException:
            self.gui.error('Nie udało się zalogować.\n'
                           'Być może nie został włączony "Dostęp mniej bezpiecznych aplikacji"')
        except Exception as error:
            self.gui.error('Nieznany błąd:\n' + str(error))

    def __handle_csv(self):
        """
            Metoda wczytująca plik CSV z uczestnikami i aktualizująca GUI.
        """
        try:
            file = self.gui.ask_file()
            self.app.load_players_csv(file)
            self.gui.delete_file_button()
            self.gui.add_players_list(self.app.get_players_info())
            self.gui.add_execute_button(self.__handle_execution)
        except FileNotFoundError as error:
            self.gui.error(str(error))
        except PermissionError as error:
            self.gui.error(str(error))
        except OSError as error:
            self.gui.error(str(error))
        except IndexError as error:
            self.gui.error(str(error))

    def __handle_execution(self):
        """
            Metoda wysyłająca maile i aktualizująca GUI.
        """
        self.app.execute_emails()
        self.gui.finish()
Пример #23
0
 def __init__(self):
     self.app = App()
     self.gui = Gui()
Пример #24
0
 def setUp(self):
     self.app = App()
     self.user = User('*****@*****.**', 'password', 'Patrick')
Пример #25
0
from classes.app import App

app = App()

if __name__ == '__main__':
    ans = app.add(4, 6)
    sub = app.subt(8, 7)
    print(ans, sub)
Пример #26
0
class TestAppCase(unittest.TestCase):
    def setUp(self):
        self.app = App()
        self.user = User('*****@*****.**', 'pato123', 'Patrick',
                         'Walukagga')

    def test_signup_user_is_created(self):
        self.app.signup_user(self.user)
        self.assertEqual(len(self.app.users), 1)
        index = len(self.app.users) - 1
        self.assertEqual(self.app.users[index].email, '*****@*****.**')
        self.assertEqual(self.app.users[index].password, 'pato123')
        self.assertEqual(self.app.users[index].first_name, 'Patrick')
        self.assertEqual(self.app.users[index].last_name, 'Walukagga')

    def test_signup_user_with_same_email_already_exists(self):
        self.app.signup_user(self.user)
        self.user = User('*****@*****.**', 'pat123', 'Rickson',
                         'Walukagga')
        self.assertFalse(self.app.signup_user(self.user))

    def test_signup_user_returns_correct_id(self):
        self.app.signup_user(self.user)
        self.assertEqual(len(self.app.users), 1)
        self.user = User('*****@*****.**', 'henry123', 'Henry', 'Kato')
        self.app.signup_user(self.user)
        self.assertEqual(len(self.app.users), 2)
        self.user = User('*****@*****.**', 'henry0009', 'Henry', 'Mutunji')
        self.app.signup_user(self.user)
        self.assertEqual(len(self.app.users), 3)

    def test_signin_user_logins_successfully(self):
        self.app.signup_user(self.user)
        self.user = User('*****@*****.**', 'pato123')
        self.assertEqual(self.app.signin_user(self.user), 1)

    def test_signin_user_login_fails_with_wrong_email_password(self):
        self.app.signup_user(self.user)
        self.user = User('*****@*****.**', 'pat1234')
        self.assertFalse(self.app.signin_user(self.user))
Пример #27
0
 def setUp(self):
     self.app = App()
     self.user = User('*****@*****.**', 'pato123', 'Patrick',
                      'Walukagga')
Пример #28
0
def application(env, response):
	return App.bootstrap(env, response)