Ejemplo n.º 1
0
 def test_base(self):
     snippets = SnippetFactory.create_batch(2)
     jsonsnippets = JSONSnippetFactory.create_batch(2)
     SnippetFactory.create(disabled=True)
     JSONSnippetFactory.create(disabled=True)
     response = views.ActiveSnippetsView.as_view()(self.request)
     eq_(response.get('content-type'), 'application/json')
     data = json.loads(response.content)
     eq_(set([snippets[0].id, snippets[1].id,
              jsonsnippets[0].id, jsonsnippets[1].id]),
         set([x['id'] for x in data]))
Ejemplo n.º 2
0
 def test_base(self):
     snippets = SnippetFactory.create_batch(2)
     jsonsnippets = JSONSnippetFactory.create_batch(2)
     SnippetFactory.create(disabled=True)
     JSONSnippetFactory.create(disabled=True)
     response = views.ActiveSnippetsView.as_view()(self.request)
     eq_(response.get('content-type'), 'application/json')
     data = json.loads(response.content)
     eq_(
         set([
             snippets[0].id, snippets[1].id, jsonsnippets[0].id,
             jsonsnippets[1].id
         ]), set([x['id'] for x in data]))
Ejemplo n.º 3
0
 def test_encode_jsonsnippet(self):
     encoder = ActiveSnippetsEncoder()
     now = datetime.now()
     data = {
         'id': 99,
         'text': 'test-text',
         'publish_start': now,
         'name': 'Foo bar',
         'countries': ['us']
     }
     snippet = JSONSnippetFactory.create(**data)
     result = encoder.default(snippet)
     eq_(
         result, {
             'id': 99,
             'name': 'Foo bar',
             'type': 'JSON Snippet',
             'template': 'default',
             'publish_start': now,
             'publish_end': None,
             'on_release': True,
             'on_beta': False,
             'on_aurora': False,
             'on_nightly': False,
             'locales': ['en-us'],
             'countries': ['us'],
             'weight': 100
         })
Ejemplo n.º 4
0
 def test_encode_without_country(self):
     encoder = JSONSnippetEncoder()
     data = {'id': 99, 'text': 'test-text',
             'icon': 'test-icon', 'url': 'test-url',
             'weight': 100}
     snippet = JSONSnippetFactory.build(**data)
     result = encoder.default(snippet)
     eq_(result, data)
Ejemplo n.º 5
0
 def test_encode_jsonsnippet(self):
     encoder = SnippetEncoder()
     data = {'id': 99, 'text': 'test-text',
             'icon': 'test-icon', 'url': 'test-url',
             'country': 'us', 'weight': 100}
     snippet = JSONSnippetFactory.build(**data)
     result = encoder.default(snippet)
     data['target_geo'] = data.pop('country').upper()
     eq_(result, data)
Ejemplo n.º 6
0
    def test_base(self):
        # Matching snippets.
        snippet_1 = JSONSnippetFactory.create(on_nightly=True, weight=66)

        # Matching but disabled snippet.
        JSONSnippetFactory.create(on_nightly=True, disabled=True)

        # Snippet that doesn't match.
        JSONSnippetFactory.create(on_nightly=False),

        params = ('4', 'Fennec', '23.0a1', '20130510041606',
                  'Darwin_Universal-gcc3', 'en-US', 'nightly',
                  'Darwin%2010.8.0', 'default', 'default_version')
        response = self.client.get('/json/{0}/'.format('/'.join(params)))
        data = json.loads(response.content)
        eq_(len(data), 1)
        eq_(data[0]['id'], snippet_1.id)
        eq_(data[0]['weight'], 66)
