예제 #1
0
    def test_will_not_return_a_deleted_term(self):
        term_one = TermsFactory()
        term_two = TermsFactory(deleted=True)

        response = self.app.get('/terms', content_type='application/json')
        self.assertEqual(response.status_code, constants.OK)
        output = json.loads(response.data)
        self.assertEquals(output.get('message'), constants.TERMS_FOUND)
        terms = output.get('terms')
        self.assertEquals(1, len(terms))
        received_terms = [term.get('word') for term in terms]
        self.assertIn(term_one.word, received_terms)
        self.assertNotIn(term_two.word, received_terms)
예제 #2
0
 def test_create_related_term_will_return_created_related_term_status(self):
     term = TermsFactory()
     related_term = TermsFactory()
     sample = {'term_id': term.id, 'related_term_id': related_term.id}
     response = self.app.post('/related-terms/',
                              data=json.dumps(sample),
                              content_type='application/json')
     self.assertEqual(response.status_code, constants.CREATED_RELATED_TERM)
     output = json.loads(response.data)
     related_term_id = output.get('related_term').get('related_term_id')
     term_id = output.get('related_term').get('term_id')
     self.assertEqual(related_term_id, related_term.id)
     self.assertEqual(term_id, term.id)
     self.assertEqual(output.get('message'), constants.CREATED_RELATED_TERM)
예제 #3
0
 def test_will_not_return_term_when_is_deleted(self):
     term = TermsFactory(deleted=True)
     response = self.app.get('/terms/{}'.format(term.id),
                             content_type='application/json')
     self.assertEqual(response.status_code, constants.DELETED)
     output = json.loads(response.data)
     self.assertEquals(output.get('message'), constants.TERM_DELETED)
예제 #4
0
 def test_will_return_term_when_it_exists(self):
     term = TermsFactory()
     response = self.app.get('/terms/{}'.format(term.id),
                             content_type='application/json')
     self.assertEqual(response.status_code, constants.FOUND)
     output = json.loads(response.data)
     self.assertEquals(output.get('message'), constants.TERM_FOUND)
예제 #5
0
 def test_will_return_error_when_payload_is_missing(self):
     term = TermsFactory()
     response = self.app.patch('/terms/{}'.format(term.id),
                               content_type='application/json')
     self.assertEqual(response.status_code, constants.ERROR)
     output = json.loads(response.data)
     self.assertEquals(output.get('message'), constants.MISSING_PAYLOAD)
예제 #6
0
 def test_will_return_deleted_when_trying_to_delete(self):
     tf = TermsFactory()
     response = self.app.delete('/terms/{}'.format(tf.id),
                                content_type='application/json')
     self.assertEqual(response.status_code, constants.DELETED)
     output = json.loads(response.data)
     self.assertEquals(output.get('message'), constants.TERM_DELETED)
예제 #7
0
 def test_create_word_will_fail_due_to_repeated_term(self):
     TermsFactory(word='asincrono')
     stub = {'word': 'asincrono', 'definition': 'Thread of life'}
     response = self.app.post('/term/',
                              data=json.dumps(stub),
                              content_type='application/json')
     obtained_code = response.status_code
     self.assertEqual(obtained_code, constants.ERROR)
예제 #8
0
 def test_will_be_logically_deleted(self):
     tf = TermsFactory()
     response = self.app.delete('/terms/{}'.format(tf.id),
                                content_type='application/json')
     self.assertEqual(response.status_code, constants.DELETED)
     output = json.loads(response.data)
     self.assertEquals(output.get('message'), constants.TERM_DELETED)
     witness = Terms.query.get(tf.id)
     self.assertTrue(witness.deleted)
예제 #9
0
 def test_create_relation_fails_because_related_term_does_not_exist(self):
     term = TermsFactory()
     sample = {'term_id': term.id + 1, 'related_term_id': term.id}
     response = self.app.post('/related-terms/',
                              data=json.dumps(sample),
                              content_type='application/json')
     self.assertEqual(response.status_code, constants.NOT_FOUND)
     output = json.loads(response.data)
     self.assertEqual(output.get('message'), constants.TERM_NOT_FOUND)
예제 #10
0
 def test_will_update_when_payload_is_ok(self):
     term = TermsFactory()
     stub = {
         'word': 'A word',
         'definition': 'Is what we need',
         'extra': 'This will not affect'
     }
     response = self.app.patch('/terms/{}'.format(term.id),
                               data=json.dumps(stub),
                               content_type='application/json')
     self.assertEqual(response.status_code, constants.UPDATED)
     output = json.loads(response.data)
     self.assertEquals(output.get('message'), constants.TERM_UPDATED)
예제 #11
0
 def test_will_fail_when_definition_is_space(self):
     term = TermsFactory()
     stub = {
         'word': 'Something',
         'definition': ' ',
         'extra': 'This will not affect'
     }
     response = self.app.patch('/terms/{}'.format(term.id),
                               data=json.dumps(stub),
                               content_type='application/json')
     self.assertEqual(response.status_code, constants.ERROR)
     output = json.loads(response.data)
     expected = {'definition': ['Word cannot be a space']}
     self.assertEquals(output.get('message'), expected)
예제 #12
0
 def test_will_fail_when_name_is_not_none(self):
     term = TermsFactory()
     stub = {
         'word': None,
         'definition': 'Is what we need',
         'extra': 'This will not affect'
     }
     response = self.app.patch('/terms/{}'.format(term.id),
                               data=json.dumps(stub),
                               content_type='application/json')
     self.assertEqual(response.status_code, constants.ERROR)
     output = json.loads(response.data)
     expected = {'word': ['Field may not be null.']}
     self.assertEquals(output.get('message'), expected)
예제 #13
0
 def test_will_not_return_a_deleted_term_in_related_terms(self):
     deleted_term = TermsFactory(deleted=True, word='deleted')
     related_term_with_deleted = RelatedTermsFactory(term=deleted_term)
     related_term = RelatedTermsFactory()
     response = self.app.get('/related-terms',
                             content_type='application/json')
     self.assertEqual(response.status_code, constants.OK)
     output = json.loads(response.data)
     # logger.debug(output.get('related_terms'))
     self.assertEquals(output.get('message'), constants.RELATED_TERMS_FOUND)
     related_terms = output.get('related_terms')
     self.assertEquals(1, len(related_terms))
     received_terms = [term.get('id') for term in related_terms]
     self.assertIn(related_term.id, received_terms)
     self.assertNotIn(related_term_with_deleted.id, received_terms)