#423 Fix hub members edition
Merged 6 years ago by abompard. Opened 6 years ago by abompard.
abompard/fedora-hubs fix/hub-members  into  develop

@@ -5,7 +5,7 @@ 

  from flask import json

  

  from hubs.app import app

- from hubs.models import Hub, User

+ from hubs.models import Hub, User, Association

  from hubs.tests import APPTest, FakeAuthorization, auth_set

  

  
@@ -131,6 +131,43 @@ 

          hub_config = Hub.query.get("decause").config

          self.assertEqual(hub_config.summary, "Decause")

  

+     def test_put_users(self):

+         hub = Hub.by_name('ralph')

+         for username in ["devyani7", "dhrish"]:

+             hub.associations.append(

+                 Association(user=User.query.get(username), role="member")

+             )

+         hub.associations.append(

+             Association(user=User.query.get("shalini"), role="subscriber")

+         )

+         user = FakeAuthorization('ralph')

+         with auth_set(app, user):

+             result = self.app.put(

+                 '/api/hubs/ralph/config',

+                 content_type="application/json",

+                 data=json.dumps({

+                     "users": {

+                         "owner": [{"username": "ralph"}],

+                         "member": [

+                             {"username": "decause"},

+                             {"username": "dhrish"},

+                         ],

+                     }

+                 })

+             )

+         self.assertEqual(result.status_code, 200)

+         result_data = json.loads(result.get_data(as_text=True))

+         self.assertEqual(result_data["status"], "OK")

+         self.assertListEqual(

+             [(a.user_id, a.role) for a in hub.associations],

+             [

+                 ('decause', 'member'),

+                 ('dhrish', u'member'),

+                 ('ralph', u'owner'),

+                 ('shalini', 'subscriber'),

+             ]

+         )

+ 

      def test_suggest_users_no_filter(self):

          user = FakeAuthorization('ralph')

          expected = [

file modified
+5 -2
@@ -82,8 +82,11 @@ 

          for u in user_roles[role]:

              new_associations.append((u["username"], role))

      # Remove old associations

-     for assoc in hub.associations:

-         if assoc.hub != hub:

+     # Note: don't iter and edit hubs.associations in the same loop, it's an

+     # instrumented list by SQLAlchemy.

+     for assoc in list(hub.associations):

+         if assoc.role not in ("owner", "member"):

+             # Leave alone the subscribers and stargazers.

              continue

          try:

              new_associations.remove(

Fix the PUT method for setting hub members and owners.

rebased onto cbc8b5f

6 years ago

Pull-Request has been merged by abompard

6 years ago