Beispiel #1
0
 def test_happyCaseGetRants(self, mock_get_rants_response):
     test_content = {
         'rants': [{
             'id': 1234,
             'text': 'Txt',
             'score': 111,
             'created_time': 234432,
             'user_id': 43289,
             'num_comments': 121,
             'user_username': '******'
         }],
         'news': {
             'id': 123,
             'type': 'T',
             'headline': 'MyHeadline',
             'body': 'MyBody',
             'footer': 'MyFooter',
             'height': 456,
             'action': 'MyAction'
         },
         'success':
         True,
         'set':
         '1',
         'wrw':
         1
     }
     test_content = json.dumps(test_content)
     mock_response = MockHttpResponse(test_content, 200)
     mock_get_rants_response.return_value = mock_response
     rants = self.devrant.get_rants("top", 1, 0)
     self.assertTrue(mock_get_rants_response.called)
     self.assertEqual(rants['rants'][0]['text'], 'Txt')
Beispiel #2
0
 def test_happyCaseGetRantById(self, mock_get_rant_by_id_response):
     test_content = {
         'rant': {
             'id': 1234,
             'text': 'Txt',
             'score': 111,
             'created_time': 234432,
             'user_id': 43289,
             'num_comments': 121,
             'user_username': '******'
         },
         'comments': [{
             'id': 1234,
             'rant_id': 2345,
             'body': 'test body',
             'upvotes': 2,
             'downvotes': 1,
             'score': 10,
             'created_time': 20102313123,
             'user_id': 111,
             'user_username': '******',
             'user_userscore': 56
         }],
         'success':
         True
     }
     test_content = json.dumps(test_content)
     test_status_code = 200
     mock_response = MockHttpResponse(test_content, test_status_code)
     mock_get_rant_by_id_response.return_value = mock_response
     rant = self.devrant.get_rant_by_id(2)
     self.assertTrue(mock_get_rant_by_id_response.called)
     assert rant['rant']['id'] == 1234
     assert rant['comments'][0]['upvotes'] == 2
Beispiel #3
0
 def test_successful_get_rants_build_response(self):
     test_content = {
         'rants': [{
             'id': 1234,
             'text': 'Txt',
             'score': 111,
             'created_time': 234432,
             'user_id': 43289,
             'num_comments': 121,
             'user_username': '******'
         }],
         'news': {
             'id': 123,
             'type': 'T',
             'headline': 'MyHeadline',
             'body': 'MyBody',
             'footer': 'MyFooter',
             'height': 456,
             'action': 'MyAction'
         },
         'success':
         True,
         'set':
         '1',
         'wrw':
         1
     }
     test_content = json.dumps(test_content)
     test_status_code = 200
     mockResponse = MockHttpResponse(test_content, test_status_code)
     rants = self.responseHandler.get_rants_build_response(mockResponse)
     assert rants['rants'][0]['id'] == 1234
Beispiel #4
0
 def test_successful_get_rant_by_id_build_response(self):
     test_content = {
         'rant': {
             'id': 1234,
             'text': 'Txt',
             'score': 111,
             'created_time': 234432,
             'user_id': 43289,
             'num_comments': 121,
             'user_username': '******'
         },
         'comments': [{
             'id': 1234,
             'rant_id': 2345,
             'body': 'test body',
             'upvotes': 2,
             'downvotes': 1,
             'score': 10,
             'created_time': 20102313123,
             'user_id': 111,
             'user_username': '******',
             'user_userscore': 56
         }],
         'success':
         True
     }
     test_content = json.dumps(test_content)
     test_status_code = 200
     mockResponse = MockHttpResponse(test_content, test_status_code)
     rant = self.responseHandler.get_rant_by_id_build_response(mockResponse)
     assert rant['rant']['id'] == 1234
     assert rant['comments'][0]['upvotes'] == 2
