def test_notice_insert(): """We can insert and replace a notice""" dmn = DMNotices() doc = { "some": "structure", 'effective_on': '2011-01-01', 'fr_url': 'http://example.com', 'publication_date': '2010-02-02', 'cfr_parts': ['222'] } dmn.insert('docdoc', doc) expected = { "document_number": "docdoc", "effective_on": date(2011, 1, 1), "fr_url": "http://example.com", "publication_date": date(2010, 2, 2), "noticecfrpart__cfr_part": '222', "notice": doc } assert list(Notice.objects.all().values(*expected.keys())) == [expected] doc['fr_url'] = 'url2' dmn.delete('docdoc') dmn.insert('docdoc', doc) expected['fr_url'] = 'url2' assert list(Notice.objects.all().values(*expected.keys())) == [expected]
def test_notice_insert(): """We can insert and replace a notice""" dmn = DMNotices() doc = {"some": "structure", 'effective_on': '2011-01-01', 'fr_url': 'http://example.com', 'publication_date': '2010-02-02', 'cfr_parts': ['222']} dmn.insert('docdoc', doc) expected = {"document_number": "docdoc", "effective_on": date(2011, 1, 1), "fr_url": "http://example.com", "publication_date": date(2010, 2, 2), "noticecfrpart__cfr_part": '222', "notice": doc} assert list(Notice.objects.all().values(*expected.keys())) == [expected] doc['fr_url'] = 'url2' dmn.delete('docdoc') dmn.insert('docdoc', doc) expected['fr_url'] = 'url2' assert list(Notice.objects.all().values(*expected.keys())) == [expected]
class DMNoticesTest(TestCase): def setUp(self): self.dmn = DMNotices() def test_get_404(self): self.assertIsNone(self.dmn.get('docdoc')) def test_get_success(self): Notice(document_number='docdoc', fr_url='frfr', publication_date=date.today(), notice={ "some": "body" }).save() self.assertEqual({"some": 'body'}, self.dmn.get('docdoc')) def test_listing(self): n = Notice(document_number='22', fr_url='fr1', notice={}, effective_on=date(2005, 5, 5), publication_date=date(2001, 3, 3)) n.save() n.noticecfrpart_set.create(cfr_part='876') n = Notice(document_number='9', fr_url='fr2', notice={}, publication_date=date(1999, 1, 1)) n.noticecfrpart_set.create(cfr_part='876') n.noticecfrpart_set.create(cfr_part='111') n.save() self.assertEqual([{ 'document_number': '22', 'fr_url': 'fr1', 'publication_date': '2001-03-03', 'effective_on': '2005-05-05' }, { 'document_number': '9', 'fr_url': 'fr2', 'publication_date': '1999-01-01' }], self.dmn.listing()) self.assertEqual(self.dmn.listing(), self.dmn.listing('876')) self.assertEqual([], self.dmn.listing('888')) def test_insert(self): """We can insert and replace a notice""" doc = { "some": "structure", 'effective_on': '2011-01-01', 'fr_url': 'http://example.com', 'publication_date': '2010-02-02', 'cfr_parts': ['222'] } self.dmn.insert('docdoc', doc) expected = { "document_number": "docdoc", "effective_on": date(2011, 1, 1), "fr_url": "http://example.com", "publication_date": date(2010, 2, 2), "noticecfrpart__cfr_part": '222', "notice": doc } fields = expected.keys() six.assertCountEqual(self, Notice.objects.all().values(*fields), [expected]) doc['fr_url'] = 'url2' self.dmn.delete('docdoc') self.dmn.insert('docdoc', doc) expected['fr_url'] = 'url2' six.assertCountEqual(self, Notice.objects.all().values(*fields), [expected])