コード例 #1
0
 def test_organization_all(self):
     """
     Test for getting all organizations (takes buid or name optionally)
     """
     gryffindor = models.Organization(name='gryffindor',
                                      owner=self.fixtures.crusoe)
     ravenclaw = models.Organization(name='ravenclaw',
                                     owner=self.fixtures.crusoe)
     db.session.add(gryffindor)
     db.session.add(ravenclaw)
     db.session.commit()
     # scenario 1: when neither buids nor names are given
     self.assertEqual(models.Organization.all(), [])
     # scenario 2: when buids are passed
     orglist = [gryffindor, ravenclaw]
     orgids = [gryffindor.buid, ravenclaw.buid]
     all_by_buids = models.Organization.all(buids=orgids)
     self.assertIsInstance(all_by_buids, list)
     self.assertCountEqual(all_by_buids, orglist)
     # scenario 3: when org names are passed
     names = [gryffindor.name, ravenclaw.name]
     all_by_names = models.Organization.all(names=names)
     self.assertIsInstance(all_by_names, list)
     self.assertCountEqual(all_by_names, orglist)
     # scenario 4: when defercols is set to True for names
     all_by_names_with_defercols = models.Organization.all(names=names)
     self.assertIsInstance(all_by_names_with_defercols, list)
     self.assertCountEqual(all_by_names_with_defercols, orglist)
     # scenario 5: when defercols is set to True for buids
     all_by_buids_with_defercols = models.Organization.all(buids=orgids)
     self.assertIsInstance(all_by_buids_with_defercols, list)
     self.assertCountEqual(all_by_buids_with_defercols, orglist)
コード例 #2
0
 def test_organization_get(self):
     """
     Test for retrieving an organization
     """
     name = 'spew'
     title = 'S.P.E.W'
     spew = models.Organization(name=name,
                                title=title,
                                owner=self.fixtures.crusoe)
     db.session.add(spew)
     db.session.commit()
     # scenario 1: when neither name or buid are passed
     with self.assertRaises(TypeError):
         models.Organization.get()
     # scenario 2: when buid is passed
     buid = spew.buid
     get_by_buid = models.Organization.get(buid=buid)
     self.assertIsInstance(get_by_buid, models.Organization)
     assert title == get_by_buid.title
     # scenario 3: when username is passed
     get_by_name = models.Organization.get(name=name)
     self.assertIsInstance(get_by_name, models.Organization)
     assert title == get_by_name.title
     # scenario 4: when defercols is set to True
     get_by_name_with_defercols = models.Organization.get(name=name,
                                                          defercols=True)
     self.assertIsInstance(get_by_name_with_defercols, models.Organization)
     assert title == get_by_name_with_defercols.title
コード例 #3
0
 def test_organization_valid_name(self):
     """
     Test for checking if given is a valid organization name
     """
     hufflepuffs = models.Organization(name='hufflepuffs',
                                       title='Huffle Puffs',
                                       owner=self.fixtures.crusoe)
     self.assertFalse(hufflepuffs.is_valid_name('#$%#%___2836273untitled'))
     self.assertTrue(hufflepuffs.is_valid_name('hufflepuffs'))
コード例 #4
0
 def test_double_assigned_name(self):
     """
     Names cannot be assigned to both a user and an organization simultaneously
     """
     user = models.User(username="******", fullname="User")
     org = models.Organization(name="double-assigned",
                               title="Organization",
                               owner=self.fixtures.piglet)
     db.session.add_all([user, org])
     with self.assertRaises(IntegrityError):
         db.session.commit()
コード例 #5
0
    def test_organization_pickername(self):
        """
        Test for checking Organization's pickername
        """
        # scenario 1: when only title is given
        abnegation = models.Organization(title="Abnegation",
                                         owner=self.fixtures.crusoe)
        self.assertIsInstance(abnegation.pickername, str)
        self.assertEqual(abnegation.pickername, abnegation.title)

        # scenario 2: when both name and title are given
        name = 'cullens'
        title = 'The Cullens'
        olympic_coven = models.Organization(title=title,
                                            owner=self.fixtures.crusoe)
        olympic_coven.name = name
        db.session.add(olympic_coven)
        db.session.commit()
        self.assertIsInstance(olympic_coven.pickername, str)
        assert ('{title} (@{name})'.format(title=title, name=name)
                in olympic_coven.pickername)
