def test_valid_first_name(self): response = self.client.post(self.url, { 'first_name': 'contributor', 'email': self.user.email }) assert_contains(response, 'Settings saved.')
def test_valid_first_name(self): response = self.client.post(self.url, { "first_name": "contributor", "email": self.user.email }) assert_contains(response, "Settings saved.")
def testLoginProcess(self): login = self.app.get(reverse('auth_login')) login.form['username'] = '******' login.form['password'] = '******' response = login.form.submit('Log in').follow() assert_equals('200 OK', response.status) assert_contains(response, 'Welcome danu :]', count=1, status_code=200)
def test_valid_first_name(self): response = self.client.post( self.url, {'first_name': 'contributor', 'email': self.user.email} ) assert_contains(response, 'Settings saved.')
def testSubmitWithEmptyCredentials(self): login = self.app.get(reverse('auth_login')) login.form['username'] = '' login.form['password'] = '' response = login.form.submit('Log in') assert_contains( response, 'This field is required.', count=2, status_code=200 )
def testLoginWithInvalidCredentials(self): login = self.app.get(reverse('auth_login')) login.form['username'] = '******' login.form['password'] = '******' response = login.form.submit('Log in') assert_contains( response, 'Please enter a correct username and password. ' 'Note that both fields are case-sensitive.', count=1, status_code=200 )
def testUserAlreadyExists(self): register = self.app.get(reverse('registration_register')) register.form['username'] = '******' register.form['email'] = '*****@*****.**' register.form['password1'] = 'test123' register.form['password2'] = 'test123' response = register.form.submit('Submit') assert_contains( response, 'A user with that username already exists.', count=1, status_code=200 )
def testEmailFieldValidation(self): register = self.app.get(reverse('registration_register')) register.form['username'] = '******' register.form['email'] = 'abc' register.form['password1'] = 'test123' register.form['password2'] = 'test123' response = register.form.submit('Submit') self.assertFieldOutput( forms.EmailField, {'*****@*****.**': '*****@*****.**'}, {'abc': [u'Enter a valid e-mail address.']} ) assert_contains( response, 'Enter a valid e-mail address.', count=1, status_code=200 )
def test_manage_project_strings_list(self): project = ProjectFactory.create(data_source='database', repositories=[]) resource = ResourceFactory.create(project=project) nb_entities = 2 entities = EntityFactory.create_batch(nb_entities, resource=resource) url = reverse('pontoon.admin.project.strings', args=(project.slug, )) response = self.client.get(url) assert_code(response, 200) for i in range(nb_entities): assert_contains(response, 'string %s' % i) # Test editing strings and comments. form_data = { 'form-TOTAL_FORMS': nb_entities, 'form-INITIAL_FORMS': nb_entities, 'form-MIN_NUM_FORMS': 0, 'form-MAX_NUM_FORMS': 1000, 'form-0-id': entities[0].id, 'form-0-string': 'changed 0', 'form-0-comment': 'Wubba lubba dub dub', 'form-1-id': entities[1].id, 'form-1-string': 'string 1', 'form-1-obsolete': 'on', # Remove this one. } response = self.client.post(url, form_data) assert_code(response, 200) assert_contains(response, 'changed 0') assert_contains(response, 'Wubba lubba dub dub') assert_not_contains(response, 'string 0') assert_not_contains(response, 'string 1') # It's been removed.
def testActivationExpired(self): register = self.app.get(reverse('registration_register')) register.form['username'] = '******' register.form['email'] = '*****@*****.**' register.form['password1'] = 'test123' register.form['password2'] = 'test123' response = register.form.submit('Submit').follow() user = User.objects.get(username='******') user.date_joined -= datetime.timedelta( days=settings.ACCOUNT_ACTIVATION_DAYS ) user.save() activation_url = re.search( '/accounts/activate/(.*)', mail.outbox[0].body ).group(0) response = self.app.get(activation_url) assert_contains( response, 'Account activation failed', count=1, status_code=200 )
def test_manage_project_strings_new(self): project = ProjectFactory.create(data_source='database', repositories=[]) url = reverse('pontoon.admin.project.strings', args=(project.slug, )) # Test sending a well-formatted batch of strings. new_strings = """Hey, I just met you And this is crazy But here's my number So call me maybe? """ response = self.client.post(url, {'new_strings': new_strings}) assert_code(response, 200) # Verify a resource has been created. resources = list(Resource.objects.filter(project=project)) assert_equal(len(resources), 1) assert_equal(resources[0].path, 'database') # Verify all strings have been created as entities. entities = list(Entity.objects.filter(resource__project=project)) assert_equal(len(entities), 4) expected_strings = [ 'Hey, I just met you', 'And this is crazy', 'But here\'s my number', 'So call me maybe?', ] assert_equal(sorted(expected_strings), sorted(x.string for x in entities)) # Verify new strings appear on the page. assert_contains(response, 'Hey, I just met you')
def testMismatchedPasswords(self): invalid_data = [ { 'data': {'username': '******', 'email': '*****@*****.**', 'password1': 'test123', 'password2': 'test321'}, 'error': "The two password fields didn't match." }, ] register = self.app.get(reverse('registration_register')) for i in invalid_data: register.form['username'] = i['data']['username'] register.form['email'] = i['data']['email'] register.form['password1'] = i['data']['password1'] register.form['password2'] = i['data']['password2'] response = register.form.submit('Submit') assert_contains( response, i['error'], count=1, status_code=200 )
def testRegisterProcess(self): register = self.app.get(reverse('registration_register')) register.form['username'] = '******' register.form['email'] = '*****@*****.**' register.form['password1'] = 'test123' register.form['password2'] = 'test123' response = register.form.submit('Submit').follow() assert_contains( response, 'You are now registered. Activation email sent.', count=1, status_code=200 ) activation_url = re.search( '/accounts/activate/(.*)', mail.outbox[0].body ).group(0) response = self.app.get(activation_url).follow() assert_contains( response, 'Your account is now activated.', count=1, status_code=200 )
def test_missing_profile_fields(self): response = self.client.post(self.url, {}) assert_contains(response, 'This field is required.', count=2)
def testLogin(self): response = self.app.get('/', user='******') assert_equals('200 OK', response.status) assert_contains(response, 'test', count=1, status_code=200)
def test_invalid_first_name(self): response = self.client.post(self.url, {'first_name': '<aa>"\'"'}) assert_contains(response, 'Enter a valid value.')
def test_invalid_email(self): response = self.client.post(self.url, {'email': 'usermail'}) assert_contains(response, 'Enter a valid email address.')
def test_poll_details_answers_listed(self): poll = self.get_polls()[0] url = reverse("poll:detail", kwargs={"pk": poll.pk}) response = self.client.get(url) for answer in poll.answer_set.all().iterator(): assert_contains(response, answer.text)
def test_vote_simple_view_answers_present(self): self.client.login(username=self.user.username, password=self.USER_PASSWORD) response = self.client.get(self.url) for answer in self.poll.answer_set.all(): assert_contains(response, answer.text)
def test_answers_in_view(self): response = self.client.get(self.url) for answer in self.poll.answer_set.all(): assert_contains(response, answer.text)
def test_poll_list_all(self): url = reverse("poll:list") polls = self.get_polls() response = self.client.get(url) for poll in polls: assert_contains(response, poll.question)
def test_invalid_email(self): response = self.client.post(self.url, {"email": "usermail"}) assert_contains(response, "Enter a valid email address.")
def test_manage_project_strings_download_csv(self): locale_kl = LocaleFactory.create(code='kl', name='Klingon') locale_gs = LocaleFactory.create(code='gs', name='Geonosian') project = ProjectFactory.create(data_source='database', locales=[locale_kl, locale_gs], repositories=[]) url = reverse('pontoon.admin.project.strings', args=(project.slug, )) new_strings = """ And on the pedestal these words appear: 'My name is Ozymandias, king of kings: Look on my works, ye Mighty, and despair!' """ response = self.client.post(url, {'new_strings': new_strings}) assert_code(response, 200) # Test downloading the data. response = self.client.get(url, {'format': 'csv'}) assert_code(response, 200) assert_equal(response._headers['content-type'], ('Content-Type', 'text/csv')) # Verify the original content is here. assert_contains(response, 'pedestal') assert_contains(response, 'Ozymandias') assert_contains(response, 'Mighty') # Verify we have the locale columns. assert_contains(response, 'kl') assert_contains(response, 'gs') # Now add some translations. entity = Entity.objects.filter( string='And on the pedestal these words appear:')[0] Translation( string='Et sur le piédestal il y a ces mots :', entity=entity, locale=locale_kl, approved=True, ).save() Translation( string='Und auf dem Sockel steht die Schrift: ‚Mein Name', entity=entity, locale=locale_gs, approved=True, ).save() entity = Entity.objects.filter( string='\'My name is Ozymandias, king of kings:')[0] Translation( string='"Mon nom est Ozymandias, Roi des Rois.', entity=entity, locale=locale_kl, approved=True, ).save() Translation( string='Ist Osymandias, aller Kön’ge König: –', entity=entity, locale=locale_gs, approved=True, ).save() entity = Entity.objects.filter( string='Look on my works, ye Mighty, and despair!\'')[0] Translation( string='Voyez mon œuvre, vous puissants, et désespérez !"', entity=entity, locale=locale_kl, approved=True, ).save() Translation( string='Seht meine Werke, Mächt’ge, und erbebt!‘', entity=entity, locale=locale_gs, approved=True, ).save() response = self.client.get(url, {'format': 'csv'}) # Verify the translated content is here. assert_contains(response, 'pedestal') assert_contains(response, 'piédestal') assert_contains(response, 'Sockel') assert_contains(response, 'Mighty') assert_contains(response, 'puissants') assert_contains(response, 'Mächt’ge')