# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# MIT License. See license.txt

from __future__ import unicode_literals
import unittest
import webnotes
from webnotes.test_runner import make_test_records

class TestDB(unittest.TestCase):
	def test_get_value(self):
		webnotes.conn.sql("""delete from `tabProfile` where name not in ('Administrator', 'Guest')""")
		del webnotes.test_objects["Profile"]
		make_test_records("Profile")
		
		self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["=", "Administrator"]}), "Administrator")
		self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["like", "Admin%"]}), "Administrator")
		self.assertEquals(webnotes.conn.get_value("Profile", {"name": ["!=", "Guest"]}), "Administrator")
		
		from webnotes.utils import nowdate
		self.assertEquals(webnotes.conn.get_value("Profile", {"modified": ["<", nowdate()]}), "Administrator")
		self.assertEquals(webnotes.conn.get_value("Profile", {"modified": ["<=", nowdate()]}), "Administrator")
		self.assertEquals(webnotes.conn.get_value("Profile", {"modified": [">", nowdate()]}), "test1@example.com")
		self.assertEquals(webnotes.conn.get_value("Profile", {"modified": [">=", nowdate()]}), "test1@example.com")
		
		
@@ -264,16 +264,72 @@
 (self):%0A
+%09%09from webnotes.utils import now_datetime%0A%09%09import time%0A
 %09%09webnot
@@ -423,74 +423,30 @@
 )%0A%09%09
-del webnotes.test_objects%5B%22Profile%22%5D%0A%09%09make_test_records(%22Profile%22
+%0A%09%09now = now_datetime(
 )%0A%09%09
@@ -760,48 +760,8 @@
 r%22)%0A
-%09%09%0A%09%09from webnotes.utils import nowdate%0A
 %09%09se
@@ -829,30 +829,24 @@
 %22: %5B%22%3C%22, now
-date()
 %5D%7D), %22Admini
@@ -929,30 +929,24 @@
 : %5B%22%3C=%22, now
-date()
 %5D%7D), %22Admini
@@ -955,36 +955,189 @@
 rator%22)%0A
-%09%09self.assertEquals(
+%0A%09%09time.sleep(2)%0A%09%09if %22Profile%22 in webnotes.test_objects:%0A%09%09%09del webnotes.test_objects%5B%22Profile%22%5D%0A%09%09make_test_records(%22Profile%22)%0A%09%09%0A%09%09self.assertEquals(%22test1@example.com%22, 
 webnotes
@@ -1189,38 +1189,11 @@
  now
-date()%5D%7D), %22test1@example.com%22
+%5D%7D)
 )%0A%09%09
@@ -1202,32 +1202,53 @@
 lf.assertEquals(
+%22test1@example.com%22, 
 webnotes.conn.ge
@@ -1293,38 +1293,11 @@
  now
-date()%5D%7D), %22test1@example.com%22
+%5D%7D)
 )%0A%09%09

fix in test cases