Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Testing harness update #916

Merged
merged 7 commits into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
key: deps-v3-1663187796-{{ checksum "requirements/dev.txt" }}
paths:
- "/home/circleci/.local"
- run: nosetests apollo/
- run: pytest -v apollo/
resource_class: large

workflows:
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
FROM python:3.6
ARG ENV

LABEL maintainer="Tim Akinbo <[email protected]>"

ADD requirements/ /app/requirements/
RUN pip install --no-cache-dir -r /app/requirements/prod.txt
ADD build.sh /app/
RUN /app/build.sh
ADD . /app/
RUN cd /app/ \
&& make babel-compile
Expand Down
2 changes: 0 additions & 2 deletions apollo/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from flask_admin import expose, Admin, AdminIndexView
from flask_apispec import FlaskApiSpec
from flask_babelex import Babel
from flask_caching import Cache
from flask_cors import CORS
try:
from flask_debugtoolbar import DebugToolbarExtension
Expand Down Expand Up @@ -40,7 +39,6 @@ def index(self):
admin = Admin(
name='Apollo', index_view=AdminHome(name='Dashboard'))
babel = Babel()
cache = Cache()
cors = CORS()
db = SQLAlchemy(session_options={'expire_on_commit': False})
jwt_manager = JWTManager()
Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions apollo/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from apollo import settings
from apollo.api import hooks as jwt_hooks
from apollo.core import (
babel, cache, db, cors, debug_toolbar, fdt_available, jwt_manager,
babel, db, cors, debug_toolbar, fdt_available, jwt_manager,
mail, migrate, red, sentry, uploads)
from apollo.helpers import register_blueprints

Expand Down Expand Up @@ -89,7 +89,6 @@ def create_app(

sentry.init_app(app)
babel.init_app(app)
cache.init_app(app)
cors.init_app(app)
db.init_app(app)
jwt_manager.init_app(app)
Expand Down
12 changes: 6 additions & 6 deletions apollo/formsframework/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,12 +149,12 @@ def __call__(self, form, field):

class BaseQuestionnaireForm(wtforms.Form):
form = wtforms.StringField(
'Form', validators=[wtforms.validators.required()],
'Form', validators=[wtforms.validators.DataRequired()],
filters=[lambda data: filter_form(data)])
form_serial = wtforms.StringField(
'Form Serial', validators=[wtforms.validators.optional()])
sender = wtforms.StringField('Sender',
validators=[wtforms.validators.required()])
validators=[wtforms.validators.DataRequired()])
comment = wtforms.StringField('Comment',
validators=[wtforms.validators.optional()])

Expand Down Expand Up @@ -339,7 +339,7 @@ def build_questionnaire(form, data=None):
fields['participant'] = wtforms.StringField(
'Participant',
filters=[partial(filter_participants, form)],
validators=[wtforms.validators.required()])
validators=[wtforms.validators.DataRequired()])

for group in form.data['groups']:
groupspec = (group['name'], [])
Expand Down Expand Up @@ -397,15 +397,15 @@ def build_questionnaire(form, data=None):

class FormForm(SecureForm):
name = wtforms.StringField(
_('Name'), validators=[wtforms.validators.InputRequired()])
_('Name'), validators=[wtforms.validators.DataRequired()])
prefix = wtforms.StringField(
_('Form Code'), validators=[wtforms.validators.InputRequired()],
_('Form Code'), validators=[wtforms.validators.DataRequired()],
description=_('What code to identify this form in text messages.'))
form_type = wtforms.SelectField(
_('Form Type'), choices=Form.FORM_TYPES,
coerce=choice_type_coerce_factory(
Form.form_type.type),
validators=[wtforms.validators.InputRequired()])
validators=[wtforms.validators.DataRequired()])
untrack_data_conflicts = wtforms.BooleanField(
_("Don't Track Data Conflicts"),
description=_('Whether data conflicts between observers in the same location are tracked or not.')) # noqa
Expand Down
15 changes: 8 additions & 7 deletions apollo/formsframework/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,14 @@ def __init__(self):
self.param = None

def parse(self, source):
grammar = '\n'.join(v.__doc__ for k, v in list(vars(self.__class__).items())
if '__' not in k and hasattr(v, '__doc__')
and v.__doc__)
# using explicit raw-strings prevents a deprecation warning
# caused by the parsing of the escape sequences
grammar = r'''
expr = operator _ operand
operator = ">=" / "<=" / ">" / "<" / "=" / "!="
operand = ~"\\-?[0-9\\.]+" / "True" / "False"
_ = ~"\\s*"
'''
return Grammar(grammar).parse(source)

