class AddTrackerViewTest(TestCase): def setUp(self): self.c = self.client self.u = User.objects.create(username="******") self.u.set_password("test") self.u.save() self.c.login(username="******", password="******") pu = PMTUser.objects.create(username="******", email="*****@*****.**", status="active") Claim.objects.create(django_user=self.u, pmt_user=pu) m = MilestoneFactory() self.project = m.project def test_post_without_required_fields(self): r = self.c.post("/api/1.0/trackers/add/", dict()) self.assertEqual(r.status_code, 200) def test_post(self): r = self.c.post("/api/1.0/trackers/add/", dict(pid=self.project.pid, task="test", time="1 hour")) self.assertEqual(r.status_code, 200) def test_post_with_nonexistant_client(self): r = self.c.post("/api/1.0/trackers/add/", dict(pid=self.project.pid, task="test", time="1 hour", client="foo")) self.assertEqual(r.status_code, 200) def test_post_with_client(self): self.client = ClientFactory() r = self.c.post( "/api/1.0/trackers/add/", dict(pid=self.project.pid, task="test", time="1 hour", client="testclient") ) self.assertEqual(r.status_code, 200) def test_with_duplicate_clients(self): self.client = ClientFactory() self.client2 = ClientFactory() self.client2.email = self.client.email self.client2.save() r = self.c.post( "/api/1.0/trackers/add/", dict(pid=self.project.pid, task="test", time="1 hour", client="testclient") ) self.assertEqual(r.status_code, 200)
class AddTrackerViewTest(TestCase): def setUp(self): self.c = Client() self.u = User.objects.create(username="******") self.u.set_password("test") self.u.save() self.c.login(username="******", password="******") pu = PMTUser.objects.create(username="******", email="*****@*****.**", status="active") Claim.objects.create(django_user=self.u, pmt_user=pu) m = MilestoneFactory() self.project = m.project def test_post_without_required_fields(self): r = self.c.post("/api/1.0/trackers/add/", dict()) self.assertEqual(r.status_code, 200) def test_post(self): r = self.c.post( "/api/1.0/trackers/add/", dict( pid=self.project.pid, task="test", time="1 hour", )) self.assertEqual(r.status_code, 200) def test_post_with_nonexistant_client(self): r = self.c.post( "/api/1.0/trackers/add/", dict( pid=self.project.pid, task="test", time="1 hour", client="foo", )) self.assertEqual(r.status_code, 200) def test_post_with_client(self): self.client = ClientFactory() r = self.c.post( "/api/1.0/trackers/add/", dict( pid=self.project.pid, task="test", time="1 hour", client="testclient", )) self.assertEqual(r.status_code, 200) def test_with_duplicate_clients(self): self.client = ClientFactory() self.client2 = ClientFactory() self.client2.email = self.client.email self.client2.save() r = self.c.post( "/api/1.0/trackers/add/", dict( pid=self.project.pid, task="test", time="1 hour", client="testclient", )) self.assertEqual(r.status_code, 200)
class AddTrackerViewTest(TestCase): def setUp(self): self.c = self.client self.u = User.objects.create(username="******") self.u.set_password("test") self.u.save() self.c.login(username="******", password="******") self.milestone = MilestoneFactory() self.project = self.milestone.project self.url = reverse('add-tracker') def test_post_without_required_fields(self): r = self.c.post( self.url, dict()) self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST) def test_post_with_empty_fields(self): r = self.c.post( self.url, dict(pid='', task='')) self.assertEqual(r.status_code, status.HTTP_400_BAD_REQUEST) def test_post(self): r = self.c.post( self.url, dict( pid=self.project.pid, task="test", time="1 hour", )) self.assertEqual(r.status_code, 200) def test_post_backdated_last(self): r = self.c.post( self.url, dict( pid=self.project.pid, task="test backdated last", time="1 hour", completed="last", )) self.assertEqual(r.status_code, 200) content = json.loads(r.content) self.assertEqual(content['duration'], 3600) self.assertEqual(content['simpleduration'], '1h') # Assert that the created time is accurate item = Item.objects.filter( milestone=self.milestone, title="test backdated last" ).first() actual_time = ActualTime.objects.filter(item=item).first() expected_time = datetime.utcnow() - timedelta(days=7) self.assertEqual(actual_time.completed.day, expected_time.day) self.assertEqual(actual_time.completed.month, expected_time.month) self.assertEqual(actual_time.completed.year, expected_time.year) def test_post_backdated_before_last(self): r = self.c.post( self.url, dict( pid=self.project.pid, task="test", time="1 hour", completed="before_last", )) self.assertEqual(r.status_code, 200) item = Item.objects.filter(milestone=self.milestone).first() actual_time = ActualTime.objects.filter(item=item).first() expected_time = datetime.utcnow() - timedelta(days=14) self.assertEqual(actual_time.completed.day, expected_time.day) self.assertEqual(actual_time.completed.month, expected_time.month) self.assertEqual(actual_time.completed.year, expected_time.year) def test_post_with_nonexistant_client(self): r = self.c.post( self.url, dict( pid=self.project.pid, task="test", time="1 hour", client="foo", )) self.assertEqual(r.status_code, 200) def test_post_with_client(self): self.client = ClientFactory() r = self.c.post( self.url, dict( pid=self.project.pid, task="test", time="1 hour", client="testclient", )) self.assertEqual(r.status_code, 200) def test_with_duplicate_clients(self): self.client = ClientFactory() self.client2 = ClientFactory() self.client2.email = self.client.email self.client2.save() r = self.c.post( self.url, dict( pid=self.project.pid, task="test", time="1 hour", client="testclient", )) self.assertEqual(r.status_code, 200)