def testSaveCountShouldCreatesStockFacetRecord(self, mock_save): from stockandflow.models import Facet f = Facet("test_slug", "test name", "test_field", [1,2]) s = Stock(*self.stock_args) s.facets = [f] s.save_count() self.assertEqual(mock_save.call_count, 2)
def testSaveCountShouldPassThroughFieldPrefix(self, mock_save): from stockandflow.models import Facet f = Facet("test_slug", "test name", "test_field", [1,2]) f.to_count = MagicMock() s = Stock(*self.stock_args) s.facets = [(f, "test_prefix")] s.save_count() self.assertEqual(f.to_count.call_args, (("test_prefix",), {}))
def testFlowIntoShouldReturnADictOfFlowsAndQuerysets(self): self.inflows = [Mock(), Mock()] self.outflows = [Mock(), Mock()] s = Stock(*self.stock_args) self.register_flows(s) rv = s.flows_into() self.assertEquals(len(rv), 2) self.assertTrue(self.inflows[0].all.called) self.assertEqual(rv[self.inflows[0]], self.inflows[0].all.return_value) self.assertTrue(self.inflows[1].all.called) self.assertEqual(rv[self.inflows[1]], self.inflows[1].all.return_value)
def testGenerateAListOfFacetsSortedBySlugBasedOnTheStocks(self): from stockandflow.models import Stock, Facet from stockandflow.views import Process f1 = Facet("test_slug", "test name", "test_field", [1,2]) f2 = Facet("test_slug", "test name", "test_field", [1,2]) self.stock_args = [] s1 = Stock('test name 1', 'test_slug_1', Mock()) s2 = Stock('test name 2', 'test_slug_2', Mock()) s1.facets = [f1] s2.facets = [f1, f2] process = Process("process_test", "process test", [s1, s2]) self.assertEqual(process.facets, [f1, f2])
def testMostRecentRecordShouldReturnCorrectStockRecord(self): s = Stock(*self.stock_args) s.save_count() # this would be the wrong record self.mock_qs.count.return_value = 111 s.save_count() self.assertEqual(s.most_recent_record().count, 111) self.mock_qs.count.return_value = 222 s.save_count() self.assertEqual(s.most_recent_record().count, 222)
from datetime import date from stockandflow.models import Stock, Flow from stockandflow.tracker import ModelTracker from stockandflow import periodic from processes.models import ProfileFlowEvent from processes import admin as sfadmin from profiles.models import Profile, CONSISTENCY_CHOICES from processes.stocksandflows import facets # The Stocks stocks = [] needs_coach_stock = Stock(slug="needs_coach", name="Needs coach user", facets=[facets.coach], queryset=Profile.objects.filter(user__is_active=True, needs_coach=True)) stocks.append(needs_coach_stock) all_member_stock = Stock(slug="members", name="Members", facets=[facets.ramp, facets.source, facets.pay_state], queryset=Profile.objects.filter(user__is_staff=False, user__is_active=True)) stocks.append(all_member_stock) inactive_member_stock = Stock(slug="inactive", name="Inactive members", queryset=Profile.objects.filter(user__is_staff=False, user__is_active=True, next_contact__exact=None)) stocks.append(inactive_member_stock) paying_member_stock = Stock(slug="paying", name="Paying members", facets=[facets.ramp, facets.source],
def testSaveCountShouldCreatesStockRecord(self, mock_save): s = Stock(*self.stock_args) s.save_count() self.assertTrue(mock_save.called)
def testSaveCountShouldCheckTheCount(self): s = Stock(*self.stock_args) s.save_count() self.assertTrue(self.mock_qs.count.called)
def testStockAllShouldReturnTheQueryset(self): s = Stock(*self.stock_args) self.assertEqual(s.all(), self.mock_qs)
def testunitGetFacetedShouldReturnAFacetBasedOnASlug(self): from stockandflow.models import Facet f = Facet("test_slug", "test name", "test_field", [1,2]) s = Stock("test stock name", "test_stock_slug", self.mock_qs, facets=[f]) rv = s.get_facet("test_slug") self.assertEqual(rv, f)
def testunitFacetedQSShouldReturnAQuerysetFilteredByAFacetBasedOnASlug(self): from stockandflow.models import Facet f = Facet("test_slug", "test name", "test_field", [1,2]) s = Stock("test stock name", "test_stock_slug", self.mock_qs, facets=[f]) s.faceted_qs("test_slug", value=1) self.assertEqual(str(self.mock_qs.filter.call_args[0][0]), "(AND: ('test_field', 1))")