Beispiel #5
0
 def test_happy_case_get_weekly_rants(self, mock_get_weekly_rants_response):
     test_content = {
         "success":
         True,
         "rants": [
             {
                 "id": 890185,
                 "text": "Pixel 2 design looks like shit.",
                 "score": 1,
                 "created_time": 1507147639,
                 "attached_image": "",
                 "num_comments": 3,
                 "tags": ["wk72"],
                 "vote_state": 0,
                 "edited": False,
                 "rt": 1,
                 "rc": 1,
                 "user_id": 80000,
                 "user_username": "******",
                 "user_score": 366,
                 "user_avatar": {
                     "b":
                     "69c9cd",
                     "i":
                     "v-17_c-3_b-6_g-m_9-1_1-6_16-1_3-2_8-1_7-1_5-1_12-6_6-14_2-3_15-14_11-1_4-1.jpg"
                 }
             },
         ],
         "settings": [],
         "wrw":
         72,
         "news": {
             "id": 0,
             "type": "weekly",
             "headline": "Worst code review experience?",
             "footer": "Week 72 Group Rant - Add tag 'wk72' to your rant",
             "height": 65,
             "action": "none"
         }
     }
     test_content = json.dumps(test_content)
     test_status_code = 200
     mock_reponse = MockHttpResponse(test_content, test_status_code)
     mock_get_weekly_rants_response.return_value = mock_reponse
     rant = self.devrant.get_weekly_rants("algo", 2)
     self.assertTrue(mock_get_weekly_rants_response.called)
     assert rant['rants'][0]['id'] == 890185
Beispiel #6
0
 def test_happy_case_get_collabs(self, mock_get_collabs_response):
     test_content = {
         "success":
         True,
         "rants": [{
             "id": 1,
             "text": "Test text",
             "score": 5,
             "created_time": 1507872,
             "attached_image": "",
             "num_comments": 3,
             "tags": [],
             "vote_state": 0,
             "edited": False,
             "link": "collabs\/1\/test",
             "rt": 2,
             "rc": 2,
             "c_type": 3,
             "c_type_long": "Project idea",
             "user_id": 3321,
             "user_username": "******",
             "user_score": 14,
             "user_avatar": {
                 "b": "2awsd",
                 "i":
                 "v-17_c-3_b-4_g-m_9-1_1-9-9_6-3_10-1_2-10_15-11_4-1.jpg"
             }
         }]
     }
     test_content = json.dumps(test_content)
     test_status_code = 200
     mock_response = MockHttpResponse(test_content, test_status_code)
     mock_get_collabs_response.return_value = mock_response
     collabs = self.devrant.get_collabs(0, 1)
     self.assertTrue(mock_get_collabs_response.called)
     assert collabs['rants'][0]['id'] == 1
Beispiel #7
0
 def test_happy_case_search_rants_by_keyword(
         self, mock_search_rants_by_keyword_response):
     test_content = {
         "success":
         True,
         "results": [{
             "id": 173,
             "text": "Random Text 1",
             "score": 241,
             "created_time": 14707,
             "attached_image": "",
             "num_comments": 5,
             "tags": [],
             "vote_state": 0,
             "edited": False,
             "rt": 1,
             "rc": 1,
             "user_id": 473,
             "user_username": "******",
             "user_score": 3,
             "user_avatar": {
                 "b": "2b9d",
                 "i": "v-175_4-2.jpg"
             }
         }, {
             "id":
             5878,
             "text":
             "Random text 2",
             "score":
             238,
             "created_time":
             1492513,
             "attached_image": {
                 "url": "https://sample.url",
                 "width": 800,
                 "height": 516
             },
             "num_comments":
             13,
             "tags": ["family", "tech support", "won't fix your computer"],
             "vote_state":
             0,
             "edited":
             False,
             "rt":
             1,
             "rc":
             1,
             "user_id":
             5458,
             "user_username":
             "******",
             "user_score":
             327,
             "user_avatar": {
                 "b": "2a8b9d",
                 "i": "v-17_c-3_b-_19-1.jpg"
             }
         }]
     }
     test_content = json.dumps(test_content)
     test_status_code = 200
     test_keyword = "test"
     mock_reponse = MockHttpResponse(test_content, test_status_code)
     mock_search_rants_by_keyword_response.return_value = mock_reponse
     searchResults = self.devrant.search_rants_by_keyword(test_keyword)
     self.assertTrue(mock_search_rants_by_keyword_response.called)
     assert searchResults['success'] == True
Beispiel #8
0
 def test_happyCaseMockHttpResponse(self):
     test_content = "sample"
     test_status_code = 200
     mockResponse = MockHttpResponse(test_content, test_status_code)
     assert mockResponse.content == test_content
     assert mockResponse.status_code == test_status_code