# Path: chemistry/util.py
# def calculate_tasks(files_id_list, smile, mol_data, models):
#     num = len(files_id_list)
#     num += 1 if smile else 0
#     num += 1 if mol_data else 0
# 
#     #TODO: 计算需要优化
#     for fid in files_id_list:
#         if not fid:
#             continue
# 
#         #根据id，获取前端页面上传的文件model
#         f_record = ProcessedFile.objects.get(fid=fid)
#         if f_record.file_type.lower() in ('smi', 'cas'):
#             num += cnt_batch_file_task(f_record)
# 
#     return num * len(models)


import base64
from django.test import TestCase
from django.contrib.auth.models import User
from mock import Mock, patch
from nose.tools import eq_, ok_
from utils import basic_auth_api
from chemistry.util import calculate_tasks
#coding: utf-8



class AuthTest(TestCase):
    def setUp(self):
        self.user = User.objects.create_user('test1', 'test1@t.com', '123')

    def test_auth_api_user(self):
        request = Mock()
        request.user = self.user
        ok_(basic_auth_api(request))

    def test_auth_api_meta(self):
        request = Mock()
        request_text = base64.encodestring('test1:123')
        request.META = {"HTTP_AUTHORIZATION": "basic %s" % request_text}
        ok_(basic_auth_api(request))


# Path: chemistry/util.py
# def calculate_tasks(files_id_list, smile, mol_data, models):
#     num = len(files_id_list)
#     num += 1 if smile else 0
#     num += 1 if mol_data else 0
# 
#     #TODO: 计算需要优化
#     for fid in files_id_list:
#         if not fid:
#             continue
# 
#         #根据id，获取前端页面上传的文件model
#         f_record = ProcessedFile.objects.get(fid=fid)
#         if f_record.file_type.lower() in ('smi', 'cas'):
#             num += cnt_batch_file_task(f_record)
# 
#     return num * len(models)


# Path: chemistry/tests.py
import base64
from django.test import TestCase
from django.contrib.auth.models import User
from mock import Mock, patch
from nose.tools import eq_, ok_
from utils import basic_auth_api
from chemistry.util import calculate_tasks

#coding: utf-8



class AuthTest(TestCase):
    def setUp(self):
        self.user = User.objects.create_user('test1', 'test1@t.com', '123')

    def test_auth_api_user(self):
        request = Mock()
        request.user = self.user
        ok_(basic_auth_api(request))

    def test_auth_api_meta(self):
        request = Mock()
        request_text = base64.encodestring('test1:123')
        request.META = {"HTTP_AUTHORIZATION": "basic %s" % request_text}
        ok_(basic_auth_api(request))


        request = Mock()