<commit_before>from apps.webdriver_testing.webdriver_base import WebdriverTestCase
from apps.webdriver_testing import data_helpers
from apps.webdriver_testing.data_factories import UserFactory
from apps.webdriver_testing.site_pages.profiles import profile_account_page 


class TestCaseUserResource(WebdriverTestCase):
    """TestSuite for uploading subtitles via the api.
    """
    
    def setUp(self):
        WebdriverTestCase.setUp(self)
        self.user = UserFactory.create(username = 'user')
        data_helpers.create_user_api_key(self, self.user)

    def api_create_user(self, **kwargs):
        """Create a user via the api.
           Creating Users:
           POST /api2/partners/users/
        """

        create_url = 'users/'
        create_data = {'username': None,
                       'email': None, 
                       'password': 'password',
                       'first_name': None, 
                       'last_name': None, 
                       'create_login_token': None
                       }
        create_data.update(kwargs)
        status, response = data_helpers.post_api_request(self, 
            create_url, 
            create_data)
        print status
        return response 


    def test_create(self):
        """Create a user via the api.

        """
        new_user = {'username': 'newuser',
                    'email': '<EMAIL>',
                    'first_name': 'New', 
                    'last_name': 'User_1',
                    }
        user_data = self.api_create_user(**new_user)
        print user_data
        self.assertEqual('newuser', user_data['username'])

    def test_create__login_token(self):
        """Create a user and login token, verify login.

        """
        new_user = {'username': 'newuser',
                    'email': '<EMAIL>',
                    'first_name': 'New', 
                    'last_name': 'User_1',
                    'create_login_token': True
                    }
        user_data = self.api_create_user(**new_user)
        api_key = user_data['api_key']
        login_url = user_data['auto_login_url']
        print api_key, login_url
        profile_account_pg = profile_account_page.ProfileAccountPage(self)
        self.browser.execute_script(
            "var url = arguments[0] ; window.open(url, '_self')", login_url)
        #profile_account_pg.open_page(login_url)
        time.sleep(3)
        profile_account_pg.open_profile_account()
        self.assertEqual(api_key, profile_account_pg.current_api_key())

        

    def test_create__invalid_email(self):
        new_user = {'username': 'newuser',
                    'email': '<EMAIL>',
                    'first_name': 'New', 
                    'last_name': 'User_1',
                    }
        user_data = self.api_create_user(**new_user)
        self.assertEqual('Enter a valid e-mail address.', user_data['email'][0])

    def test_create__invalid_username(self):
        new_user = {'username': 'new user',
                    'email': '<EMAIL>',
                    'first_name': 'New', 
                    'last_name': 'User_1',
                    }
        user_data = self.api_create_user(**new_user)
        self.assertEqual('This value may contain only letters, numbers and @/./+/-/_ characters.', 
                         user_data['username'][0])

    
<commit_msg>Revert "trying a direct open to workaround jenkins craziness" "because it didn't help"<commit_after>from apps.webdriver_testing.webdriver_base import WebdriverTestCase
from apps.webdriver_testing import data_helpers
from apps.webdriver_testing.data_factories import UserFactory
from apps.webdriver_testing.site_pages.profiles import profile_account_page 


class TestCaseUserResource(WebdriverTestCase):
    """TestSuite for uploading subtitles via the api.
    """
    
    def setUp(self):
        WebdriverTestCase.setUp(self)
        self.user = UserFactory.create(username = 'user')
        data_helpers.create_user_api_key(self, self.user)

    def api_create_user(self, **kwargs):
        """Create a user via the api.
           Creating Users:
           POST /api2/partners/users/
        """

        create_url = 'users/'
        create_data = {'username': None,
                       'email': None, 
                       'password': 'password',
                       'first_name': None, 
                       'last_name': None, 
                       'create_login_token': None
                       }
        create_data.update(kwargs)
        status, response = data_helpers.post_api_request(self, 
            create_url, 
            create_data)
        print status
        return response 


    def test_create(self):
        """Create a user via the api.

        """
        new_user = {'username': 'newuser',
                    'email': '<EMAIL>',
                    'first_name': 'New', 
                    'last_name': 'User_1',
                    }
        user_data = self.api_create_user(**new_user)
        print user_data
        self.assertEqual('newuser', user_data['username'])

    def test_create__login_token(self):
        """Create a user and login token, verify login.

        """
        new_user = {'username': 'newuser',
                    'email': '<EMAIL>',
                    'first_name': 'New', 
                    'last_name': 'User_1',
                    'create_login_token': True
                    }
        user_data = self.api_create_user(**new_user)
        api_key = user_data['api_key']
        login_url = user_data['auto_login_url']
        print api_key, login_url
        profile_account_pg = profile_account_page.ProfileAccountPage(self)
        profile_account_pg.open_page(login_url)
        profile_account_pg.open_profile_account()
        
        self.assertEqual(api_key, profile_account_pg.current_api_key())

        

    def test_create__invalid_email(self):
        new_user = {'username': 'newuser',
                    'email': 'stone-<EMAIL>ing-<EMAIL>@<EMAIL>',
                    'first_name': 'New', 
                    'last_name': 'User_1',
                    }
        user_data = self.api_create_user(**new_user)
        self.assertEqual('Enter a valid e-mail address.', user_data['email'][0])

    def test_create__invalid_username(self):
        new_user = {'username': 'new user',
                    'email': '<EMAIL>',
                    'first_name': 'New', 
                    'last_name': 'User_1',
                    }
        user_data = self.api_create_user(**new_user)
        self.assertEqual('This value may contain only letters, numbers and @/./+/-/_ characters.', 
                         user_data['username'][0])

    

{'fraction_non_alphanumeric': 0.10722784057108864, 'fraction_numerical': 0.002379535990481856, 'mean_word_length': 1.8641396933560477, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4329823', 'n_tokens_mistral': 1912, 'n_tokens_neox': 1816, 'n_words': 366}