class TestTaskLoader(TestCase):

    def setUp(self):
        self.app = Application()
        
    def tearDown(self):
        self.app.reset()

    def test_resolve_category(self):
        category = self.app.taskloader.__resolve_category__('test', '/')
        self.assertEqual('/test', category)

    def test_resolve_category_without_delimiter(self):
        category = self.app.taskloader.__resolve_category__('test', '')
        self.assertEqual('test', category)

    def test_resolve_classname(self):
        classname = self.app.taskloader.__resolve_classname__('TestClass')
        self.assertEqual('Test Class', classname)

    def test_resolve_classname_camelcase(self):
        classname = self.app.taskloader.__resolve_classname__('testClass')
        self.assertEqual('Test Class', classname)

    def test_resolve_classname_lowercase(self):
        classname = self.app.taskloader.__resolve_classname__('testclass')
        self.assertEqual('Testclass', classname)

    def test_load_tasks(self):
        tasks = self.app.taskloader.load_tasks('test')
        self.assertEqual(1, len(tasks))
        self.assertEqual(tasks[0].title, 'Test Task')
        self.assertEqual(tasks[0].description, 'This is a test task')
class TestJob(TestCase):
    def setUp(self):
        self.app = Application()

    def tearDown(self):
        self.app.reset()

    def test_add_job(self):
        service = JobService(self.app.database, self.app.storage)
        service.create_job('Test title', 'Test description')

        jobs = service.get_jobs()
        self.assertEqual(1, len(jobs))
        self.assertEqual(jobs[0].title, 'Test title')
        self.assertTrue(os.path.exists(jobs[0].directory))

    def test_add_job_without_title(self):
        service = JobService(self.app.database, self.app.storage)
        service.create_job(None)

        jobs = service.get_jobs()
        self.assertEqual(0, len(jobs))

    def test_add_steps_to_job(self):
        service = JobService(self.app.database, self.app.storage)
        service.create_job('Test title', 'Test description')

        jobs = service.get_jobs()
        job_id = jobs[0].id

        step1_parameter1 = TaskParameter(key='step1_key1',
                                         value='step1_value1')
        step1_parameter2 = TaskParameter(key='step1_key2',
                                         value='step1_value2')

        step1 = Step('Test step 1', job_id)
        step1.parameters = [step1_parameter1, step1_parameter2]

        step2_parameter1 = TaskParameter(key='step2_key1',
                                         value='step2_value1')
        step2_parameter2 = TaskParameter(key='step2_key2',
                                         value='step2_value2')
        step2_parameter3 = TaskParameter(key='step2_key3',
                                         value='step2_value3')

        step2 = Step('Test step 2', job_id)
        step2.parameters = [
            step2_parameter1, step2_parameter2, step2_parameter3
        ]

        service.add_steps(job_id, [step1, step2])

        steps = service.get_steps(job_id)
        self.assertEqual(2, len(steps))
        self.assertEqual('Test step 1', steps[0].title)
def test_create_tribe():
    """ Happy path for creating a tribe """

    app = Application("test")
    test_client = app.flask.test_client()

    response = test_client.post("/tribe/create",
                                json={
                                    "name": "Test Tribe",
                                    "latitude": 50.5,
                                    "longitude": 0.1
                                })

    assert response.status == "201 CREATED"

    response_body = response.get_json()

    assert response_body.get("status") == "Success"

    created_tribe = response_body.get("tribe", None)

    assert created_tribe is not None
    assert UUID4_REGEX.match(created_tribe.get("public_id"))
    assert created_tribe.get("latitude") == 50.5
    assert created_tribe.get("longitude") == 0.1
    assert created_tribe.get("name") == "Test Tribe"
def test_create_tribe_admin_user_taken():
    app = Application("test")
    test_client = app.flask.test_client()

    response = test_client.post("/tribe/create",
                                json={
                                    "name": "Test Tribe",
                                    "latitude": 50.5,
                                    "longitude": 0.5
                                })
    assert response.status_code == 201

    tribe_id = response.get_json().get("tribe").get("public_id")

    response = test_client.post(f"/tribe/{tribe_id}/admin",
                                json={
                                    "name": "TestName",
                                    "username": "******",
                                    "password": "******"
                                })
    assert response.status_code == 201

    response = test_client.post(f"/tribe/{tribe_id}/admin",
                                json={
                                    "name": "TestName",
                                    "username": "******",
                                    "password": "******"
                                })
    assert response.status_code == 400
    body = response.get_json()

    assert body.get("status") == "Failure"
    assert body.get("message") == "Username is already taken"