def eval(self, source, param=None):
Expand All @@ -89,20 +94,17 @@ def eval(self, source, param=None):
return method(node, [self.eval(n) for n in node])

def expr(self, node, children):
'expr = operator _ operand'
operator, _, operand = children
return operator(self.param, operand)

def operator(self, node, children):
'operator = ">=" / "<=" / ">" / "<" / "=" / "!="'
operators = {
'>': op.gt, '>=': op.ge,
'<': op.lt, '<=': op.le,
'=': op.eq, '!=': op.ne}
return operators[node.text]

def operand(self, node, children):
'operand = ~"\-?[0-9\.]+" / "True" / "False"'
if node.text == "True":
return True
elif node.text == "False":
Expand All @@ -111,5 +113,4 @@ def operand(self, node, children):
return float(node.text)

def _(self, node, children):
'_ = ~"\s*"'
pass
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from apollo.formsframework.models import Form
from apollo.formsframework.parser import Comparator, grammar_factory
from apollo.testutils import factory as test_factory, fixtures
from sqlalchemy.orm.session import close_all_sessions

DEFAULT_FIXTURE_PATH = pathlib.Path(__file__).parent / 'fixtures'

Expand Down Expand Up @@ -52,7 +53,7 @@ def setUp(self):
self.incident_form.data = {'groups': [grp2]}

def tearDown(self):
db.session.close_all()
close_all_sessions()
db.drop_all()

@mock.patch('apollo.formsframework.forms.filter_form')
Expand Down Expand Up @@ -98,7 +99,7 @@ def setUp(self):
db.create_all()

def tearDown(self):
db.session.close_all()
close_all_sessions()
db.drop_all()

def test_numeric_comparisons(self):
Expand Down Expand Up @@ -202,7 +203,7 @@ def setUp(self):
db.create_all()

def tearDown(self):
db.session.close_all()
close_all_sessions()
db.drop_all()

def test_active_form_selector(self):
Expand Down
Empty file removed apollo/frontend/tests/__init__.py
Empty file.
3 changes: 0 additions & 3 deletions apollo/frontend/tests/test_plain.py

This file was deleted.

7 changes: 0 additions & 7 deletions apollo/frontend/tests/test_ut.py

This file was deleted.

