Ejemplo n.º 1
0
    def test_get_ident_by_id_with_user_backend(self):
        contributors.user_endpoint_active = True
        with patch.object(index.YAMLBackend, 'load_db'):
            with patch.object(contributors.Contributors, '_get_idents'):
                with patch.object(users.Users, 'get_ident_by_id') as egi:
                    egi.return_value = {
                        'name':
                        'John Doe',
                        'default-email':
                        '*****@*****.**',
                        'emails': [{
                            'email': '*****@*****.**'
                        }, {
                            'email': '*****@*****.**',
                            'groups': [{
                                'group': 'barbican-ptl'
                            }]
                        }],
                        'uid':
                        'johndoe123'
                    }

                    c = contributors.Contributors(db_path="db_path")

                    id, ident = c.get_ident_by_id('johndoe123')
                    self.assertEqual(ident['name'], 'John Doe')
                    self.assertEqual(id, 'johndoe123')
Ejemplo n.º 2
0
    def test_groups_get(self):
        contributors.user_endpoint_active = False
        f1 = """
---
groups:
  acme-10:
    description: The group 10 of acme
    emails:
      [email protected]:
        begin-date: 2016-01-01
        end-date: 2016-01-09
      [email protected]:
"""
        default = """
---
groups:
  acme-10:
    description: The group 10 of acme
    emails:
      [email protected]:
      [email protected]:
  acme-11:
    description: The group 11 of acme
    emails:
      [email protected]:
      [email protected]:
      [email protected]:
    domains:
      - dom1.org
"""
        files = {'f1.yaml': f1, 'default.yaml': default}
        db = self.create_db(files)
        index.conf['db_default_file'] = os.path.join(db, 'default.yaml')
        p = contributors.Contributors(db_path=db)
        ret = p.get_groups()
        self.assertDictEqual(
            ret, {
                'acme-10': {
                    'emails': {
                        '*****@*****.**': {
                            'begin-date': 1451606400.0,
                            'end-date': 1452297600.0
                        },
                        '*****@*****.**': None
                    },
                    'description': 'The group 10 of acme'
                },
                'acme-11': {
                    'emails': {
                        '*****@*****.**': None,
                        '*****@*****.**': None,
                        '*****@*****.**': None
                    },
                    'domains': ['dom1.org'],
                    'description': 'The group 11 of acme'
                }
            })
Ejemplo n.º 3
0
    def test_get_group_by_id_with_users_backend(self):
        contributors.user_endpoint_active = True
        with patch.object(index.YAMLBackend, 'load_db'):
            with patch.object(users.Users, 'get_idents_in_group') as egi:
                egi.return_value = [
                    {
                        'name':
                        'John Doe',
                        'default-email':
                        '*****@*****.**',
                        'emails': [{
                            'email': '*****@*****.**'
                        }, {
                            'email': '*****@*****.**',
                            'groups': [{
                                'group': 'barbican-ptl'
                            }]
                        }],
                        'uid':
                        'johndoe123'
                    },
                ]

                c = contributors.Contributors(db_path="db_path")
                c.groups = {
                    'barbican-ptl': {
                        'description': 'The barbican-ptl group',
                        'emails': {}
                    },
                    'barbican-core': {
                        'description': 'The barbican-core group',
                        'emails': {}
                    }
                }

                gid, gdata = c.get_group_by_id('barbican-ptl')
                self.assertDictEqual(
                    gdata, {
                        'description': 'The barbican-ptl group',
                        'emails': {
                            '*****@*****.**': {}
                        }
                    })
                self.assertEqual(gid, 'barbican-ptl')

                gid, gdata = c.get_group_by_id('barbican-core')
                self.assertDictEqual(gdata, {
                    'description': 'The barbican-core group',
                    'emails': {}
                })
                self.assertEqual(gid, 'barbican-core')
Ejemplo n.º 4
0
    def test_get_idents_by_emails_with_user_backend(self):
        contributors.user_endpoint_active = True
        with patch.object(index.YAMLBackend, 'load_db'):
            with patch.object(contributors.Contributors, '_get_idents'):
                with patch.object(users.Users, 'get_idents_by_emails') as egi:
                    egi.return_value = [
                        {
                            u'name':
                            u'John Doe',
                            u'default-email':
                            u'*****@*****.**',
                            u'emails': [{
                                u'email': u'*****@*****.**'
                            }, {
                                u'email':
                                u'*****@*****.**',
                                u'groups': [{
                                    u'group': u'barbican-ptl'
                                }]
                            }],
                            u'uid':
                            u'johndoe123'
                        },
                    ]

                    c = contributors.Contributors(db_path="db_path")

                    ret = c.get_idents_by_emails('*****@*****.**')
                    self.assertDictEqual(
                        ret['johndoe123'], {
                            'name': 'John Doe',
                            'default-email': '*****@*****.**',
                            'emails': {
                                '*****@*****.**': {
                                    'groups': {}
                                },
                                '*****@*****.**': {
                                    'groups': {
                                        'barbican-ptl': {}
                                    }
                                }
                            }
                        })
