Skip to content

Commit

Permalink
Update models & some cleanup. (#554)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsangmeister committed Mar 18, 2021
1 parent 096ddcd commit 00635ed
Show file tree
Hide file tree
Showing 23 changed files with 381 additions and 409 deletions.
11 changes: 6 additions & 5 deletions openslides_backend/models/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from openslides_backend.models.base import Model
from openslides_backend.shared.patterns import Collection

MODELS_YML_CHECKSUM = "a193a614fa0f1498fa9e6c9d001e56a6"
MODELS_YML_CHECKSUM = "c2930fed7fb920b6d56898763b15cfff"


class Organisation(Model):
Expand Down Expand Up @@ -46,7 +46,7 @@ class User(Model):
email = fields.CharField()
default_number = fields.CharField()
default_structure_level = fields.CharField()
default_vote_weight = fields.DecimalField(default="1")
default_vote_weight = fields.DecimalField(default="1.000000")
last_email_send = fields.TimestampField()
is_demo_user = fields.BooleanField(read_only=True)
organisation_management_level = fields.CharField(
Expand Down Expand Up @@ -1108,6 +1108,7 @@ class MotionState(Model):
name = fields.CharField(required=True)
recommendation_label = fields.CharField()
css_class = fields.CharField(
required=True,
default="lightblue",
constraints={"enum": ["grey", "red", "green", "lightblue", "yellow"]},
)
Expand Down Expand Up @@ -1228,9 +1229,9 @@ class Poll(Model):
)
min_votes_amount = fields.IntegerField(default=1)
max_votes_amount = fields.IntegerField(default=1)
global_yes = fields.BooleanField(default=True)
global_no = fields.BooleanField(default=True)
global_abstain = fields.BooleanField(default=True)
global_yes = fields.BooleanField(default=False)
global_no = fields.BooleanField(default=False)
global_abstain = fields.BooleanField(default=False)
onehundred_percent_base = fields.CharField(
required=True,
constraints={"enum": ["Y", "YN", "YNA", "N", "valid", "cast", "disabled"]},
Expand Down
11 changes: 3 additions & 8 deletions tests/system/action/motion_workflow/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ def test_create_wrong_field(self) -> None:

def test_create_simple_workflow(self) -> None:
self.create_model("meeting/42", {"name": "test_meeting1"})
response = self.client.post(
"/",
json=[
{
"action": "motion_workflow.create_simple_workflow",
"data": [{"name": "test_Xcdfgee", "meeting_id": 42}],
}
],
response = self.request(
"motion_workflow.create_simple_workflow",
{"name": "test_Xcdfgee", "meeting_id": 42},
)
self.assert_status_code(response, 200)
self.assert_model_exists(
Expand Down
3 changes: 2 additions & 1 deletion tests/system/action/organisation/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def test_update_wrong_field(self) -> None:
)
self.assert_status_code(response, 400)
assert (
"data must not contain {'wrong_name'} properties" in response.data.decode()
"data must not contain {'wrong_name'} properties"
in response.json["message"]
)
model = self.get_model("organisation/3")
assert model.get("name") == "aBuwxoYU"
Expand Down
48 changes: 21 additions & 27 deletions tests/system/action/poll/test_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,28 +57,21 @@ def test_create_correct(self) -> None:
assert global_option.get("meeting_id") == 113

def test_create_three_options(self) -> None:
response = self.client.post(
"/",
json=[
{
"action": "poll.create",
"data": [
{
"title": "test",
"type": "analog",
"pollmethod": "YNA",
"options": [
{"text": "test2", "Y": "10.000000"},
{"text": "test3", "N": "0.999900"},
{"text": "test4", "N": "11.000000"},
],
"meeting_id": 113,
"onehundred_percent_base": "YNA",
"majority_method": "simple",
}
],
}
],
response = self.request(
"poll.create",
{
"title": "test",
"type": "analog",
"pollmethod": "YNA",
"options": [
{"text": "test2", "Y": "10.000000"},
{"text": "test3", "N": "0.999900"},
{"text": "test4", "N": "11.000000"},
],
"meeting_id": 113,
"onehundred_percent_base": "YNA",
"majority_method": "simple",
},
)
self.assert_status_code(response, 200)
poll = self.get_model("poll/1")
Expand Down Expand Up @@ -203,8 +196,9 @@ def test_missing_keys(self) -> None:
self.assert_model_not_exists("poll/1")

def test_with_groups(self) -> None:
self.create_model("group/1", {"meeting_id": 113})
self.create_model("group/2", {"meeting_id": 113})
self.set_models(
{"group/1": {"meeting_id": 113}, "group/2": {"meeting_id": 113}}
)
response = self.request(
"poll.create",
{
Expand Down Expand Up @@ -353,7 +347,7 @@ def test_wrong_pollmethod_onehundred_percent_base_combination_1(self) -> None:
self.assert_status_code(response, 400)
assert (
"This onehundred_percent_base not allowed in this pollmethod"
in response.data.decode()
in response.json["message"]
)
self.assert_model_not_exists("poll/1")

Expand All @@ -374,7 +368,7 @@ def test_wrong_pollmethod_onehundred_percent_base_combination_2(self) -> None:
self.assert_status_code(response, 400)
assert (
"This onehundred_percent_base not allowed in this pollmethod"
in response.data.decode()
in response.json["message"]
)
self.assert_model_not_exists("poll/1")

Expand All @@ -395,7 +389,7 @@ def test_wrong_pollmethod_onehundred_percent_base_combination_3(self) -> None:
self.assert_status_code(response, 400)
assert (
"This onehundred_percent_base not allowed in this pollmethod"
in response.data.decode()
in response.json["message"]
)
self.assert_model_not_exists("poll/1")

Expand Down
2 changes: 1 addition & 1 deletion tests/system/action/poll/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def test_publish_wrong_state(self) -> None:
assert poll.get("state") == "created"
assert (
"Cannot publish poll 1, because it is not in state finished."
in response.data.decode()
in response.json["message"]
)
23 changes: 12 additions & 11 deletions tests/system/action/poll/test_start.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ def setUp(self) -> None:
},
)
self.create_poll()
self.create_model("meeting/113", {"name": "my meeting"})
self.create_model("group/1", {"user_ids": [1]})
self.create_model("option/1", {"meeting_id": 113, "poll_id": 1})
self.create_model("option/2", {"meeting_id": 113, "poll_id": 1})
self.update_model(
"user/1",
self.set_models(
{
"is_present_in_meeting_ids": [113],
"group_$113_ids": [1],
"group_$_ids": ["113"],
},
"meeting/113": {"name": "my meeting"},
"group/1": {"user_ids": [1]},
"option/1": {"meeting_id": 113, "poll_id": 1},
"option/2": {"meeting_id": 113, "poll_id": 1},
"user/1": {
"is_present_in_meeting_ids": [113],
"group_$113_ids": [1],
"group_$_ids": ["113"],
},
}
)

def create_poll(self) -> None:
Expand Down Expand Up @@ -68,7 +69,7 @@ def test_start_wrong_state(self) -> None:
assert poll.get("state") == "published"
assert (
"Cannot start poll 1, because it is not in state created."
in response.data.decode()
in response.json["message"]
)


Expand Down
2 changes: 1 addition & 1 deletion tests/system/action/poll/test_stop.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ def test_stop_wrong_state(self) -> None:
assert poll.get("state") == "published"
assert (
"Cannot stop poll 1, because it is not in state started."
in response.data.decode()
in response.json["message"]
)
69 changes: 32 additions & 37 deletions tests/system/action/poll/test_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,35 @@
class UpdatePollTestCase(BaseActionTestCase):
def setUp(self) -> None:
super().setUp()
self.create_model(
"assignment/1",
{
"title": "test_assignment_ohneivoh9caiB8Yiungo",
"open_posts": 1,
},
)
self.create_model("meeting/113", {"name": "my meeting"})
self.create_model("organisation/1", {"enable_electronic_voting": True})
self.create_model("group/1", {"user_ids": [1], "poll_ids": [1]})
self.create_model(
"poll/1",
self.set_models(
{
"content_object_id": "assignment/1",
"title": "test_title_beeFaihuNae1vej2ai8m",
"pollmethod": "Y",
"type": Poll.TYPE_NAMED,
"onehundred_percent_base": "Y",
"majority_method": "simple",
"state": Poll.STATE_CREATED,
"meeting_id": 113,
"option_ids": [1, 2],
"entitled_group_ids": [1],
},
)
self.create_model("option/1", {"meeting_id": 113, "poll_id": 1})
self.create_model("option/2", {"meeting_id": 113, "poll_id": 1})
self.update_model(
"user/1",
{
"is_present_in_meeting_ids": [113],
"group_$113_ids": [1],
"group_$_ids": ["113"],
},
"assignment/1": {
"title": "test_assignment_ohneivoh9caiB8Yiungo",
"open_posts": 1,
},
"meeting/113": {"name": "my meeting"},
"organisation/1": {"enable_electronic_voting": True},
"group/1": {"user_ids": [1], "poll_ids": [1]},
"poll/1": {
"content_object_id": "assignment/1",
"title": "test_title_beeFaihuNae1vej2ai8m",
"pollmethod": "Y",
"type": Poll.TYPE_NAMED,
"onehundred_percent_base": "Y",
"majority_method": "simple",
"state": Poll.STATE_CREATED,
"meeting_id": 113,
"option_ids": [1, 2],
"entitled_group_ids": [1],
},
"option/1": {"meeting_id": 113, "poll_id": 1},
"option/2": {"meeting_id": 113, "poll_id": 1},
"user/1": {
"is_present_in_meeting_ids": [113],
"group_$113_ids": [1],
"group_$_ids": ["113"],
},
}
)

def test_catch_not_allowed(self) -> None:
Expand All @@ -58,7 +53,7 @@ def test_catch_not_allowed(self) -> None:
},
)
self.assert_status_code(response, 400)
assert ("data must not contain {'type'} properties") in response.data.decode()
assert ("data must not contain {'type'} properties") in response.json["message"]

def test_optional_state_created(self) -> None:
response = self.request(
Expand Down Expand Up @@ -89,7 +84,7 @@ def test_not_allowed_for_analog(self) -> None:
assert (
"Following options are not allowed in this state and type: "
"entitled_group_ids"
) in response.data.decode()
) in response.json["message"]

def test_not_allowed_for_non_analog(self) -> None:
response = self.request(
Expand All @@ -105,7 +100,7 @@ def test_not_allowed_for_non_analog(self) -> None:
assert (
"Following options are not allowed in this state and type: "
"votesvalid, votesinvalid, votescast"
) in response.data.decode()
) in response.json["message"]

def test_update_title(self) -> None:
response = self.request(
Expand Down Expand Up @@ -269,7 +264,7 @@ def test_update_wrong_100_percent_base_state_not_created(self) -> None:
self.assert_status_code(response, 400)
assert (
"This onehundred_percent_base not allowed in this pollmethod"
in response.data.decode()
in response.json["message"]
)
poll = self.get_model("poll/1")
self.assertEqual(poll.get("onehundred_percent_base"), "Y")
Expand Down
Loading

0 comments on commit 00635ed

Please sign in to comment.