Example #1
0
def after_scenario(context, step):
    Base.metadata.drop_all()
    DBSession.remove()

    from augias.utils import cache

    del cache.backend
Example #2
0
    def test_list_if_user_has_invites_and_no_notebook(self):
        user = User(email='*****@*****.**')
        notebook = Notebook(name='some notebook', invites=[user.email])
        DBSession.add_all([user, notebook])

        result = self._call_view(user=user)

        self.assertEqual(result['notebooks'], [])
        self.assertEqual(result['invites'], [notebook.inv[0]])
Example #3
0
    def test_last_user_deletes_notebook(self):
        from augias.views import notebook_delete_post
        user = User(email='*****@*****.**')
        notebook = Notebook(name='wizzz', users=[user])
        DBSession.add_all([user, notebook])
        self.assertEqual(Notebook.query().count(), 1)
        request = DummyRequest(user=user)

        result = notebook_delete_post(notebook, request)

        self.assertEqual(Notebook.query().count(), 0)
Example #4
0
    def test_execute_invalid_duration(self):
        from augias.views import execute
        task = self._get_task()
        user = User(email='*****@*****.**')
        DBSession.add(user)
        request = DummyRequest({'length': 'this is no integer', 'executor': user.email})

        result = execute(task, request)

        self.assertEqual(result.code, 302)
        request.flash_error.assert_called_once_with('Invalid length "this is no integer"')
Example #5
0
def step(context, name):
    email, assertion = get_email_and_assertion('http://example.com')
    with transaction.manager:
        user = User(email=email, name=name)
        DBSession.add(user)

    result = context.app.get('/')
    token = re.findall(r"csrf_token: '([0-9a-f]*)'", result.unicode_body)[0]
    context.app.post('/login', {'assertion': assertion,
                                'csrf_token': token,
                                'came_from': '/'})
    context.last['user'] = user
Example #6
0
    def test_redirect_to_notebook_if_user_has_one_and_no_invites(self):
        user = User(email='*****@*****.**')
        notebook = Notebook(name='some notebook', users=[user])
        DBSession.add_all([user, notebook])
        DBSession.flush()
        self.assertEqual(Notebook.query().count(), 1)

        result = self._call_view(user=user)

        self.assertEqual(Notebook.query().count(), 1)
        self.assertEqual(result.code, 302)
        self.assertEqual(result.location, DummyRequest().resource_url(notebook))
Example #7
0
    def test_execute_with_colon_duration(self):
        from augias.views import execute
        task = self._get_task()
        user = User(email='*****@*****.**')
        DBSession.add(user)
        request = DummyRequest({'length': '1:30:41', 'executor': user.email})
        request.flash_success = create_autospec(lambda x: None)

        result = execute(task, request)

        self.assertEqual(result.code, 302)
        execution = DBSession.query(Execution).one()
        self.assertEqual(execution.length, 91)
Example #8
0
def main(argv=sys.argv):
    config_uri = argv[1]
    options = [arg for arg in argv[2:] if '=' in arg]
    options = parse_vars(options)
    env = bootstrap(config_uri, options=options)
    setup_logging(config_uri)
    emails = [arg for arg in argv[2:] if '=' not in arg]
    with transaction.manager:
        for email in emails:
            print('Adding user {}'.format(email))
            user = User(email=email)
            DBSession.add(user)

    env['closer']()
Example #9
0
    def test_execute_without_duration(self):
        from augias.views import execute
        task = self._get_task()
        user = User(email='*****@*****.**')
        DBSession.add(user)
        request = DummyRequest({'length': '', 'executor': user.email})

        result = execute(task, request)

        self.assertEqual(result.code, 302)
        execution = DBSession.query(Execution).one()
        self.assertEqual(execution.executor, user)
        self.assertEqual(execution.length, None)
        request.flash_success.assert_called_once_with('Task executed')