Example #5
0
class TestTask(TestCase):
    def setUp(self):
        self.app = Application()

    def tearDown(self):
        self.app.reset()

    def test_load_tasks(self):
        service = TaskService(self.app.taskloader)
        tasks = service.get_all_tasks('test')
        self.assertEqual(1, len(tasks))
        self.assertEqual(tasks[0].title, 'Test Task')
        self.assertEqual(tasks[0].description, 'This is a test task')

    def test_get_input(self):
        service = TaskService(self.app.taskloader)
        tasks = service.get_all_tasks('test')
        inputs = service.get_inputs(tasks[0].id)
        self.assertEqual(2, len(inputs))
        self.assertEqual('test1', inputs[0].key)
        self.assertEqual(False, inputs[1].required)
Example #6
0
class TestBuild(TestCase):
    def setUp(self):
        self.app = Application()

    def tearDown(self):
        self.app.reset()

    def test_queue_build(self):
        build_service = BuildService(self.app.database)
        job_service = JobService(self.app.database, self.app.storage)

        job_service.create_job('Test job')
        job = job_service.get_jobs()[0]

        self.assertIsNotNone(job)

        build_service.queue_build(job.id)
        build_service.queue_build(job.id)

        builds = build_service.get_queue_builds(job.id)

        self.assertEqual(2, len(builds))
        self.assertFalse(builds[0].id == builds[1].id)
def test_create_tribe_admin_no_tribe():
    """ Test creating a new tribe admin when the tribe does not exist """

    app = Application("test")
    test_client = app.flask.test_client()

    response = test_client.post("/tribe/nonexistenttribe/admin",
                                json={
                                    "name": "TestName",
                                    "username": "******",
                                    "password": "******"
                                })

    assert response.status_code == 404
    body = response.get_json()

    assert body.get("status") == "Failure"
    assert body.get("message") == "Tribe not found"
def test_create_tribe_admin():
    """ Happy path for creating an admin """
    app = Application("test")
    test_client = app.flask.test_client()

    response = test_client.post("/tribe/create",
                                json={
                                    "name": "Test Tribe",
                                    "latitude": 50.5,
                                    "longitude": 0.5
                                })

    assert response.status_code == 201

    tribe = response.get_json().get("tribe")

    assert tribe is not None

    tribe_public_id = tribe.get("public_id")
    tribe_private_id = tribe.get("id")
    assert UUID4_REGEX.match(tribe_public_id)

    response = test_client.post(f"/tribe/{tribe_public_id}/admin",
                                json={
                                    "name": "Test Admin",
                                    "username":
                                    "******",
                                    "password": "******"
                                })

    assert response.status_code == 201

    admin_created_body = response.get_json()

    assert admin_created_body.get("status") == "Success"

    new_admin = admin_created_body.get("user")

    assert new_admin.get("name") == "Test Admin"
    assert new_admin.get("username") == "TestCreateTribeAdminHappyPath"
    assert new_admin.get("tribe_id") == tribe_private_id
    assert new_admin.get("role") == "tribeadmin"
from app.main import Application

import logging

if __name__ == '__main__':
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.INFO)
    app = Application()
    app.start()
Example #10
0
 def test_integrations(self):
     app = Application()
     app.start()
 def setUp(self):
     self.app = Application()
"""
Created 10/03/2021
Prod Server WSGI Script
"""

from app.main import Application

app = Application("prod")
flask = app.flask

if __name__ == "__main__":
    flask.run()
Example #13
0
 def test_integrations(self):
     app = Application()
     app.start()
Example #14
0
import csv
import os
import unittest
from datetime import datetime
from uuid import uuid4
import random
import inquirer
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from app.main.constants import UserRoles
from app.main import Application
from app.main.models import db
from app.main.models.user import User
from app.main.models.well import Well

app = Application(os.getenv("ENV") or "dev")

app.flask.app_context().push()

manager = Manager(app.flask)
migrate = Migrate(app.flask, db)

manager.add_command("db", MigrateCommand)


@manager.command
def run():
    """ Run the application in dev mode """
    app.flask.run(host="0.0.0.0", port=8080, debug=True)

def setup_test_environment():
    app = Application(os.environ.get("ENV", "prod"))

    with app.flask.app_context():
        # db.drop_all()
        db.create_all()
from app.main import Application

import logging

if __name__ == '__main__':
    logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',
                        level=logging.INFO)
    application = Application()
    application.start()