2 changes: 1 addition & 1 deletion apollo/locations/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def update_locations(
# spreadsheet structure

for idx in data_frame.index:
current_row = data_frame.ix[idx]
current_row = data_frame.iloc[idx]
location_path_helper_map = {}
error_this_row = False
warning_this_row = False
Expand Down
8 changes: 4 additions & 4 deletions apollo/messaging/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ class KannelForm(wtforms.Form):
:param charset: (Optional) character set for handling incoming message.
:param coding: (Optional) not being used at the moment.'''

sender = wtforms.StringField(validators=[wtforms.validators.required()])
text = wtforms.StringField(validators=[wtforms.validators.required()])
sender = wtforms.StringField(validators=[wtforms.validators.DataRequired()])
text = wtforms.StringField(validators=[wtforms.validators.DataRequired()])
charset = wtforms.StringField()
coding = wtforms.StringField()
timestamp = wtforms.IntegerField()
Expand Down Expand Up @@ -60,8 +60,8 @@ class TelerivetForm(BaseHttpForm):

id = wtforms.StringField()
from_number = wtforms.StringField(
validators=[wtforms.validators.required()])
content = wtforms.StringField(validators=[wtforms.validators.required()])
validators=[wtforms.validators.DataRequired()])
content = wtforms.StringField(validators=[wtforms.validators.DataRequired()])
time_created = wtforms.IntegerField()

def get_message(self):
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion apollo/participants/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def update_participants(dataframe, header_map, participant_set, task):
db.session.commit()

for idx in index:
record = dataframe.ix[idx]
record = dataframe.iloc[idx]
participant_id = record[PARTICIPANT_ID_COL]
try:
participant_id = int(participant_id)
Expand Down
8 changes: 4 additions & 4 deletions apollo/process_analysis/voting.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@


def proportion(df, options, param):
m = df.ix[:, options].sum(axis=1)
m = df.loc[:, options].sum(axis=1)
mbar = m.sum(axis=0) / m.size
return df.ix[:, param].sum(axis=0).sum(axis=0) / (mbar * m.size)
return df.loc[:, param].sum(axis=0).sum(axis=0) / (mbar * m.size)


def variance(df, options, param):
p = proportion(df, options, param)
psquared = p * p

m = df.ix[:, options].sum(axis=1)
m = df.loc[:, options].sum(axis=1)
msquared = m * m

a = df.ix[:, param].sum(axis=1)
a = df.loc[:, param].sum(axis=1)
asquared = a * a

mbar = m.sum(axis=0) / m.size
Expand Down
18 changes: 9 additions & 9 deletions apollo/result_analysis/views_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ def _voting_results(form_id, location_id=None):

try:
overall_summation = dataset.groupby(
location.location_type.name).sum().ix[location.name]
location.location_type.name).sum().loc[location.name]
reported_subset = dataset[dataset.reported == True] # noqa
valid_dataframe = reported_subset[
reported_subset[location.location_type.name] == location.name]
valid_summation = reported_subset.fillna(0).groupby(
location.location_type.name).sum().ix[location.name]
location.location_type.name).sum().loc[location.name]
reporting = overall_summation[['missing', 'reported']]
reporting['reported_pct'] = reporting['reported']/(
reporting['reported'] + reporting['missing'])
Expand Down Expand Up @@ -278,9 +278,9 @@ def _voting_results(form_id, location_id=None):

for sublocation in location_tree[location_type]:
try:
_overall = grouped_summation.ix[sublocation.name]
_overall = grouped_summation.loc[sublocation.name]
_valid = grouped_valid_summation.fillna(
0).ix[sublocation.name]
0).loc[sublocation.name]
_reported_subset = dataset[dataset.reported==True] # noqa
_valid_dataframe = _reported_subset[
_reported_subset[location_type] == sublocation.name]
Expand Down Expand Up @@ -526,22 +526,22 @@ def results_analysis_with_location(form_id, location_id):
def _point_estimate(dataframe, numerator, denominator):
if not isinstance(numerator, list):
numerator = [numerator]
m = dataframe.ix[:, denominator].sum(axis=1)
m = dataframe.loc[:, denominator].sum(axis=1)
mbar = m.sum(axis=0) / m.size
return dataframe.ix[:, numerator].sum(axis=0).sum(axis=0) / (mbar * m.size)
return dataframe.loc[:, numerator].sum(axis=0).sum(axis=0) / (mbar * m.size)


def _variance(dataframe, numerator, denominator):
p = _point_estimate(dataframe, numerator, denominator)
psquared = p * p

m = dataframe.ix[:, denominator].sum(axis=1)
m = dataframe.loc[:, denominator].sum(axis=1)
msquared = m * m

if isinstance(numerator, list):
a = dataframe.ix[:, numerator].sum(axis=1)
a = dataframe.loc[:, numerator].sum(axis=1)
else:
a = dataframe.ix[:, [numerator]].sum(axis=1)
a = dataframe.loc[:, [numerator]].sum(axis=1)
asquared = a * a

mbar = m.sum(axis=0) / m.size
Expand Down
4 changes: 2 additions & 2 deletions apollo/submissions/incidents.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ def incidents_csv(df, groupby, options):
for group in list(grouped.groups.keys()):
entry = {}
entry['LOC'] = group
entry['TOT'] = int(df.ix[grouped.groups[group]].ix[:, options].fillna(0).sum().sum())
entry['TOT'] = int(df.loc[grouped.groups[group]].loc[:, options].fillna(0).sum().sum())
for option in options:
try:
entry[option] = int(df.ix[grouped.groups[group]][option].fillna(0).sum())
entry[option] = int(df.loc[grouped.groups[group]][option].fillna(0).sum())
except KeyError:
entry[option] = 0
incidents.append(entry)
Expand Down
File renamed without changes.
7 changes: 7 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

if [ "${ENV}" = "DEV" ]; then
pip install --no-cache-dir -r /app/requirements/dev.txt
else
pip install --no-cache-dir -r /app/requirements/prod.txt
fi
4 changes: 2 additions & 2 deletions requirements/dev.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ autopep8
coverage
flake8
flask-debugtoolbar==0.10.1
flask-testing==0.7.1
flask-testing==0.8.1
mimesis
nose==1.3.7
pip-tools
pytest==7.0.1
Loading