# Path: extrapypi/models/user.py
# class User(db.Model):
#     ROLES = [
#         'admin',
#         'developer',
#         'installer',
#         'maintainer'
#     ]
# 
#     id = db.Column(db.Integer, primary_key=True)
#     username = db.Column(db.String(255), nullable=False, unique=True)
#     email = db.Column(db.String(255), nullable=False, unique=True)
#     password_hash = db.Column(db.String(255), nullable=False)
#     is_active = db.Column(db.Boolean, default=True)
#     role = db.Column(db.String(80), nullable=True)
# 
#     @validates('role')
#     def validate_role(self, key, role):
#         assert role in self.ROLES or role is None
#         return role
# 
#     @property
#     def is_authenticated(self):
#         return True
# 
#     @property
#     def is_anonymous(self):
#         return False
# 
#     @property
#     def is_admin(self):
#         return self.role == 'admin'
# 
#     def get_id(self):
#         try:
#             return unicode(self.id)
#         except NameError:
#             return str(self.id)
# 
#     def __repr__(self):
#         return "<User {0.username}>".format(self)
# 
# Path: extrapypi/extensions.py



from extrapypi.models import User
from extrapypi.extensions import db
    f.write("a simple test")
    valid_data = {
        ':action': 'file_upload',
        'name': 'uploaded',
        'summary': 'from unittests',
        'description': 'simple upload test',
        'download_url': '',
        'home_page': '',
        'version': '0.1',
        'keywords': ['test', 'other'],
        'file': (f.open('rb'), 'test-0.1.tar.gz')
    }
    resp = client.post('/simple/', headers=admin_headers, data=valid_data)
    assert resp.status_code == 200

    # bad action
    resp = client.post('/simple/', headers=admin_headers,
                       data={':action': 'bad'})
    assert resp.status_code == 400

    # bad data
    data = {
        ':action': 'file_upload'
    }
    resp = client.post('/simple/', headers=admin_headers, data=data)
    assert resp.status_code == 400

    # monkey patch db to raise exception
    def raise_db(obj):
        raise Exception()

# Path: extrapypi/models/user.py
# class User(db.Model):
#     ROLES = [
#         'admin',
#         'developer',
#         'installer',
#         'maintainer'
#     ]
# 
#     id = db.Column(db.Integer, primary_key=True)
#     username = db.Column(db.String(255), nullable=False, unique=True)
#     email = db.Column(db.String(255), nullable=False, unique=True)
#     password_hash = db.Column(db.String(255), nullable=False)
#     is_active = db.Column(db.Boolean, default=True)
#     role = db.Column(db.String(80), nullable=True)
# 
#     @validates('role')
#     def validate_role(self, key, role):
#         assert role in self.ROLES or role is None
#         return role
# 
#     @property
#     def is_authenticated(self):
#         return True
# 
#     @property
#     def is_anonymous(self):
#         return False
# 
#     @property
#     def is_admin(self):
#         return self.role == 'admin'
# 
#     def get_id(self):
#         try:
#             return unicode(self.id)
#         except NameError:
#             return str(self.id)
# 
#     def __repr__(self):
#         return "<User {0.username}>".format(self)
# 
# Path: extrapypi/extensions.py



# Path: tests/test_views.py
from extrapypi.models import User
from extrapypi.extensions import db

    f.write("a simple test")
    valid_data = {
        ':action': 'file_upload',
        'name': 'uploaded',
        'summary': 'from unittests',
        'description': 'simple upload test',
        'download_url': '',
        'home_page': '',
        'version': '0.1',
        'keywords': ['test', 'other'],
        'file': (f.open('rb'), 'test-0.1.tar.gz')
    }
    resp = client.post('/simple/', headers=admin_headers, data=valid_data)
    assert resp.status_code == 200

    # bad action
    resp = client.post('/simple/', headers=admin_headers,
                       data={':action': 'bad'})
    assert resp.status_code == 400

    # bad data
    data = {
        ':action': 'file_upload'
    }
    resp = client.post('/simple/', headers=admin_headers, data=data)
    assert resp.status_code == 400

    # monkey patch db to raise exception
    def raise_db(obj):
        raise Exception()

    monkeypatch.setattr(db.session, 'commit', raise_db)