class ConnectionCreateViewTest(TestCase): def setUp(self): self.site = LearningSiteFactory() self.parent = LearningSiteFactory() def test_get_form(self): view = ConnectionCreateView() view.parent = self.parent view.request = RequestFactory() view.request.method = 'GET' frm = view.get_form() self.assertEquals(frm.fields['site'].queryset.count(), 1) self.assertEquals(frm.fields['site'].queryset[0], self.site) def test_form_valid_associates(self): site = LearningSiteFactory() frm = ConnectionForm() frm.cleaned_data = {'connection_type': 'associate', 'site': site} view = ConnectionCreateView() view.parent = self.parent view.form_valid(frm) self.assertTrue(len(self.parent.associates()), 1) self.assertEquals(self.parent.associates()[0], site)
class ConnectionDeleteViewTest(TestCase): def setUp(self): self.site = LearningSiteFactory() self.parent = LearningSiteFactory() editor = UserFactory() editor.groups.add(GroupFactory(name='Editor')) self.client.login(username=editor.username, password='******') def test_remove_associate(self): LearningSiteRelationshipFactory(site_one=self.parent, site_two=self.site) url = reverse('connection-delete-view', kwargs={ 'parent': self.parent.pk, 'type': 'associate', 'pk': self.site.pk }) response = self.client.post(url) self.assertEquals(response.status_code, 302) self.assertTrue(self.site not in self.parent.associates())