# Path: coldsweat/utilities.py
# def datetime_as_epoch(value):
#     return int(timegm(value.utctimetuple()))
# 
# Path: coldsweat/models.py
# class User(CustomModel):
#     """
#     Coldsweat user
#     """    
#     DEFAULT_USERNAME = 'coldsweat' 
#     MIN_PASSWORD_LENGTH = 8
# 
#     username            = CharField(unique=True)
#     password            = CharField()  
#     email               = CharField(default='')
#     api_key             = CharField(unique=True)
#     is_enabled          = BooleanField(default=True) 
# 
#     class Meta:
#         db_table = 'users'
#     
#     @staticmethod
#     def make_api_key(email, password):
#         return make_md5_hash(u'%s:%s' % (email, password))
# 
#     @staticmethod
#     def validate_api_key(api_key):
#         try:
#             # Clients may send api_key in uppercase, lower it
#             user = User.get((User.api_key == api_key.lower()) & 
#                 (User.is_enabled == True))        
#         except User.DoesNotExist:
#             return None
# 
#         return user
# 
#     @staticmethod
#     def validate_credentials(username_or_email, password):        
#         '''Lookup for and existing username/e-mail combo and password'''
#         try:
#             user = User.get(((User.username == username_or_email) | 
#                 (User.email == username_or_email)) & 
#                 (User.is_enabled == True))
#         except User.DoesNotExist:
#             return None
# 
#         # Do a case-sensitive compare
#         if user.password != password:
#             return None
# 
#         return user
#     
#     @staticmethod
#     def validate_password(password):
#         return len(password) >= User.MIN_PASSWORD_LENGTH


import sys, subprocess, optparse
from datetime import datetime
from ..utilities import datetime_as_epoch
from ..models import User
            (True, 'mark=feed&as_=read&id=1&before=%d' % epoch),    # Malformed (5)
            (True, 'mark=feed&as=read&id=0&before=%d' % epoch),     # Does not exist
        ]) 

    if 'mark_group' in suites:
        queries.extend([
            (True, 'mark=group&as=read&id=1&before=%d' % epoch), 
            (True, 'mark=group&as=read&id=1&before=abc'),           # Malformed 
            (True, 'mark=group&as=read&id=-1&before=%d' % epoch),   # Unsupported
        ]) 

    if 'mark_all' in suites:
        queries.extend([
            (True, 'mark=group&as=read&id=0&before=%d' % epoch),    # Mark all as read 
        ])         

    if 'unread_read' in suites:
        queries.extend([
            (True, 'unread_recently_read=1')
        ])          
                              
    # Test auth failure
    print ('\n= auth (failure)\n')

    subprocess.call([
        "curl", 
        "-dapi_key=%s" % 'wrong-api-key',
        "%s?api&unread_item_ids" % endpoint
    ])
    

# Path: coldsweat/utilities.py
# def datetime_as_epoch(value):
#     return int(timegm(value.utctimetuple()))
# 
# Path: coldsweat/models.py
# class User(CustomModel):
#     """
#     Coldsweat user
#     """    
#     DEFAULT_USERNAME = 'coldsweat' 
#     MIN_PASSWORD_LENGTH = 8
# 
#     username            = CharField(unique=True)
#     password            = CharField()  
#     email               = CharField(default='')
#     api_key             = CharField(unique=True)
#     is_enabled          = BooleanField(default=True) 
# 
#     class Meta:
#         db_table = 'users'
#     
#     @staticmethod
#     def make_api_key(email, password):
#         return make_md5_hash(u'%s:%s' % (email, password))
# 
#     @staticmethod
#     def validate_api_key(api_key):
#         try:
#             # Clients may send api_key in uppercase, lower it
#             user = User.get((User.api_key == api_key.lower()) & 
#                 (User.is_enabled == True))        
#         except User.DoesNotExist:
#             return None
# 
#         return user
# 
#     @staticmethod
#     def validate_credentials(username_or_email, password):        
#         '''Lookup for and existing username/e-mail combo and password'''
#         try:
#             user = User.get(((User.username == username_or_email) | 
#                 (User.email == username_or_email)) & 
#                 (User.is_enabled == True))
#         except User.DoesNotExist:
#             return None
# 
#         # Do a case-sensitive compare
#         if user.password != password:
#             return None
# 
#         return user
#     
#     @staticmethod
#     def validate_password(password):
#         return len(password) >= User.MIN_PASSWORD_LENGTH


# Path: coldsweat/tests/fever.py
import sys, subprocess, optparse
from datetime import datetime
from ..utilities import datetime_as_epoch
from ..models import User

            (True, 'mark=feed&as_=read&id=1&before=%d' % epoch),    # Malformed (5)
            (True, 'mark=feed&as=read&id=0&before=%d' % epoch),     # Does not exist
        ]) 

    if 'mark_group' in suites:
        queries.extend([
            (True, 'mark=group&as=read&id=1&before=%d' % epoch), 
            (True, 'mark=group&as=read&id=1&before=abc'),           # Malformed 
            (True, 'mark=group&as=read&id=-1&before=%d' % epoch),   # Unsupported
        ]) 

    if 'mark_all' in suites:
        queries.extend([
            (True, 'mark=group&as=read&id=0&before=%d' % epoch),    # Mark all as read 
        ])         

    if 'unread_read' in suites:
        queries.extend([
            (True, 'unread_recently_read=1')
        ])          
                              
    # Test auth failure
    print ('\n= auth (failure)\n')

    subprocess.call([
        "curl", 
        "-dapi_key=%s" % 'wrong-api-key',
        "%s?api&unread_item_ids" % endpoint
    ])
    

    api_key=User.make_api_key(*TEST_USER_CREDENTIALS)