예제 #1
0
    def find_or_create(cls, user_info):
        """
        This method populates db when user sign up or login through external auth system
        :param user_info: User data from external auth system
        :param oauth_source: From which oauth source the user coming from e.g. github
        :return: User data from Database
        """
        print(user_info)
        user = models.User.get_by_name(user_info['login'])
        if user:
            return user

        # convert github info to our local user info
        ourinfo = {
            'name': user_info['login'],
            'full_name': user_info.get('name'),
            'email': user_info.get('email')
        }
        user = models.User(**ourinfo)
        # create publisher for this user
        publisher = models.Publisher(name=user.name)
        association = models.PublisherUser(role=models.UserRoleEnum.owner, publisher=publisher, user=user)
        # user.publishers.append(association)
        db.session.add(user)
        db.session.commit()
        return user
예제 #2
0
def populate_db(email, user_name, full_name, secret):
    user = models.User.query.filter_by(name=user_name).first()

    publisher = models.Publisher.query.filter_by(name=user_name).first()
    if user is None:
        user = models.User()
        user.email, user.name, user.full_name, user.secret \
            = email, user_name, full_name, secret
        db.session.add(user)
        db.session.commit()

    if publisher is None:

        publisher = models.Publisher(name=user_name)

        association = models.PublisherUser(role=models.UserRoleEnum.owner)
        association.publisher = publisher
        user.publishers.append(association)

        db.session.add(user)
        db.session.commit()
예제 #3
0
    def setUp(self):
        self.publisher_name = 'demo'
        self.package_name = 'demo-package'
        self.app = create_app()
        self.app.app_context().push()
        with self.app.app_context():
            db.drop_all()
            db.create_all()
            self.user = models.User()
            self.user.email, self.user.name, self.user.secret = \
                '*****@*****.**', self.publisher_name, 'super_secret'
            self.publisher = models.Publisher(name=self.publisher_name)
            self.association = models.PublisherUser(
                role=models.UserRoleEnum.owner)
            self.metadata = models.Package(name=self.package_name)
            self.metadata.tags.append(models.PackageTag(descriptor={}))
            self.publisher.packages.append(self.metadata)
            self.association.publisher = self.publisher
            self.user.publishers.append(self.association)

            db.session.add(self.user)
            db.session.commit()
예제 #4
0
 def test_schema_for_publisher_with_pubic_contact(self):
     publisher = models.Publisher(name=self.publisher, contact_public=True)
     publisher_schema = logic.PublisherSchema()
     expected = {'country': None, 'email': None, 'phone': None}
     self.assertEqual(
         publisher_schema.dump(publisher).data['contact'], expected)