from tests.test_actions import *
from ltk.actions import Action

import unittest

class TestRequest(unittest.TestCase):
    @classmethod
    def setUpClass(cls):
        create_config()

    @classmethod
    def tearDownClass(cls):
        cleanup()

    def setUp(self):
        self.action = Action(os.getcwd())
        self.files = ['sample.txt', 'sample1.txt', 'sample2.txt']
        self.first_doc = 'sample.txt'
        for fn in self.files:
            create_txt_file(fn)
        self.action.add_action(None, ['sample*.txt'])
        self.doc_ids = self.action.doc_manager.get_doc_ids()
        for doc_id in self.doc_ids:
            assert poll_doc(self.action, doc_id)

    def tearDown(self):
        for curr_file in self.files:
            self.action.rm_action(curr_file, True)
        self.action.clean_action(False, False, None)

    def check_locales_exist(self, documents, locales):
        for document in documents:
            curr_doc = self.action.doc_manager.get_doc_by_prop('file_name', document)
            return all(locale in curr_doc['locales'] for locale in locales)

    def test_request_one_locale_doc(self):
        locales = ['ja_JP']
        self.action.target_action(self.first_doc, locales, False, None, None)
        assert self.check_locales_exist([self.first_doc], locales)

    def test_request_mult_locale_doc(self):
        locales = ['ja_JP', 'zh_CN', 'es_MX']
        self.action.target_action(self.first_doc, locales, False, None, None)
        assert self.check_locales_exist([self.first_doc], locales)

    def test_request_one_locale_proj(self):
        locales = ['ja_JP']
        self.action.target_action(None, locales, False, None, None)
        assert self.check_locales_exist(self.files, locales)

    def test_request_mult_locale_proj(self):
        locales = ['ja_JP', 'zh_CN', 'es_MX']
        self.action.target_action(None, locales, False, None, None)
        assert self.check_locales_exist(self.files, locales)

    def test_delete_locale_doc(self):
        locales = ['ja_JP']
        self.action.target_action(self.first_doc, locales, False, None, None)
        assert self.check_locales_exist(self.first_doc, locales)
        self.action.target_action(self.first_doc, 'ja_JP', True, None, None)
        assert not self.check_locales_exist(self.first_doc, locales)

    def test_delete_locale_proj(self):
        locales = ['ja_JP']
        self.action.target_action(None, locales, False, None, None)
        assert self.check_locales_exist(self.first_doc, locales)
        self.action.target_action(None, 'ja_JP', True, None, None)
        assert not self.check_locales_exist(self.files, locales)

@@ -998,13 +998,8 @@
 op('
-file_
 name
@@ -2140,32 +2140,33 @@
 k_locales_exist(
+%5B
 self.first_doc, 
@@ -2155,32 +2155,33 @@
 (%5Bself.first_doc
+%5D
 , locales)%0A     
@@ -2225,23 +2225,23 @@
 st_doc, 
-'ja_JP'
+locales
 , True, 
@@ -2288,32 +2288,33 @@
 k_locales_exist(
+%5B
 self.first_doc, 
@@ -2303,32 +2303,33 @@
 (%5Bself.first_doc
+%5D
 , locales)%0A%0A    
@@ -2495,24 +2495,25 @@
 cales_exist(
+%5B
 self.first_d
@@ -2506,32 +2506,33 @@
 (%5Bself.first_doc
+%5D
 , locales)%0A     
@@ -2566,23 +2566,23 @@
 n(None, 
-'ja_JP'
+locales
 , True, 

fix request tests