Ejemplo n.º 7
0
    def test_base(self):
        # Matching snippets.
        snippet_1 = JSONSnippetFactory.create(on_nightly=True, weight=66)

        # Matching but disabled snippet.
        JSONSnippetFactory.create(on_nightly=True, disabled=True)

        # Snippet that doesn't match.
        JSONSnippetFactory.create(on_nightly=False),

        params = ('4', 'Fennec', '23.0a1', '20130510041606',
                  'Darwin_Universal-gcc3', 'en-US', 'nightly',
                  'Darwin%2010.8.0', 'default', 'default_version')
        response = self.client.get('/json/{0}/'.format('/'.join(params)))
        data = json.loads(response.content)
        self.assertEqual(len(data), 1)
        self.assertEqual(data[0]['id'], snippet_1.id)
        self.assertEqual(data[0]['weight'], 66)
 def test_encode_jsonsnippet(self):
     encoder = JSONSnippetEncoder()
     data = {'id': 99, 'text': 'test-text',
             'icon': 'test-icon', 'url': 'test-url',
             'countries': ['US', 'GR'], 'weight': 100}
     snippet = JSONSnippetFactory.create(**data)
     result = encoder.default(snippet)
     self.assertEqual(result.pop('target_geo'), result.get('countries')[0])
     self.assertEqual(set(result.pop('countries')), set(data.pop('countries')))
     self.assertEqual(result, data)
Ejemplo n.º 9
0
 def test_encode_without_country(self):
     encoder = JSONSnippetEncoder()
     data = {
         'id': 99,
         'text': 'test-text',
         'icon': 'test-icon',
         'url': 'test-url',
         'weight': 100
     }
     snippet = JSONSnippetFactory.build(**data)
     result = encoder.default(snippet)
     eq_(result, data)
Ejemplo n.º 10
0
 def test_encode_jsonsnippet(self):
     encoder = SnippetEncoder()
     data = {
         'id': 99,
         'text': 'test-text',
         'icon': 'test-icon',
         'url': 'test-url',
         'country': 'us',
         'weight': 100
     }
     snippet = JSONSnippetFactory.build(**data)
     result = encoder.default(snippet)
     data['target_geo'] = data.pop('country').upper()
     eq_(result, data)
Ejemplo n.º 11
0
 def test_encode_jsonsnippet(self):
     encoder = JSONSnippetEncoder()
     data = {
         'id': 99,
         'text': 'test-text',
         'icon': 'test-icon',
         'url': 'test-url',
         'countries': ['US', 'GR'],
         'weight': 100
     }
     snippet = JSONSnippetFactory.create(**data)
     result = encoder.default(snippet)
     eq_(result.pop('target_geo'), result.get('countries')[0])
     eq_(set(result.pop('countries')), set(data.pop('countries')))
     eq_(result, data)
 def test_encode_jsonsnippet(self):
     encoder = ActiveSnippetsEncoder()
     now = datetime.now()
     data = {'id': 99, 'text': 'test-text', 'publish_start': now,
             'name': 'Foo bar', 'countries': ['us']}
     snippet = JSONSnippetFactory.create(**data)
     result = encoder.default(snippet)
     self.assertEqual(result, {'id': 99,
                               'name': 'Foo bar',
                               'type': 'JSON Snippet',
                               'template': 'default',
                               'publish_start': now,
                               'publish_end': None,
                               'on_release': True,
                               'on_beta': False,
                               'on_aurora': False,
                               'on_nightly': False,
                               'locales': ['en-us'],
                               'countries': ['us'],
                               'weight': 100
                               })
Ejemplo n.º 13
0
 def setUp(self):
     for i in range(10):
         JSONSnippetFactory.create()
Ejemplo n.º 14
0
 def test_filter(self):
     JSONSnippetFactory.create(on_nightly=True)
     response = self.client.get(urlparams(reverse('base.index_json'), on_nightly=2))
     eq_(response.status_code, 200)
     eq_(response.context['snippets'].paginator.count, 1)
Ejemplo n.º 15
0
 def setUp(self):
     for i in range(10):
         JSONSnippetFactory.create()
Ejemplo n.º 16
0
 def test_filter(self):
     JSONSnippetFactory.create(on_nightly=True)
     response = self.client.get(
         urlparams(reverse('base.index_json'), on_nightly=2))
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.context['snippets'].paginator.count, 1)
Ejemplo n.º 17
0
 def test_json_snippet(self):
     snippet = JSONSnippetFactory.create()
     self._dup_test(snippet)
Ejemplo n.º 18
0
 def test_json_snippet(self):
     snippet = JSONSnippetFactory.create()
     self._dup_test(snippet)