Ejemplo n.º 5
0
    def test_get_group_by_id(self):
        contributors.user_endpoint_active = False
        with patch.object(index.YAMLBackend, 'load_db'):
            with patch.object(contributors.Contributors, 'get_groups') as gg:
                gg.return_value = {
                    'acme-11': {
                        'description': 'The group 11 of acme',
                        'emails': {
                            '*****@*****.**': None,
                            '*****@*****.**': None
                        }
                    }
                }
                c = contributors.Contributors(db_path="db_path")

                gid, gdata = c.get_group_by_id('zzz')
                self.assertEqual(gid, 'zzz')
                self.assertEqual(gdata, None)

                gid, gdata = c.get_group_by_id('acme-11')
                self.assertEqual(gid, 'acme-11')
                self.assertEqual(gdata['description'], 'The group 11 of acme')
Ejemplo n.º 6
0
    def test_get_ident_by_id(self):
        contributors.user_endpoint_active = False
        with patch.object(index.YAMLBackend, 'load_db'):
            with patch.object(contributors.Contributors, '_get_idents') as gi:
                gi.return_value = {
                    '1234-1235': {
                        'name': 'Jane Doe',
                        'emails': {
                            '*****@*****.**': {},
                            '*****@*****.**': {}
                        }
                    }
                }
                c = contributors.Contributors(db_path="db_path")

                cid, cdata = c.get_ident_by_id('8888-8888')
                self.assertEqual(cid, '8888-8888')
                self.assertEqual(cdata, None)

                cid, cdata = c.get_ident_by_id('1234-1235')
                self.assertEqual(cid, '1234-1235')
                self.assertEqual(cdata['name'], 'Jane Doe')
Ejemplo n.º 7
0
    def test_contributors_get(self):
        f1 = """
---
identities:
  1234-1233:
    name: Amperman
    default-email: [email protected]
    emails:
      [email protected]:
        groups:
          amp:
            begin-date: 2010-01-01
            end-date: 2020-01-09
"""
        f2 = """
---
identities:
  1234-1236:
    name: Bill Doe
    default-email: [email protected]
    emails:
      [email protected]:
        groups:
          acme-12:
            begin-date: 2016-01-01
            end-date: 2016-01-09
"""

        default = """
---
identities:
  1234-1234:
    name: John Doe
    default-email: [email protected]
    emails:
      [email protected]:
        groups:
          acme-10:
            begin-date: 2016-01-01
          acme-11:
          acme-12:
      [email protected]:
        groups: {}
  1234-1235:
    name: Jane Doe
    default-email: [email protected]
    emails:
      [email protected]: {}
      [email protected]: {}
  1234-1236:
    name: Bill Doe
    default-email: [email protected]
    emails:
      [email protected]: {}
      [email protected]: {}
"""
        files = {'f1.yaml': f1, 'f2.yaml': f2, 'default.yaml': default}
        db = self.create_db(files)
        index.conf['db_default_file'] = os.path.join(db, 'default.yaml')
        p = contributors.Contributors(db_path=db)
        ret = p._get_idents()
        self.assertDictEqual(
            ret, {
                '1234-1235': {
                    'name': 'Jane Doe',
                    'default-email': '*****@*****.**',
                    'emails': {
                        '*****@*****.**': {},
                        '*****@*****.**': {}
                    }
                },
                '1234-1234': {
                    'name': 'John Doe',
                    'default-email': '*****@*****.**',
                    'emails': {
                        '*****@*****.**': {
                            'groups': {
                                'acme-12': None,
                                'acme-10': {
                                    'end-date': None,
                                    'begin-date': 1451606400.0
                                },
                                'acme-11': None
                            }
                        },
                        '*****@*****.**': {
                            'groups': {}
                        }
                    }
                },
                '1234-1236': {
                    'name': 'Bill Doe',
                    'default-email': '*****@*****.**',
                    'emails': {
                        '*****@*****.**': {
                            'groups': {
                                'acme-12': {
                                    'end-date': 1452297600.0,
                                    'begin-date': 1451606400.0
                                }
                            }
                        }
                    }
                },
                '1234-1233': {
                    'name': 'Amperman',
                    'default-email': '*****@*****.**',
                    'emails': {
                        '*****@*****.**': {
                            'groups': {
                                'amp': {
                                    'end-date': 1578528000.0,
                                    'begin-date': 1262304000.0
                                }
                            }
                        }
                    }
                }
            })
