#197 Adding more unittests
Merged 7 years ago by skrzepto. Opened 7 years ago by skrzepto.
skrzepto/fedora-hubs unittest  into  unittest

@@ -206,6 +206,80 @@ 

              self.assertEqual(result.status_code, 302)

              self.assertEqual(urlparse(result.location).path, "/")

  

+     def test_hub_add_widget_get_no_args(self):

+         result = self.app.get('/ralph/add', follow_redirects=False)

+         self.assertEqual(result.status_code, 400)

+         expected_str = 'Invalid position provided'

+         self.assertTrue(expected_str in result.data)

+ 

+     def test_hub_add_widget_get_with_args(self):

+         result = self.app.get('/ralph/add?position=right',

+                               follow_redirects=True)

+         self.assertEqual(result.status_code, 200)

+         expected_str = 'Adding widget to hub: ralph'

+         self.assertTrue(expected_str in result.data)

+         expected_str = "url: 'add/' + $('#widget').val() + '?position=right',"

+         self.assertTrue(expected_str in result.data)

+ 

+     def test_hub_add_widget_post_no_widget_name(self):

+         data = {}

+         result = self.app.post('/ralph/add', data=data, follow_redirects=False)

+         self.assertEqual(result.status_code, 400)

+         expected_str = 'Invalid request sent'

+         self.assertTrue(expected_str in result.data)

+ 

+     def test_hub_add_widget_post_invalid_widget_name(self):

+         data = {'widget_name': 'invalid_widget_name'}

+         result = self.app.post('/ralph/add', data=data, follow_redirects=False)

+         self.assertEqual(result.status_code, 404)

+         expected_str = 'Unknown widget called'

+         self.assertTrue(expected_str in result.data)

+ 

+     def test_hub_add_widget_post_valid_widget_name_no_args(self):

+         user = tests.FakeAuthorization('ralph')

+         with tests.auth_set(app, user):

+             data = {'widget_name': 'about'}

+             result = self.app.post('/ralph/add', data=data,

+                                    follow_redirects=False)

+             self.assertEqual(result.status_code, 200)

+             expected_str = '<h6 class="dropdown-header">Account Information</h6>'

+             self.assertTrue(expected_str in result.data)

+             expected_str = '<a href="#" class="dropdown-item">Full Name: fullname: ralph</a>'

+             self.assertTrue(expected_str in result.data)

+ 

+     def test_hub_add_widget_post_valid_widget_name_with_args(self):

+         user = tests.FakeAuthorization('ralph')

+         with tests.auth_set(app, user):

+             data = {'widget_name': 'about', 'text': 'text of widget'}

+             result = self.app.post('/ralph/add', data=data,

+                                    follow_redirects=False)

+             self.assertEqual(result.status_code, 200)

+             expected_str = '<h6 class="dropdown-header">Account Information</h6>'

+             self.assertTrue(expected_str in result.data)

+             expected_str = '<a href="#" class="dropdown-item">Full Name: fullname: ralph</a>'

+             self.assertTrue(expected_str in result.data)

+ 

+     def test_hub_edit_widget_get_logged_in(self):

+         user = tests.FakeAuthorization('ralph')

+         with tests.auth_set(app, user):

+             result = self.app.get('/ralph/31/edit', follow_redirects=True)

+             self.assertEqual(result.status_code, 200)

+             expected_str = '<input id="fmn_context" class="form-control" type="text"'

+             self.assertTrue(expected_str in result.data)

+ 

+     @unittest.skip("Authorization layer not present yet")

+     def test_hub_edit_widget_get_logged_out(self):

+         result = self.app.get('/ralph/31/edit', follow_redirects=True)

+         self.assertEqual(result.status_code, 403)

+ 

+     def test_hub_edit_widget_post_empty_data_logged_in(self):

+         user = tests.FakeAuthorization('ralph')

+         with tests.auth_set(app, user):

+             data = {}

+             url = '/ralph/31/edit'

+             result = self.app.post(url, data=data, follow_redirects=False)

+             self.assertEqual(result.status_code, 302)

+             self.assertEqual(urlparse(result.location).path, '/ralph/')

  

  if __name__ == '__main__':

      unittest.main()

fixing skipped tests so they pass and added test for /hub/add test

adding post tests for hub/add/ widget

added hubs edit post with valid minimum valid data

working on hubs edit widget testing Should be at 64% coverage

I may need to remove the changes in test_hub.py since atelic added them in his pr

rebased

7 years ago

rebased

7 years ago

Removed my changes from test_hub.py the PR can now be reviewed.

Minor: we probably should be consistent on whether we use double or single-quoted strings.

One minor note but looks good:

TOTAL 1457 519 64%

Ran 56 tests in 10.064s

OK (SKIP=5)

I think it depends on the situation but i agree this should be changed to single quote. Will push update soon

rebased

7 years ago

Additional note, it doesn't pass pep8 because of lines are too long but 2 out of the 4 strings are 81 chars and it doesn't make sense to split it unless someone has a suggestion that would make it pretty

IMO the 81 and 93 char lines are fine. It would probably make readability worse to change.

So :thumbsup: from me

that was the same thought i had thanks

Pull-Request has been merged by skrzepto

7 years ago
Metadata