Skip to content
This repository was archived by the owner on Sep 20, 2021. It is now read-only.

Commit 7ef8b8f

Browse files
committedJul 27, 2020
merge changes for issue #94
2 parents b53d891 + d72fd10 commit 7ef8b8f

File tree

7 files changed

+119
-6
lines changed

7 files changed

+119
-6
lines changed
 

‎backend/app/cp/domains.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,21 @@ def get_cp_domain(domain_id):
4242
SHOULD NOT be repeated.
4343
:status 404: Not found
4444
"""
45-
domain = Domain.query.get_or_404(domain_id)
45+
domain = Domain.query.get(domain_id)
4646
if not domain:
4747
abort(404)
4848

49-
#org = Organization.get(domain.organization_id)
5049
org = domain.organization
5150
if not org:
5251
abort(404)
5352
if not g.user.may_handle_organization(org):
5453
abort(401)
55-
return ApiResponse(domain.serialize())
54+
55+
#serialize() kills keys where value == 0
56+
domain_serialized = domain.serialize()
57+
if domain.notification_interval == 0:
58+
domain_serialized['notification_interval'] = 0
59+
return ApiResponse(domain_serialized)
5660

5761

5862
@cp.route('/domains', methods=['POST'])

‎backend/app/models.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -2102,7 +2102,7 @@ def load_user(user_id):
21022102

21032103
class Domain(Model, SerializerMixin):
21042104
__tablename__ = 'domains'
2105-
__public__ = ('id', 'organization_id', 'domain_name')
2105+
__public__ = ('id', 'organization_id', 'domain_name', 'delivery_protocol', 'delivery_format', 'notification_interval')
21062106
__table_args__ = (
21072107
db.UniqueConstraint('organization_id', 'domain_name'),
21082108
)
@@ -2112,6 +2112,9 @@ class Domain(Model, SerializerMixin):
21122112
_domain_name = db.Column('domain_name', db.String(255), nullable=False)
21132113
organization_id = db.Column(db.Integer, db.ForeignKey('organizations.id', ondelete="CASCADE"), nullable=False)
21142114
organization = db.relationship('Organization', back_populates='domains')
2115+
delivery_protocol = db.Column(db.Enum('Mail', 'REST API', 'AMQP', name='delivery_protocol_enum'), default='Mail')
2116+
delivery_format = db.Column(db.Enum('CSV', 'JSON', name='delivery_format_enum'), default='CSV')
2117+
notification_interval = db.Column(db.Integer, default=0)
21152118

21162119
@property
21172120
def domain_name(self):
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
"""empty message
2+
3+
Revision ID: 4f34c9a337ca
4+
Revises: None
5+
Create Date: 2020-07-24 15:04:52.900526
6+
7+
"""
8+
9+
# revision identifiers, used by Alembic.
10+
revision = '4f34c9a337ca'
11+
down_revision = None
12+
13+
from alembic import op
14+
import sqlalchemy as sa
15+
16+
17+
def upgrade():
18+
### commands auto generated by Alembic - please adjust! ###
19+
op.add_column('domains', sa.Column('delivery_format', sa.Enum('CSV', 'JSON', name='delivery_format_enum'), nullable=True))
20+
op.add_column('domains', sa.Column('delivery_protocol', sa.Enum('Mail', 'REST API', 'AMQP', name='delivery_protocol_enum'), nullable=True))
21+
op.add_column('domains', sa.Column('notification_interval', sa.Integer(), nullable=True))
22+
### end Alembic commands ###
23+
24+
25+
def downgrade():
26+
### commands auto generated by Alembic - please adjust! ###
27+
op.drop_column('domains', 'notification_interval')
28+
op.drop_column('domains', 'delivery_protocol')
29+
op.drop_column('domains', 'delivery_format')
30+
### end Alembic commands ###

‎backend/tests/test_cp_domains.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ def test_get_domain(client):
384384
url_for('cp.get_cp_domain', domain_id=domain.id),
385385
)
386386
assert rv.status_code == 200
387-
expectedkeys = ['id', 'domain_name', 'organization_id']
387+
expectedkeys = ['id', 'domain_name', 'organization_id', 'delivery_protocol', 'delivery_format', 'notification_interval']
388388
expectedkeys.sort()
389389
gotkeys = list(rv.json.keys())
390390
gotkeys.sort()

‎backend/tests/test_domains.py

+30-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class TDS:
1414
domain1 = 'domain1.at'
1515
domain2 = 'domain2.at'
1616
domainwrong = ' '
17+
domainwrongenum = 'domain.wrong.enum.at'
1718

1819
@staticmethod
1920
def getOrganization(orgname):
@@ -77,7 +78,7 @@ def test_create_wrong_domain(client):
7778
db.session.rollback()
7879
exception_occured = True
7980

80-
assert exception_occured or newdomain, 'wrong domain created'
81+
assert exception_occured, 'wrong domain created'
8182

8283
domain = Domain.query.filter_by(_domain_name=TDS.domainwrong).first()
8384
assert not domain, 'wrong domain created'
@@ -125,3 +126,31 @@ def test_delete_domain(client):
125126
domain = org.domains.first()
126127
assert not domain, 'domain deleted but found by organization.'
127128

129+
130+
def test_create_domain_wrong_enum(client):
131+
org = TDS.getOrganization(TDS.org1)
132+
assert org, 'test broken. organization not found'
133+
134+
exception_occured = False
135+
try:
136+
newdomain = Domain(domain_name=TDS.domainwrongenum, organization=org, delivery_protocol='xyz')
137+
db.session.add(newdomain)
138+
db.session.commit()
139+
except:
140+
db.session.rollback()
141+
exception_occured = True
142+
assert exception_occured, 'domain created with wrong enum.'
143+
144+
exception_occured = False
145+
try:
146+
newdomain = Domain(domain_name=TDS.domainwrongenum, organization=org, delivery_format='xyz')
147+
db.session.add(newdomain)
148+
db.session.commit()
149+
except:
150+
db.session.rollback()
151+
exception_occured = True
152+
assert exception_occured, 'domain created with wrong enum.'
153+
154+
domain = Domain.query.filter_by(_domain_name=TDS.domainwrongenum).first()
155+
assert not domain, 'domain created with wrong enum, found by domain_name.'
156+

‎frontend/app/views/domain-create.html

+27
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@ <h3 class="panel-title">"New Domain"</h3>
2525
ng-model="domain.domain_name">
2626
</div>
2727
</div>
28+
29+
<div class="row show-grid">
30+
<div class="col-xs-2">Protocol</div>
31+
<div class="col-xs-10">
32+
<select class="form-control input-sm" required ng-model="domain.delivery_protocol">
33+
<option ng-repeat="proto in ['Mail', 'REST API', 'AMQP']" ng-checked="proto === domain.delivery_protocol" value="{{proto}}">{{proto}}</option>
34+
</select>
35+
</div>
36+
</div>
37+
38+
<div class="row show-grid">
39+
<div class="col-xs-2">Format</div>
40+
<div class="col-xs-10">
41+
<select class="form-control input-sm" required ng-model="domain.delivery_format">
42+
<option ng-repeat="format in ['CSV', 'JSON']" ng-checked="format === domain.delivery_format" value="{{format}}">{{format}}</option>
43+
</select>
44+
</div>
45+
</div>
46+
47+
<div class="row show-grid">
48+
<div class="col-xs-2">Interval [s]</div>
49+
<div class="col-xs-10">
50+
<div class="col-xs-2">
51+
<input class="form-control input-sm" required ng-model="domain.notification_interval">
52+
</div>
53+
</div>
54+
</div>
2855
</div>
2956
</div>
3057

‎frontend/app/views/organization-edit.html

+20
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,34 @@ <h3 class="panel-title">Associated Domains</h3>
134134
<div class="panel-body">
135135
<div class="row show-grid">
136136
<div class="col-xs-2"><strong>Domain name</strong></div>
137+
<div class="col-xs-2"><strong>Protocol</strong></div>
138+
<div class="col-xs-2"><strong>Format</strong></div>
139+
<div class="col-xs-2"><strong>Interval [s]</strong></div>
137140
</div>
138141
<div ng-repeat="domain in domains">
139142
<div class="row show-grid">
140143
<div ng-if="!(edit && domain.dirty)">
141144
<div class="col-xs-2">{{domain.domain_name}}</div>
145+
<div class="col-xs-2">{{domain.delivery_protocol}}</div>
146+
<div class="col-xs-2">{{domain.delivery_format}}</div>
147+
<div class="col-xs-2">{{domain.notification_interval}}</div>
142148
</div>
143149
<div ng-if="edit && domain.dirty">
144150
<div class="col-xs-2"><input class="form-control input-sm" required ng-model="domain.domain_name"></div>
151+
<div class="col-xs-2">
152+
<select class="form-control input-sm" required ng-model="domain.delivery_protocol">
153+
<option ng-repeat="proto in ['Mail', 'REST API', 'AMQP']" ng-checked="proto === domain.delivery_protocol" value="{{proto}}">{{proto}}</option>
154+
</select>
155+
</div>
156+
<div class="col-xs-2">
157+
<select class="form-control input-sm" required ng-model="domain.delivery_format">
158+
<option ng-repeat="format in ['CSV', 'JSON']" ng-checked="format === domain.delivery_format" value="{{format}}">{{format}}</option>
159+
</select>
160+
</div>
161+
<div class="col-xs-2">
162+
<input class="form-control input-sm" required ng-model="domain.notification_interval">
163+
</div>
164+
145165
<div class="col-xs-2">
146166
<button class="btn btn-default btn-sm" ng-click="update_domain(domain)">
147167
<span class="glyphicon glyphicon-floppy-disk" aria-hidden="true"></span>

0 commit comments

Comments
 (0)
This repository has been archived.