Example #10
0
def main(argv=sys.argv):
    config_uri = argv[1]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri)
    engine = engine_from_config(settings, 'sqlalchemy.')
    DBSession.configure(bind=engine)
    import augias.tests  # for the null cache backend
    from augias.utils import cache
    cache.configure('null')
    with transaction.manager:
        user = get_user('*****@*****.**')
        for t in DBSession.query(Task).all():
            if random.random() < 0.2:
                t.last_execution = None
            else:
                exec_time = datetime.datetime.now() - datetime.timedelta(days=t.periodicity * random.random() * 1.5)
                t.execute(user, 10, exec_time)
Example #11
0
    def test_new_task(self):
        from augias.views import new_task
        user = User(email='*****@*****.**')
        notebook = Notebook(users=[user], name='some notebook')
        DBSession.add_all([user, notebook])
        request = DummyRequest(dict(name='Task name',
                                    periodicity=12))

        result = new_task(notebook, request)

        self.assertEqual(result.code, 302)
        task = DBSession.query(Task).one()
        self.assertEqual(task.name, 'Task name')
        self.assertEqual(task.periodicity, 12)
        self.assertEqual(task.notebook, notebook)
        self.assertEqual(len(task.executions), 0)
        self.assertEqual(task.last_execution, None)
Example #12
0
    def test_execute_collective(self):
        from augias.views import execute
        task = self._get_task()
        request = DummyRequest({'length': '15', 'executor': ''})

        result = execute(task, request)

        self.assertEqual(result.code, 302)
        execution = DBSession.query(Execution).one()
        self.assertEqual(execution.executor, None)
        self.assertEqual(execution.length, 15)
        request.flash_success.assert_called_once_with('Task executed')
Example #13
0
    def test_deleting_a_notebook_deletes_the_tasks(self):
        notebook = Notebook(name='tagada', users=[])
        task = Task(notebook=notebook, name='stuff', periodicity=42)
        DBSession.add_all([notebook, task])
        DBSession.flush()

        DBSession.delete(notebook)

        self.assertEqual(Task.query().count(), 0)
Example #14
0
    def test_deleting_a_task_deletes_the_executions(self):
        notebook = Notebook(name='tagada', users=[])
        task = Task(notebook=notebook, name='stuff', periodicity=42)
        DBSession.add_all([notebook, task])
        DBSession.flush()
        task.execute(None, 12)
        self.assertEqual(Execution.query().count(), 1)

        DBSession.delete(task)

        self.assertEqual(Execution.query().count(), 0)
Example #15
0
def report_for_range(notebook, begin, end):
    from augias.models import DBSession, Execution, Task
    executions = (DBSession.query(Execution)
                  .filter(Execution.time.between(begin, end))
                  .join('task').filter(Task.notebook==notebook)).all()

    total = ExecutionTime()
    by_person = defaultdict(ExecutionTime)
    by_task = defaultdict(lambda: defaultdict(ExecutionTime))

    for e in executions:
        total.add(e)
        by_person[e.executor].add(e)
        by_task[e.task][e.executor].add(e)
        by_task[e.task]['total'].add(e)

    def sorter(item):
        task, executions = item
        return (-executions['total'].total, task.name)

    by_task = sorted(by_task.items(), key=sorter)

    return {'total': total, 'by_task': by_task, 'by_person': by_person}
Example #16
0
 def tearDown(self):
     DBSession.remove()
     testing.tearDown()
Example #17
0
 def __getitem__(self, item):
     return DBSession.merge(super().__getitem__(item))
Example #18
0
 def _get_task(self):
     notebook = Notebook(name='some notebook')
     task = Task(name='some task', notebook=notebook, periodicity=42)
     DBSession.add_all([notebook, task])
     return task
Example #19
0
def step(context, name):
    with transaction.manager:
        notebook = Notebook(name=name)
        DBSession.add(notebook)
    context.last['notebook'] = notebook
Example #20
0
def step(context, name):
    notebook = DBSession.query(Notebook).one()
    with transaction.manager:
        task = Task(name=name, periodicity=42, notebook=notebook)
        DBSession.add(task)
    context.last['task'] = task
Example #21
0
 def setUp(self):
     self.config = testing.setUp()
     Base.metadata.create_all(self.engine)
     DBSession.configure(bind=self.engine)