Skip to content

Commit

Permalink
Addressing PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
andrey-canon committed Dec 26, 2018
1 parent b90cb0f commit cb5ce65
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
12 changes: 7 additions & 5 deletions rocketc/rocketc.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ def api_teams(self):
try:
client_id = self.xblock_settings["client_id"]
client_secret = self.xblock_settings["client_secret"]
except KeyError:
except KeyError, xblock_settings_error:
LOG.error('Get rocketchat xblock settings error: %s', xblock_settings_error)
raise

server_url = settings.LMS_ROOT_URL
Expand Down Expand Up @@ -429,7 +430,7 @@ def _add_user_to_course_group(self, user_id):
"""
This method add the user to the default course channel
"""
group_name = "{}__{}".format(_("General"), self.course_id)
group_name = "{}__{}".format("General", self.course_id)
self._add_user_to_group(
user_id,
group_name,
Expand All @@ -438,8 +439,9 @@ def _add_user_to_course_group(self, user_id):
create=True
)

def _add_user_to_default_group(self, group_name, user_id):
def _add_user_to_specific_group(self, group_name, user_id):
"""
This method allows to add a user to a given group.
"""
group = "{}__{}".format(group_name, self.course_id)
result = self._add_user_to_group(user_id, group)
Expand Down Expand Up @@ -495,7 +497,7 @@ def _join_user_to_groups(self, user_id, user_data, auth_token):
if default_channel.startswith("(Team Group)"):
return self._join_user_to_specific_team_group(user_id, user_data, default_channel)

self.ui_is_block, default_channel = self._add_user_to_default_group(default_channel, user_id)
self.ui_is_block, default_channel = self._add_user_to_specific_group(default_channel, user_id)
return default_channel
else:
self.ui_is_block = False
Expand Down Expand Up @@ -686,7 +688,7 @@ def leave_group(self, data, suffix=""):
team = self._get_team(self.user_data["username"])
team_name, topic_id = generate_team_variables(team)

if group_name == team_name or group_name == _("General"):
if group_name == team_name or group_name == "General":
return {"success": False, "error": "You Can Not Leave a Main Group"}
group_name = "{}__{}__{}__{}".format(group_name, team_name, topic_id, self.course_id)

Expand Down
8 changes: 4 additions & 4 deletions rocketc/tests/test_rocketChat.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ def test_add_user_to_group(self):
self.assertTrue(result)

@patch('rocketc.rocketc.RocketChatXBlock._add_user_to_group')
def test_add_user_to_default_group(self, mock_add_to_group):
def test_add_user_to_specific_group(self, mock_add_to_group):
"""
Test the method add to default group
"""
group_name = "test_group_name"
user_id = "test_user_id"
mock_add_to_group.return_value = True

result, group = self.block._add_user_to_default_group(group_name, user_id)
result, group = self.block._add_user_to_specific_group(group_name, user_id)
self.assertTrue(result)
self.assertEquals(group, "{}__{}".format(group_name, self.block.course_id))
mock_add_to_group.assert_called_with(
Expand All @@ -106,7 +106,7 @@ def test_add_user_to_default_group(self, mock_add_to_group):
)

mock_add_to_group.return_value = False
result, group = self.block._add_user_to_default_group(group_name, user_id)
result, group = self.block._add_user_to_specific_group(group_name, user_id)
self.assertFalse(result)
self.assertEquals(group, "{}__{}".format(group_name, self.block.course_id))

Expand Down Expand Up @@ -301,7 +301,7 @@ def test_join_user_to_groups(self):

self.block.selected_view = "Specific Channel"

with patch('rocketc.rocketc.RocketChatXBlock._add_user_to_default_group', return_value=(True, "")):
with patch('rocketc.rocketc.RocketChatXBlock._add_user_to_specific_group', return_value=(True, "")):
self.block._join_user_to_groups(user_id, user_data, auth_token)
self.assertTrue(self.block.ui_is_block)

Expand Down

0 comments on commit cb5ce65

Please sign in to comment.