コード例 #1
0
ファイル: tests.py プロジェクト: stiller/ember-code-camp
def add_sessions_ratings_and_speakers():
    first_tag = Tag(description='javascript')
    last_tag = Tag(description='ember-js')
    first_tag.save()
    last_tag.save()
    first_session = Session(name='first', room='A', desc='javascript')
    last_session = Session(name='last', room='Z', desc='python')
    first_session.save()
    last_session.save()
    first_session.tags.add(first_tag)
    last_session.tags.add(last_tag)
    first_session.save()
    last_session.save()
    first_rating = Rating(score=9, feedback='legit', session=first_session)
    last_rating = Rating(score=2, feedback='broken', session=first_session)
    first_rating.save()
    last_rating.save()
    first_speaker = Speaker(name='foo', session=first_session)
    last_speaker = Speaker(name='bar', session=last_session)
    first_speaker.save()
    last_speaker.save()
    return first_session, last_session, first_rating, last_rating, first_speaker, last_speaker, first_tag, last_tag
コード例 #2
0
ファイル: tests.py プロジェクト: Jalalhejazi/ember-code-camp
def add_sessions_ratings_and_speakers():
    first_tag = Tag(description='javascript')
    last_tag = Tag(description='ember-js')
    first_tag.save()
    last_tag.save()
    first_session = Session(name='first', room='A', desc='javascript')
    last_session = Session(name='last', room='Z', desc='python')
    first_session.save()
    last_session.save()
    first_session.tags.add(first_tag)
    last_session.tags.add(last_tag)
    first_session.save()
    last_session.save()
    first_rating = Rating(score=9, feedback='legit', session=first_session)
    last_rating = Rating(score=2, feedback='broken', session=first_session)
    first_rating.save()
    last_rating.save()
    first_speaker = Speaker(name='foo', session=first_session)
    last_speaker = Speaker(name='bar', session=last_session)
    first_speaker.save()
    last_speaker.save()
    return first_session, last_session, first_rating, last_rating, first_speaker, last_speaker, first_tag, last_tag
コード例 #3
0
 def setUp(self):
     self.first_tag = Tag(description='javascript')
     self.last_tag = Tag(description='python')
     self.first_tag.save()
     self.last_tag.save()
コード例 #4
0
class TagTests(TestCase):

    def setUp(self):
        self.first_tag = Tag(description='javascript')
        self.last_tag = Tag(description='python')
        self.first_tag.save()
        self.last_tag.save()

    def test_will_return_json_with_list_of_tags(self):
        response = self.client.get('/codecamp/tags/')
        tags = json.loads(response.content)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(len(tags), 2)

    def test_tags_json_returns_first_tag_json(self):
        response = self.client.get('/codecamp/tags/')
        speakers = json.loads(response.content)
        self.assertEqual(speakers[0]['description'], 'javascript')

    def test_tags_json_returns_last_tag_json(self):
        response = self.client.get('/codecamp/tags/')
        speakers = json.loads(response.content)
        self.assertEqual(speakers[1]['description'], 'python')

    def test_detail_tags_endpoint_returns_attributes_for_given_tag_id(self):
        response = self.client.get('/codecamp/tags/{}/'.format(self.first_tag.pk))
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.content, '{"id": 1, "description": "javascript"}')

    def test_http_post_will_create_tag_and_return_201(self):
        data = {'description': 'new'}
        response = self.client.post('/codecamp/tags/', data)
        self.assertEqual(response.status_code, 201)

    def test_http_post_will_create_tag_and_return_created_tag_json(self):
        data = {'description': 'new'}
        response = self.client.post('/codecamp/tags/', data)
        created_tag = json.loads(response.content)
        self.assertEqual(created_tag['description'], 'new')

    def test_http_post_without_data_returns_400(self):
        response = self.client.post('/codecamp/tags/', {})
        self.assertEqual(response.status_code, 400)

    def test_http_put_will_update_first_tag_and_return_200(self):
        data = {'description': 'updated'}
        response = self.client.put('/codecamp/tags/{}/'.format(self.first_tag.pk), data)
        self.assertEqual(response.status_code, 200)

    def test_http_put_will_update_first_tag_and_return_updated_tag_json(self):
        data = {'description': 'updated'}
        response = self.client.put('/codecamp/tags/{}/'.format(self.first_tag.pk), data)
        updated_speaker = json.loads(response.content)
        self.assertEqual(updated_speaker['description'], 'updated')

    def test_http_delete_will_remove_first_tag_and_return_204(self):
        response = self.client.delete('/codecamp/tags/{}/'.format(self.first_tag.pk))
        self.assertEqual(response.status_code, 204)

    def test_http_delete_will_remove_first_tag_and_return_empty_content(self):
        response = self.client.delete('/codecamp/tags/{}/'.format(self.first_tag.pk))
        self.assertEqual(response.content, '')

    def test_http_delete_will_return_404_when_incorrect_id_used_to_delete_tag(self):
        response = self.client.delete('/codecamp/tags/999999999999999999/')
        self.assertEqual(response.status_code, 404)