<s> from __future__ import unicode_literals <EOL> import os <EOL> import pytest <EOL> import requests <EOL> import json <EOL> from django . conf import settings <EOL> from django . core . urlresolvers import reverse <EOL> from django . test import TestCase <EOL> from django . db import IntegrityError <EOL> from rest_framework . test import APITestCase <EOL> from rest_framework import status <EOL> from base . models import Project <EOL> class TestProjectREST ( APITestCase ) : <EOL> """<STR_LIT>""" <EOL> @ classmethod <EOL> def setUpClass ( cls ) : <EOL> cls . test_project = Project ( <EOL> name = "<STR_LIT>" , <EOL> description = "<STR_LIT>" <EOL> ) <EOL> cls . test_project . save ( ) <EOL> cls . url = "<STR_LIT>" <EOL> def parse_response ( self , response ) : <EOL> return json . loads ( response . content ) [ <NUM_LIT:0> ] <EOL> def test_add_project ( self ) : <EOL> response = self . client . post ( self . url , { "<STR_LIT:name>" : "<STR_LIT>" } , format = "<STR_LIT>" ) <EOL> assert json . loads ( response . content ) [ "<STR_LIT>" ] == "<STR_LIT>" <EOL> assert json . loads ( response . content ) [ "<STR_LIT:name>" ] == "<STR_LIT>" <EOL> def test_add_project_no_name ( self ) : <EOL> response = self . client . post ( self . url , { } , format = "<STR_LIT>" ) <EOL> assert json . loads ( response . content ) [ "<STR_LIT:name>" ] [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> def test_add_project_no_name ( self ) : <EOL> response = self . client . post ( self . url , { "<STR_LIT:name>" : "<STR_LIT>" } , format = "<STR_LIT>" ) <EOL> assert json . loads ( response . content ) [ "<STR_LIT:name>" ] [ <NUM_LIT:0> ] == "<STR_LIT>" <EOL> def test_get_all_projects ( self ) : <EOL> response = self . client . get ( self . url ) <EOL> assert self . parse_response ( response ) <EOL> def test_get_project_by_id ( self ) : <EOL> response = self . client . get ( self . url + "<STR_LIT>" % self . test_project . id ) <EOL> assert self . parse_response ( response ) [ "<STR_LIT:id>" ] == self . test_project . id <EOL> def test_get_project_by_name ( self ) : <EOL> response = self . client . get ( self . url + "<STR_LIT>" % self . test_project . name ) <EOL> assert self . parse_response ( response ) [ "<STR_LIT:name>" ] == self . test_project . name <EOL> def test_get_project_by_slug ( self ) : <EOL> response = self . client . get ( self . url + "<STR_LIT>" % self . test_project . slug ) <EOL> assert self . parse_response ( response ) [ "<STR_LIT>" ] == self . test_project . slug <EOL> def test_no_project_exists ( self ) : <EOL> response = self . client . get ( self . url + "<STR_LIT>" ) <EOL> assert not response . data <EOL> def test_change_name ( self ) : <EOL> response = self . client . patch ( self . url + "<STR_LIT>" % self . test_project . id , <EOL> { '<STR_LIT:name>' : '<STR_LIT>' } , format = "<STR_LIT>" ) <EOL> assert json . loads ( response . content ) [ "<STR_LIT:name>" ] == "<STR_LIT>" <EOL> def test_change_description ( self ) : <EOL> response = self . client . patch ( self . url + "<STR_LIT>" % self . test_project . id , <EOL> { '<STR_LIT:description>' : '<STR_LIT>' } , format = "<STR_LIT>" ) <EOL> assert json . loads ( response . content ) [ "<STR_LIT:description>" ] == "<STR_LIT>" <EOL> def test_change_slug_fails ( self ) : <EOL> """<STR_LIT>""" <EOL> response = self . client . patch ( self . url + "<STR_LIT>" % self . test_project . id , <EOL> { '<STR_LIT>' : '<STR_LIT>' } , format = "<STR_LIT>" ) <EOL> assert json . loads ( response . content ) [ "<STR_LIT>" ] == "<STR_LIT>" </s>