コード例 #6
0
 def test_organization_init(self):
     """
     Test for initializing a Organization instance
     """
     name = 'dachshunited'
     title = 'Dachshunds United'
     dachsunited = models.Organization(name=name,
                                       title=title,
                                       owner=self.fixtures.crusoe)
     self.assertIsInstance(dachsunited, models.Organization)
     self.assertEqual(dachsunited.title, title)
     self.assertEqual(dachsunited.name, name)
コード例 #7
0
 def test_organization_name(self):
     """
     Test for retrieving Organization's name
     name is a setter method
     """
     insurgent = models.Organization(title='Insurgent',
                                     owner=self.fixtures.crusoe)
     with self.assertRaises(ValueError):
         insurgent.name = '35453496*%&^$%^'
     with self.assertRaises(ValueError):
         insurgent.name = '-Insurgent'
     insurgent.name = 'insurgent'
     self.assertEqual(insurgent.name, 'insurgent')
     insurgent.name = 'Insurgent'
     self.assertEqual(insurgent.name, 'Insurgent')
コード例 #8
0
def team_merge_data(test_client):
    db = models.db
    db.create_all()
    user1 = models.User(
        username='******',
        fullname="User 1",
        created_at=db.func.utcnow() - timedelta(days=1),
    )
    user2 = models.User(username='******', fullname="User 2")
    org = models.Organization(
        name='test-org-team-merge', title="Organization", owner=user1
    )
    team = models.Team(title="Team", organization=org)
    db.session.add_all([user1, user2, org, team])
    db.session.commit()

    yield SimpleNamespace(**locals())

    db.session.rollback()
    db.drop_all()
コード例 #9
0
    def test_authtoken_all(self):
        """
        Test for retreiving all AuthToken instances for given users
        """
        auth_client = self.fixtures.auth_client

        # scenario 1: When users passed are an instance of Query class
        hermione = models.User(username='******', fullname='Hermione Granger')
        herminone_token = models.AuthToken(
            auth_client=auth_client, user=hermione, scope=['id']
        )
        myrtle = models.User(username='******', fullname='Moaning Myrtle')
        myrtle_token = models.AuthToken(
            auth_client=auth_client, user=myrtle, scope=['id']
        )
        alastor = models.User(username='******', fullname='Alastor Moody')
        alastor_token = models.AuthToken(
            auth_client=auth_client, user=alastor, scope=['id']
        )
        greyback = models.User(username='******', fullname='Fenrir Greyback')
        greyback_token = models.AuthToken(
            auth_client=auth_client, user=greyback, scope=['id']
        )
        pottermania = models.Organization(
            name='pottermania', title='Pottermania', owner=hermione
        )
        db.session.add_all(
            [
                myrtle,
                myrtle_token,
                hermione,
                herminone_token,
                alastor,
                alastor_token,
                greyback,
                greyback_token,
                pottermania,
            ]
        )
        db.session.commit()

        # scenario 1
        result1 = models.AuthToken.all(pottermania.owner_users)
        self.assertIsInstance(result1, list)
        self.assertIsInstance(result1[0], models.AuthToken)
        self.assertCountEqual(result1, [herminone_token])

        # Scenario 2: When users passed are not an instance of Query class
        lily = models.User(username='******', fullname='Lily Evans Potter')
        cho = models.User(username='******', fullname='Cho Chang')
        lily_token = models.AuthToken(
            auth_client=auth_client, user=lily, scope=['memories']
        )
        cho_token = models.AuthToken(
            auth_client=auth_client, user=cho, scope=['charms']
        )
        db.session.add_all([lily, lily_token, cho, cho_token])
        db.session.commit()

        # scenario 2 and count == 1
        result3 = models.AuthToken.all([lily])
        self.assertIsInstance(result3, list)
        self.assertIsInstance(result3[0], models.AuthToken)
        self.assertCountEqual(result3, [lily_token])

        # scenario 2 and count > 1
        result4 = models.AuthToken.all([lily, cho])
        self.assertIsInstance(result4, list)
        for each in result4:
            self.assertIsInstance(each, models.AuthToken)
        self.assertCountEqual(result4, [lily_token, cho_token])

        # scenario 5: When user instances passed don't have any AuthToken against them
        oakley = self.fixtures.oakley
        piglet = self.fixtures.piglet
        users = [piglet, oakley]
        result5 = models.AuthToken.all(users)
        self.assertListEqual(result5, [])