Ejemplo n.º 8
0
 def test_get_idents_by_emails(self):
     contributors.user_endpoint_active = False
     with patch.object(index.YAMLBackend, 'load_db'):
         with patch.object(contributors.Contributors, '_get_idents') as gi:
             gi.return_value = {
                 '1234-1235': {
                     'name': 'Jane Doe',
                     'emails': {
                         '*****@*****.**': {},
                         '*****@*****.**': {}
                     }
                 }
             }
             c = contributors.Contributors(db_path="db_path")
             ret = c.get_idents_by_emails('*****@*****.**')
             self.assertTrue(len(ret), 1)
             self.assertDictEqual(
                 ret['1234-1235'], {
                     'name': 'Jane Doe',
                     'emails': {
                         '*****@*****.**': {},
                         '*****@*****.**': {}
                     }
                 })
             ret = c.get_idents_by_emails('*****@*****.**')
             self.assertDictEqual(
                 ret['*****@*****.**'], {
                     'name': None,
                     'default-email': '*****@*****.**',
                     'emails': {
                         '*****@*****.**': {}
                     }
                 })
             gi.return_value = {
                 '1234-1235': {
                     'name': 'Jane Doe',
                     'emails': {
                         '*****@*****.**': {},
                         '*****@*****.**': {}
                     }
                 },
                 '1234-1236': {
                     'name': 'John Doe',
                     'emails': {
                         '*****@*****.**': {}
                     }
                 },
                 '1234-1237': {
                     'name': 'Ampanman',
                     'emails': {
                         '*****@*****.**': {}
                     }
                 },
             }
             ret = c.get_idents_by_emails(
                 ['*****@*****.**', '*****@*****.**'])
             self.assertDictEqual(ret['1234-1237'], {
                 'name': 'Ampanman',
                 'emails': {
                     '*****@*****.**': {}
                 }
             })
             self.assertDictEqual(ret['1234-1236'], {
                 'name': 'John Doe',
                 'emails': {
                     '*****@*****.**': {}
                 }
             })
             self.assertEqual(len(ret), 2)
Ejemplo n.º 9
0
    def test_groups_get_enriched(self):
        contributors.user_endpoint_active = False
        f1 = """
---
identities:
  1234-1234:
    name: John Doe
    default-email: [email protected]
    emails:
      [email protected]:
        groups:
          acme-10:
            begin-date: 2016-01-01
            end-date: 2016-01-09
          acme-11:
          acme-12:
      [email protected]:
        groups: {}
  1234-1235:
    name: Jane Doe
    default-email: [email protected]
    emails:
      [email protected]:
        groups:
          acme-10:
            begin-date: 2015-01-01
            end-date: 2015-01-09
      [email protected]:
        groups:
          acme-12:
            begin-date: 2015-01-01
            end-date: 2015-01-05

groups:
  acme-10:
    description: The group 10 of acme
    emails: {}
  acme-11:
    description: The group 11 of acme
    emails:
      [email protected]:
  acme-12:
    description: The group 12 of acme
    emails:
      [email protected]:
    domains:
      - acme12.org
"""
        files = {'f1.yaml': f1}
        db = self.create_db(files)
        index.conf['db_default_file'] = None
        p = contributors.Contributors(db_path=db)
        ret = p.get_groups()
        expected_ret = {
            'acme-12': {
                'description': 'The group 12 of acme',
                'domains': ['acme12.org'],
                'emails': {
                    '*****@*****.**': None,
                    '*****@*****.**': {
                        'end-date': 1420416000.0,
                        'begin-date': 1420070400.0
                    },
                    '*****@*****.**': None
                }
            },
            'acme-11': {
                'description': 'The group 11 of acme',
                'emails': {
                    '*****@*****.**': None,
                    '*****@*****.**': None
                }
            },
            'acme-10': {
                'description': 'The group 10 of acme',
                'emails': {
                    '*****@*****.**': {
                        'end-date': 1452297600.0,
                        'begin-date': 1451606400.0
                    },
                    '*****@*****.**': {
                        'end-date': 1420761600.0,
                        'begin-date': 1420070400.0
                    }
                }
            }
        }
        self.assertDictEqual(ret, expected_ret)
Ejemplo n.º 10
0
    def test_groups_validate(self):
        f1 = """
---
groups:
  acme-10:
    description: The group 10 of acme
    domains:
      - dom1.org
      - dom2.org
    emails:
      [email protected]:
        begin-date: 2016-01-01
        end-date: 2016-01-09
      [email protected]:
"""
        f2 = """
---
groups:
  acme-11:
    description: The group 11 of acme
    emails:
      [email protected]:
      [email protected]:
      [email protected]:
"""

        files = {'f1.yaml': f1, 'f2.yaml': f2}
        db = self.create_db(files)
        index.conf['db_default_file'] = None
        p = contributors.Contributors(db_path=db)
        validation_logs = p._validate_groups()
        self.assertEqual(len(validation_logs), 0)

        f3 = """
---
groups:
  acme-12:
    description: The group 12 of acme
    emails: wrong format
"""
        files = {'f1.yaml': f1, 'f2.yaml': f2, 'f3.yaml': f3}
        db = self.create_db(files)
        index.conf['db_default_file'] = None
        p = contributors.Contributors(db_path=db)
        validation_logs = p._validate_groups()
        self.assertEqual(validation_logs[0],
                         "'wrong format' is not of type 'object'")
        self.assertEqual(len(validation_logs), 1)

        f3 = """
---
groups:
  acme-11:
    description: The group 11 of acme
    emails:
      [email protected]:
      [email protected]:
      [email protected]:
"""
        files = {'f1.yaml': f1, 'f2.yaml': f2, 'f3.yaml': f3}
        db = self.create_db(files)
        index.conf['db_default_file'] = None
        p = contributors.Contributors(db_path=db)
        validation_logs = p._validate_groups()
        self.assertEqual(validation_logs[0],
                         "Group IDs [acme-11,] are duplicated")
        self.assertEqual(len(validation_logs), 1)
Ejemplo n.º 11
0
    def test_contributors_validate(self):
        f1 = """
---
identities:
  1234-1234:
    name: John Doe
    default-email: [email protected]
    emails:
      [email protected]:
        groups:
          acme-10:
            begin-date: 2016-01-01
            end-date: 2016-01-09
          acme-11:
          acme-12:
      [email protected]:
        groups: {}
  1234-1235:
    name: Jane Doe
    default-email: [email protected]
    emails:
      [email protected]: {}
      [email protected]: {}

groups:
  acme-10:
    description: The group 10 of acme
    emails: {}
  acme-11:
    description: The group 11 of acme
    emails: {}
  acme-12:
    description: The group 12 of acme
    emails: {}
"""
        f2 = """
---
identities:
  1234-1236:
    name: John Doe
    default-email: [email protected]
    emails:
      [email protected]:
        groups:
          acme-10:
            begin-date: 2016-01-01
            end-date: 2016-01-09
          acme-11:
          acme-12:
      [email protected]:
        groups: {}
  1234-1237:
    name: Jane Doe
    default-email: [email protected]
    emails:
      [email protected]: {}
      [email protected]: {}
"""

        files = {'f1.yaml': f1, 'f2.yaml': f2}
        db = self.create_db(files)
        index.conf['db_default_file'] = None
        p = contributors.Contributors(db_path=db)
        validation_logs = p._validate_idents()
        self.assertEqual(len(validation_logs), 0)

        f3 = """
---
identities:
  1234-1238:
    name: John Doe
    default-email: [email protected]
    emails:
      isthisanemail?
"""

        files = {'f1.yaml': f1, 'f2.yaml': f2, 'f3.yaml': f3}
        db = self.create_db(files)
        index.conf['db_default_file'] = None
        p = contributors.Contributors(db_path=db)
        validation_logs = p._validate_idents()
        self.assertEqual(validation_logs[0],
                         "'isthisanemail?' is not of type 'object'")
        self.assertEqual(len(validation_logs), 1)

        f3 = """
---
identities:
  1234-1237:
    name: John Doe
    default-email: [email protected]
    emails:
      [email protected]:
        groups: {}
"""

        files = {'f1.yaml': f1, 'f2.yaml': f2, 'f3.yaml': f3}
        db = self.create_db(files)
        index.conf['db_default_file'] = None
        p = contributors.Contributors(db_path=db)
        validation_logs = p._validate_idents()
        self.assertEqual(validation_logs[0],
                         "Identity IDs [1234-1237,] are duplicated")
        self.assertEqual(len(validation_logs), 1)

        f3 = """
---
identities:
  1234-1238:
    name: John Doe
    default-email: [email protected]
    emails:
      [email protected]:
        groups: {}
"""

        files = {'f1.yaml': f1, 'f2.yaml': f2, 'f3.yaml': f3}
        db = self.create_db(files)
        index.conf['db_default_file'] = None
        p = contributors.Contributors(db_path=db)
        validation_logs = p._validate_idents()
        self.assertEqual(
            validation_logs[0],
            "Identity 1234-1238 default an unknown default-email")
        self.assertEqual(len(validation_logs), 1)